From b503455356fbe00bd1622d44b83b352924d8f96b Mon Sep 17 00:00:00 2001 From: Jason Stapels Date: Tue, 16 Jul 2019 10:21:20 -0400 Subject: [PATCH] Updates to Swift 4.2 and fixed a few warning. --- GoFont.xcodeproj/project.pbxproj | 14 ++++++++++---- GoFont/FontManager.swift | 9 +++++---- GoFont/GoogleFonts.swift | 2 +- GoFont/ViewController.swift | 2 +- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/GoFont.xcodeproj/project.pbxproj b/GoFont.xcodeproj/project.pbxproj index 5f8e8a3..7d5b8a5 100644 --- a/GoFont.xcodeproj/project.pbxproj +++ b/GoFont.xcodeproj/project.pbxproj @@ -128,7 +128,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0820; - LastUpgradeCheck = 0900; + LastUpgradeCheck = 1020; ORGANIZATIONNAME = "Code Adepts"; TargetAttributes = { AD6FB7901E207ED8001BA39D = { @@ -145,7 +145,7 @@ }; buildConfigurationList = AD6FB78C1E207ED8001BA39D /* Build configuration list for PBXProject "GoFont" */; compatibilityVersion = "Xcode 8.0"; - developmentRegion = English; + developmentRegion = en; hasScannedForEncodings = 0; knownRegions = ( en, @@ -211,6 +211,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_ANALYZER_NONNULL = YES; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; @@ -220,6 +221,7 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_DOCUMENTATION_COMMENTS = YES; CLANG_WARN_EMPTY_BODY = YES; @@ -227,6 +229,7 @@ CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; @@ -266,6 +269,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_ANALYZER_NONNULL = YES; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; @@ -275,6 +279,7 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_DOCUMENTATION_COMMENTS = YES; CLANG_WARN_EMPTY_BODY = YES; @@ -282,6 +287,7 @@ CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; @@ -316,7 +322,7 @@ CODE_SIGN_ENTITLEMENTS = GoFont/GoFont.entitlements; CODE_SIGN_IDENTITY = "Mac Developer"; COMBINE_HIDPI_IMAGES = YES; - DEVELOPMENT_TEAM = 9TC6Q3R3J9; + DEVELOPMENT_TEAM = S4533V6XQ6; INFOPLIST_FILE = GoFont/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.12; @@ -336,7 +342,7 @@ CODE_SIGN_ENTITLEMENTS = GoFont/GoFont.entitlements; CODE_SIGN_IDENTITY = "Mac Developer"; COMBINE_HIDPI_IMAGES = YES; - DEVELOPMENT_TEAM = 9TC6Q3R3J9; + DEVELOPMENT_TEAM = S4533V6XQ6; INFOPLIST_FILE = GoFont/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.12; diff --git a/GoFont/FontManager.swift b/GoFont/FontManager.swift index 31607aa..2042aff 100644 --- a/GoFont/FontManager.swift +++ b/GoFont/FontManager.swift @@ -51,7 +51,7 @@ class FontManager { } func getFont(name: String) -> FontFamily? { - return handlers.flatMap({ $0.getFont(name: name) }).first + return handlers.compactMap({ $0.getFont(name: name) }).first } } @@ -94,10 +94,11 @@ struct AnyFont: Hashable, Comparable { var font: FontFamily var variantId: String - var hashValue: Int { - return 31 &* font.name.hashValue &+ variantId.hashValue + func hash(into hasher: inout Hasher) { + hasher.combine(font.name) + hasher.combine(variantId) } - + static func == (lhs: AnyFont, rhs: AnyFont) -> Bool { return lhs.font.name == rhs.font.name && lhs.variantId == rhs.variantId } diff --git a/GoFont/GoogleFonts.swift b/GoFont/GoogleFonts.swift index 233d2cc..25bfb5f 100644 --- a/GoFont/GoogleFonts.swift +++ b/GoFont/GoogleFonts.swift @@ -150,7 +150,7 @@ struct GoogleFonts: FontHandler { func query(search: String, sort: FontSort) -> [FontFamily] { return families[sort]! .filter { search.isEmpty || $0.lowercased().contains(search.lowercased()) } - .map { fonts[$0]! } + .compactMap { fonts[$0] } } func getFont(name: String) -> FontFamily? { diff --git a/GoFont/ViewController.swift b/GoFont/ViewController.swift index 1b9977a..5d3af40 100644 --- a/GoFont/ViewController.swift +++ b/GoFont/ViewController.swift @@ -484,7 +484,7 @@ class ViewController: NSViewController, NSTextFieldDelegate, WKScriptMessageHand // Selected fonts html. let selectionsHtml = selectedFamilyIds .filter { !shownIds.contains($0) } - .flatMap { getSelectedFontHtml(name: $0) } + .compactMap { getSelectedFontHtml(name: $0) } .joined() // Render output.