Просмотр исходного кода

Improve Swift 4.2 compatibility

Kishikawa Katsumi 6 лет назад
Родитель
Сommit
405888a2e3

+ 3 - 0
Examples/Example-iOS/Example-iOS.xcodeproj/project.pbxproj

@@ -163,6 +163,7 @@
 					14DAEE8F1A51E1BE0070B77E = {
 						CreatedOnToolsVersion = 6.2;
 						DevelopmentTeam = 27AEDK3C9F;
+						LastSwiftMigration = 1000;
 					};
 				};
 			};
@@ -374,6 +375,7 @@
 				LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
 				PRODUCT_BUNDLE_IDENTIFIER = "com.kishikawakatsumi.$(PRODUCT_NAME:rfc1034identifier)";
 				PRODUCT_NAME = "$(TARGET_NAME)";
+				SWIFT_VERSION = 4.2;
 			};
 			name = Debug;
 		};
@@ -386,6 +388,7 @@
 				LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
 				PRODUCT_BUNDLE_IDENTIFIER = "com.kishikawakatsumi.$(PRODUCT_NAME:rfc1034identifier)";
 				PRODUCT_NAME = "$(TARGET_NAME)";
+				SWIFT_VERSION = 4.2;
 			};
 			name = Release;
 		};

+ 1 - 1
Examples/Example-iOS/Example-iOS.xcodeproj/xcshareddata/xcschemes/Example-iOS.xcscheme

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <Scheme
-   LastUpgradeVersion = "0930"
+   LastUpgradeVersion = "1000"
    version = "1.3">
    <BuildAction
       parallelizeBuildables = "YES"

+ 22 - 0
Examples/Example-iOS/Example-iOS/AccountsViewController.swift

@@ -82,6 +82,27 @@ class AccountsViewController: UITableViewController {
         return cell
     }
 
+    #if swift(>=4.2)
+    override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
+        let services = Array(itemsGroupedByService!.keys)
+        let service = services[indexPath.section]
+
+        let keychain = Keychain(service: service)
+        let items = keychain.allItems()
+
+        let item = items[indexPath.row]
+        let key = item["key"] as! String
+
+        keychain[key] = nil
+
+        if items.count == 1 {
+            reloadData()
+            tableView.deleteSections(IndexSet(integer: indexPath.section), with: .automatic)
+        } else {
+            tableView.deleteRows(at: [indexPath], with: .automatic)
+        }
+    }
+    #else
     override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
         let services = Array(itemsGroupedByService!.keys)
         let service = services[indexPath.section]
@@ -101,6 +122,7 @@ class AccountsViewController: UITableViewController {
             tableView.deleteRows(at: [indexPath], with: .automatic)
         }
     }
+    #endif
 
     // MARK:
 

+ 6 - 1
Examples/Example-iOS/Example-iOS/AppDelegate.swift

@@ -29,8 +29,13 @@ import UIKit
 class AppDelegate: UIResponder, UIApplicationDelegate {
     var window: UIWindow?
 
+    #if swift(>=4.2)
+    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
+        return true
+    }
+    #else
     func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {
         return true
     }
-
+    #endif
 }

+ 5 - 0
Examples/Example-iOS/Example-iOS/Images.xcassets/AppIcon.appiconset/Contents.json

@@ -39,6 +39,11 @@
       "idiom" : "iphone",
       "size" : "60x60",
       "scale" : "3x"
+    },
+    {
+      "idiom" : "ios-marketing",
+      "size" : "1024x1024",
+      "scale" : "1x"
     }
   ],
   "info" : {

+ 2 - 2
Lib/Configurations/Base.xcconfig

@@ -38,7 +38,7 @@ GCC_WARN_UNUSED_VARIABLE = YES;
 VERSIONING_SYSTEM = "apple-generic";
 VERSION_INFO_PREFIX = "";
 
-CODE_SIGN_IDENTITY[sdk=iphoneos*] = iPhone Developer;
+CODE_SIGN_IDENTITY = ;
 DEVELOPMENT_TEAM = ;
 
 IPHONEOS_DEPLOYMENT_TARGET = 8.0;
@@ -46,4 +46,4 @@ WATCHOS_DEPLOYMENT_TARGET = 2.0;
 TVOS_DEPLOYMENT_TARGET = 9.0;
 MACOSX_DEPLOYMENT_TARGET = 10.9;
 
-SWIFT_VERSION = 4.1;
+SWIFT_VERSION = 4.2;

+ 2 - 1
Lib/Configurations/TestHost.xcconfig

@@ -13,9 +13,10 @@ EMBEDDED_CONTENT_CONTAINS_SWIFT = YES;
 PRODUCT_BUNDLE_IDENTIFIER = com.kishikawakatsumi.KeychainAccess.TestHost;
 
 CODE_SIGN_ENTITLEMENTS = TestHost/TestHost.entitlements;
-PROVISIONING_PROFILE_SPECIFIER[sdk=iphone*] = iOS Development;
 
+CODE_SIGN_IDENTITY[sdk=iphone*] = iPhone Developer;
 CODE_SIGN_IDENTITY[sdk=macosx*] = Developer ID Application;
+PROVISIONING_PROFILE_SPECIFIER[sdk=iphone*] = iOS Development;
 PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*] = KeychainAccess Tests;
 
 DEVELOPMENT_TEAM = 27AEDK3C9F;

+ 2 - 2
Lib/KeychainAccess.xcodeproj/project.pbxproj

