From 08ab36ad6b5c50398d7487c03297af9a2ed12e22 Mon Sep 17 00:00:00 2001 From: Steve Kalkwarf Date: Tue, 30 Nov 2021 09:23:58 -0500 Subject: [PATCH] Build with newer Swift and UIKit --- Eject.xcodeproj/project.pbxproj | 64 +++++++++++++------ EjectKit/Builder/CocoaTouchBuilder.swift | 2 +- EjectKit/CodeGenerators/CodeGeneration.swift | 2 +- EjectKit/CodeGenerators/Initializer.swift | 2 +- .../CodeGenerators/ValueCodeGenerators.swift | 2 +- EjectKit/Configuration.swift | 6 +- EjectKit/Foundation+Eject.swift | 4 +- Tests/EjectKitTests/EjectKitTests.swift | 2 +- 8 files changed, 58 insertions(+), 26 deletions(-) diff --git a/Eject.xcodeproj/project.pbxproj b/Eject.xcodeproj/project.pbxproj index 1f922db..a525019 100644 --- a/Eject.xcodeproj/project.pbxproj +++ b/Eject.xcodeproj/project.pbxproj @@ -187,7 +187,9 @@ AB47D9AD1DB5A3DD00A7B5E8 /* Products */, AB530CCC1DD101DE00B54516 /* Tests */, ); + indentWidth = 4; sourceTree = ""; + tabWidth = 4; }; AB47D9AD1DB5A3DD00A7B5E8 /* Products */ = { isa = PBXGroup; @@ -232,10 +234,10 @@ isa = PBXGroup; children = ( ABB389FD1DB95DDB008BF59E /* CodeGeneration.swift */, + AB05071A1DD7BA35005B5427 /* ConstraintCodeGenerator.swift */, ABB389FE1DB95DDB008BF59E /* Initializer.swift */, ABB38A051DB95DDB008BF59E /* ValueCodeGenerators.swift */, ABB38A071DB95DDB008BF59E /* VariableConfiguration.swift */, - AB05071A1DD7BA35005B5427 /* ConstraintCodeGenerator.swift */, ); path = CodeGenerators; sourceTree = ""; @@ -275,6 +277,7 @@ ABB38A261DB95E04008BF59E /* ConstraintBuilder.swift */, ABB389F31DB95DDB008BF59E /* DocumentBuilder.swift */, ABB389F41DB95DDB008BF59E /* FontBuilder.swift */, + AB9EF7E01DED4BCD0097C3FC /* ItemsBuilder.swift */, ABB389F51DB95DDB008BF59E /* KeyValueBuilder.swift */, ABB389F61DB95DDB008BF59E /* ObjectDefinition+Builder.swift */, ABB389F71DB95DDB008BF59E /* OptionSetBuilder.swift */, @@ -282,7 +285,6 @@ ABF8D90A1DC1197C008D9178 /* SegmentsBuilder.swift */, ABB389FA1DB95DDB008BF59E /* StructBuilder.swift */, ABB389FB1DB95DDB008BF59E /* SubviewBuilder.swift */, - AB9EF7E01DED4BCD0097C3FC /* ItemsBuilder.swift */, ABB389FC1DB95DDB008BF59E /* UserDefinedAttributesBuilder.swift */, ); path = Builder; @@ -291,15 +293,15 @@ ABB38A001DB95DDB008BF59E /* Model */ = { isa = PBXGroup; children = ( - ABB38A011DB95DDB008BF59E /* XIBDocument.swift */, - AB61CB491DD7A41E009DB519 /* ObjectDefinition.swift */, - ABB38A041DB95DDB008BF59E /* Reference.swift */, - AB477E331DBF8F2E000A0A56 /* Statement.swift */, - ABF8D90E1DC11E75008D9178 /* ValueFormat.swift */, ABF8D90C1DC11A7C008D9178 /* AssociationContext.swift */, AB6415D41DD7A9F500FD0C6C /* Configuration.swift */, AB61CB461DD7A2C0009DB519 /* MappingKey.swift */, + AB61CB491DD7A41E009DB519 /* ObjectDefinition.swift */, AB9EF7DC1DED37D10097C3FC /* PostProcessor.swift */, + ABB38A041DB95DDB008BF59E /* Reference.swift */, + AB477E331DBF8F2E000A0A56 /* Statement.swift */, + ABF8D90E1DC11E75008D9178 /* ValueFormat.swift */, + ABB38A011DB95DDB008BF59E /* XIBDocument.swift */, ); path = Model; sourceTree = ""; @@ -400,7 +402,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0800; - LastUpgradeCheck = 0800; + LastUpgradeCheck = 1250; ORGANIZATIONNAME = "Brian King"; TargetAttributes = { AB9EF79C1DE61A910097C3FC = { @@ -424,7 +426,7 @@ }; buildConfigurationList = AB47D9A71DB5A3DD00A7B5E8 /* Build configuration list for PBXProject "Eject" */; compatibilityVersion = "Xcode 3.2"; - developmentRegion = English; + developmentRegion = en; hasScannedForEncodings = 0; knownRegions = ( en, @@ -596,20 +598,31 @@ 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++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 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; CLANG_WARN_ENUM_CONVERSION = YES; 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_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_SUSPICIOUS_MOVES = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -644,20 +657,31 @@ 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++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 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; CLANG_WARN_ENUM_CONVERSION = YES; 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_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_SUSPICIOUS_MOVES = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -686,7 +710,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; INFOPLIST_FILE = CocoaTouchExample/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 10.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.raizlabs.CocoaTouchExample; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -703,7 +727,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; INFOPLIST_FILE = CocoaTouchExample/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 10.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.raizlabs.CocoaTouchExample; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -721,15 +745,17 @@ ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; + CODE_SIGN_IDENTITY = "-"; COMBINE_HIDPI_IMAGES = YES; DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = Eject/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; + MACOSX_DEPLOYMENT_TARGET = 11.0; PRODUCT_BUNDLE_IDENTIFIER = com.brianking.Eject; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -739,21 +765,24 @@ ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; + CODE_SIGN_IDENTITY = "-"; COMBINE_HIDPI_IMAGES = YES; DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = Eject/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; + MACOSX_DEPLOYMENT_TARGET = 11.0; PRODUCT_BUNDLE_IDENTIFIER = com.brianking.Eject; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; }; name = Release; }; ABB38A461DB95EA0008BF59E /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { - CODE_SIGN_IDENTITY = "Mac Developer"; + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + CODE_SIGN_IDENTITY = ""; COMBINE_HIDPI_IMAGES = YES; CURRENT_PROJECT_VERSION = 1; DEFINES_MODULE = YES; @@ -761,7 +790,6 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; - EMBEDDED_CONTENT_CONTAINS_SWIFT = YES; FRAMEWORK_VERSION = A; INFOPLIST_FILE = EjectKit/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; @@ -770,7 +798,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; @@ -779,6 +807,7 @@ ABB38A471DB95EA0008BF59E /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; CODE_SIGN_IDENTITY = ""; COMBINE_HIDPI_IMAGES = YES; CURRENT_PROJECT_VERSION = 1; @@ -787,7 +816,6 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; - EMBEDDED_CONTENT_CONTAINS_SWIFT = YES; FRAMEWORK_VERSION = A; INFOPLIST_FILE = EjectKit/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; @@ -796,7 +824,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; diff --git a/EjectKit/Builder/CocoaTouchBuilder.swift b/EjectKit/Builder/CocoaTouchBuilder.swift index 7dee5d6..22b779e 100644 --- a/EjectKit/Builder/CocoaTouchBuilder.swift +++ b/EjectKit/Builder/CocoaTouchBuilder.swift @@ -394,7 +394,7 @@ extension DocumentBuilder { let button = control.inherit( className: "UIButton", properties: [ - .build("buttonType", .enumeration, "custom", .inject), + .build("type", .enumeration, "custom", .inject), .build("reversesTitleShadowWhenHighlighted", .boolean), .build("showsTouchWhenHighlighted", .boolean), .build("adjustsImageWhenHighlighted", .boolean), diff --git a/EjectKit/CodeGenerators/CodeGeneration.swift b/EjectKit/CodeGenerators/CodeGeneration.swift index 75c5884..f211a4c 100644 --- a/EjectKit/CodeGenerators/CodeGeneration.swift +++ b/EjectKit/CodeGenerators/CodeGeneration.swift @@ -108,7 +108,7 @@ extension Reference { let code = try statements .filter { $0.phase == phase } .map { try $0.generator.generateCode(in: document) } - .flatMap { $0 } + .compactMap { $0 } document.variableNameOverrides[identifier] = original return code } diff --git a/EjectKit/CodeGenerators/Initializer.swift b/EjectKit/CodeGenerators/Initializer.swift index be91df9..0b676f5 100644 --- a/EjectKit/CodeGenerators/Initializer.swift +++ b/EjectKit/CodeGenerators/Initializer.swift @@ -26,7 +26,7 @@ struct Initializer: CodeGenerator { return "\(property): \(value)" } return nil - }.flatMap() { $0 } + }.compactMap() { $0 } return "let \(variable) = \(className)(\(arguments.joined(separator: ", ")))" } diff --git a/EjectKit/CodeGenerators/ValueCodeGenerators.swift b/EjectKit/CodeGenerators/ValueCodeGenerators.swift index 09b09e7..95b1ff0 100644 --- a/EjectKit/CodeGenerators/ValueCodeGenerators.swift +++ b/EjectKit/CodeGenerators/ValueCodeGenerators.swift @@ -12,7 +12,7 @@ struct OptionSetValue: CodeGenerator { let keys: [String] init(attributes: [String: String]) { - let keys = attributes.map() { $0.value == "YES" ? .some($0.key) : nil }.flatMap() { $0 } + let keys = attributes.map() { $0.value == "YES" ? .some($0.key) : nil }.compactMap() { $0 } self.keys = keys } diff --git a/EjectKit/Configuration.swift b/EjectKit/Configuration.swift index 988bafd..940aad1 100644 --- a/EjectKit/Configuration.swift +++ b/EjectKit/Configuration.swift @@ -15,7 +15,11 @@ public struct Configuration { public var constraint: ConstraintConfiguration = .anchor public var postprocessors: [PostProcessor] = [DuplicateVariableProcessor(), TargetActionConfiguration.PostProcessor()] var selfIdentifier: String? = nil - public init() { } + public init(_ constraint: ConstraintConfiguration? = nil) { + if let constraint = constraint { + self.constraint = constraint + } + } } public enum ConstraintConfiguration: String { diff --git a/EjectKit/Foundation+Eject.swift b/EjectKit/Foundation+Eject.swift index 5c2c7c8..eaa1851 100644 --- a/EjectKit/Foundation+Eject.swift +++ b/EjectKit/Foundation+Eject.swift @@ -13,7 +13,7 @@ extension String { func snakeCased() -> String { var newString = "" var previousCharacter: Character? = nil - for character in characters { + for character in self { if previousCharacter == nil { newString.append(String(character).lowercased()) } @@ -84,7 +84,7 @@ extension RangeReplaceableCollection where Iterator.Element : Equatable { mutating func remove(contentsOf array: Array) { for item in array { - if let index = index(of: item) { + if let index = firstIndex(of: item) { remove(at: index) } } diff --git a/Tests/EjectKitTests/EjectKitTests.swift b/Tests/EjectKitTests/EjectKitTests.swift index d9c6b06..5379f6d 100644 --- a/Tests/EjectKitTests/EjectKitTests.swift +++ b/Tests/EjectKitTests/EjectKitTests.swift @@ -352,7 +352,7 @@ class EjectTests: XCTestCase { func testButton() { let xml = wrap("") checkXML(xml, [ - "let button = UIButton(buttonType: .custom)", + "let button = UIButton(type: .custom)", "button.titleLabel?.lineBreakMode = .byTruncatingMiddle", "button.titleLabel?.font = .boldSystemFont(ofSize: 15)", "button.setTitle(\"Title\", for: .normal)",