@@ -267,12 +267,12 @@
 			isa = PBXProject;
 			attributes = {
 				LastSwiftUpdateCheck = 0730;
-				LastUpgradeCheck = 0930;
+				LastUpgradeCheck = 1000;
 				ORGANIZATIONNAME = "kishikawa katsumi";
 				TargetAttributes = {
 					140F195B1A49D79400B0016A = {
 						CreatedOnToolsVersion = 6.1.1;
-						LastSwiftMigration = 0900;
+						LastSwiftMigration = 1000;
 						ProvisioningStyle = Automatic;
 					};
 					140F19661A49D79500B0016A = {

+ 1 - 1
Lib/KeychainAccess.xcodeproj/xcshareddata/xcschemes/KeychainAccess.xcscheme

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <Scheme
-   LastUpgradeVersion = "0930"
+   LastUpgradeVersion = "1000"
    version = "1.3">
    <BuildAction
       parallelizeBuildables = "YES"

+ 1 - 1
Lib/KeychainAccess.xcodeproj/xcshareddata/xcschemes/TestHost.xcscheme

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <Scheme
-   LastUpgradeVersion = "0930"
+   LastUpgradeVersion = "1000"
    version = "1.3">
    <BuildAction
       parallelizeBuildables = "YES"

+ 10 - 11
Lib/Rakefile

@@ -243,21 +243,18 @@ namespace :build do
   task :carthage do
     sh %[echo 'github \"kishikawakatsumi/KeychainAccess\"' > Cartfile]
     if xcode_version.start_with?('10')
-      sh %[echo SWIFT_VERSION=\"4.2\" > swift42.xcconfig]
-      sh %[XCODE_XCCONFIG_FILE=`pwd`/swift42.xcconfig carthage update --no-use-binaries]
+      sh %[echo SWIFT_VERSION=\"4.2\" > swift.xcconfig]
     elsif xcode_version.start_with?('9.4')
-      sh %[echo SWIFT_VERSION=\"4.1\" > swift41.xcconfig]
-      sh %[XCODE_XCCONFIG_FILE=`pwd`/swift41.xcconfig carthage update --no-use-binaries]
+      sh %[echo SWIFT_VERSION=\"4.1\" > swift.xcconfig]
     elsif xcode_version.start_with?('9.3')
-      sh %[echo SWIFT_VERSION=\"4.1\" > swift41.xcconfig]
-      sh %[XCODE_XCCONFIG_FILE=`pwd`/swift41.xcconfig carthage update --no-use-binaries]
+      sh %[echo SWIFT_VERSION=\"4.1\" > swift.xcconfig]
     elsif xcode_version.start_with?('9')
-      sh %[echo SWIFT_VERSION=\"4.0\" > swift40.xcconfig]
-      sh %[XCODE_XCCONFIG_FILE=`pwd`/swift40.xcconfig carthage update --no-use-binaries]
+      sh %[echo SWIFT_VERSION=\"4.0\" > swift.xcconfig]
     else
-      sh %[echo SWIFT_VERSION=\"3.0\" > swift3.xcconfig]
-      sh %[XCODE_XCCONFIG_FILE=`pwd`/swift3.xcconfig carthage update --no-use-binaries]
+      sh %[echo SWIFT_VERSION=\"3.0\" > swift.xcconfig]
     end
+    sh %[XCODE_XCCONFIG_FILE=`pwd`/swift.xcconfig carthage update --no-use-binaries]
+    sh %[find . -name '*.bcsymbolmap' | xargs grep swiftlang]
   end
 end
 
@@ -290,8 +287,10 @@ namespace :test do
           t.coverage = true
           t.build_dir = 'build'
           t.hide_shell_script_environment = true
-          if xcode_version.start_with?('9.4')
+          if xcode_version.start_with?('10')
             t.add_build_setting('SWIFT_VERSION', '4.2')
+          elsif xcode_version.start_with?('9.4')
+            t.add_build_setting('SWIFT_VERSION', '4.1')
           elsif xcode_version.start_with?('9.3')
             t.add_build_setting('SWIFT_VERSION', '4.1')
           elsif xcode_version.start_with?('9')

+ 6 - 0
Lib/TestHost/AppDelegate.swift

@@ -42,8 +42,14 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
 
     var window: UIWindow?
 
+    #if swift(>=4.2)
+    private func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
+        return true
+    }
+    #else
     func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {
         return true
     }
+    #endif
 }
 #endif

+ 2 - 1
README.md

@@ -7,6 +7,7 @@
 [![Swift 3.x](https://img.shields.io/badge/Swift-3.x-orange.svg?style=flat)](https://swift.org/)
 [![Swift 4.0](https://img.shields.io/badge/Swift-4.0-orange.svg?style=flat)](https://swift.org/)
 [![Swift 4.1](https://img.shields.io/badge/Swift-4.1-orange.svg?style=flat)](https://swift.org/)
+[![Swift 4.2](https://img.shields.io/badge/Swift-4.2-orange.svg?style=flat)](https://swift.org/)
 
 KeychainAccess is a simple Swift wrapper for Keychain that works on iOS and OS X. Makes using Keychain APIs extremely easy and much more palatable to use in Swift.
 
@@ -540,7 +541,7 @@ item: [authenticationType: Default, key: honeylemon, server: github.com, class:
 | **v2.3.x** | iOS 8+, OSX 10.9+, watchOS 2+, tvOS 9+ | 2.0, 2.1, 2.2 |
 | **v2.4.x** | iOS 8+, OSX 10.9+, watchOS 2+, tvOS 9+ | 2.2, 2.3      |
 | **v3.0.x** | iOS 8+, OSX 10.9+, watchOS 2+, tvOS 9+ | 3.x           |
-| **v3.1.x** | iOS 8+, OSX 10.9+, watchOS 2+, tvOS 9+ | 4.0, 4.1      |
+| **v3.1.x** | iOS 8+, OSX 10.9+, watchOS 2+, tvOS 9+ | 4.0, 4.1, 4.2 |
 
 ## Installation