Skip to content

Commit f77a025

Browse files
Merge pull request #404 from kishikawakatsumi/swift42
Improve Swift 4.2 compatibility
2 parents d0c6d82 + 405888a commit f77a025

File tree

14 files changed

+107
-19
lines changed

14 files changed

+107
-19
lines changed

Diff for: .travis.yml

+11
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@ script:
1111
- "(cd Lib && travis_retry bundle exec rake $ACTION)"
1212
matrix:
1313
include:
14+
- osx_image: xcode10
15+
env: ACTION=build
16+
- osx_image: xcode10
17+
env: ACTION='build:carthage'
18+
- osx_image: xcode10
19+
env: ACTION='test:iphonesimulator'
20+
- osx_image: xcode10
21+
env: ACTION='test:appletvsimulator'
22+
- osx_image: xcode10
23+
env: ACTION='test:macosx'
24+
1425
- osx_image: xcode9.4
1526
env: ACTION=build
1627
- osx_image: xcode9.4

Diff for: Examples/Example-iOS/Example-iOS.xcodeproj/project.pbxproj

+3
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@
163163
14DAEE8F1A51E1BE0070B77E = {
164164
CreatedOnToolsVersion = 6.2;
165165
DevelopmentTeam = 27AEDK3C9F;
166+
LastSwiftMigration = 1000;
166167
};
167168
};
168169
};
@@ -374,6 +375,7 @@
374375
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
375376
PRODUCT_BUNDLE_IDENTIFIER = "com.kishikawakatsumi.$(PRODUCT_NAME:rfc1034identifier)";
376377
PRODUCT_NAME = "$(TARGET_NAME)";
378+
SWIFT_VERSION = 4.2;
377379
};
378380
name = Debug;
379381
};
@@ -386,6 +388,7 @@
386388
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
387389
PRODUCT_BUNDLE_IDENTIFIER = "com.kishikawakatsumi.$(PRODUCT_NAME:rfc1034identifier)";
388390
PRODUCT_NAME = "$(TARGET_NAME)";
391+
SWIFT_VERSION = 4.2;
389392
};
390393
name = Release;
391394
};

Diff for: Examples/Example-iOS/Example-iOS.xcodeproj/xcshareddata/xcschemes/Example-iOS.xcscheme

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0930"
3+
LastUpgradeVersion = "1000"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

Diff for: Examples/Example-iOS/Example-iOS/AccountsViewController.swift

+22
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,27 @@ class AccountsViewController: UITableViewController {
8282
return cell
8383
}
8484

85+
#if swift(>=4.2)
86+
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
87+
let services = Array(itemsGroupedByService!.keys)
88+
let service = services[indexPath.section]
89+
90+
let keychain = Keychain(service: service)
91+
let items = keychain.allItems()
92+
93+
let item = items[indexPath.row]
94+
let key = item["key"] as! String
95+
96+
keychain[key] = nil
97+
98+
if items.count == 1 {
99+
reloadData()
100+
tableView.deleteSections(IndexSet(integer: indexPath.section), with: .automatic)
101+
} else {
102+
tableView.deleteRows(at: [indexPath], with: .automatic)
103+
}
104+
}
105+
#else
85106
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
86107
let services = Array(itemsGroupedByService!.keys)
87108
let service = services[indexPath.section]
@@ -101,6 +122,7 @@ class AccountsViewController: UITableViewController {
101122
tableView.deleteRows(at: [indexPath], with: .automatic)
102123
}
103124
}
125+
#endif
104126

105127
// MARK:
106128

Diff for: Examples/Example-iOS/Example-iOS/AppDelegate.swift

+6-1
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,13 @@ import UIKit
2929
class AppDelegate: UIResponder, UIApplicationDelegate {
3030
var window: UIWindow?
3131

32+
#if swift(>=4.2)
33+
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
34+
return true
35+
}
36+
#else
3237
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {
3338
return true
3439
}
35-
40+
#endif
3641
}

Diff for: Examples/Example-iOS/Example-iOS/Images.xcassets/AppIcon.appiconset/Contents.json

+5
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@
3939
"idiom" : "iphone",
4040
"size" : "60x60",
4141
"scale" : "3x"
42+
},
43+
{
44+
"idiom" : "ios-marketing",
45+
"size" : "1024x1024",
46+
"scale" : "1x"
4247
}
4348
],
4449
"info" : {

Diff for: Lib/Configurations/Base.xcconfig

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ GCC_WARN_UNUSED_VARIABLE = YES;
3838
VERSIONING_SYSTEM = "apple-generic";
3939
VERSION_INFO_PREFIX = "";
4040

41-
CODE_SIGN_IDENTITY[sdk=iphoneos*] = iPhone Developer;
41+
CODE_SIGN_IDENTITY = ;
4242
DEVELOPMENT_TEAM = ;
4343

4444
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
4545
WATCHOS_DEPLOYMENT_TARGET = 2.0;
4646
TVOS_DEPLOYMENT_TARGET = 9.0;
4747
MACOSX_DEPLOYMENT_TARGET = 10.9;
4848

49-
SWIFT_VERSION = 4.1;
49+
SWIFT_VERSION = 4.2;

Diff for: Lib/Configurations/TestHost.xcconfig

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ EMBEDDED_CONTENT_CONTAINS_SWIFT = YES;
1313
PRODUCT_BUNDLE_IDENTIFIER = com.kishikawakatsumi.KeychainAccess.TestHost;
1414

1515
CODE_SIGN_ENTITLEMENTS = TestHost/TestHost.entitlements;
16-
PROVISIONING_PROFILE_SPECIFIER[sdk=iphone*] = iOS Development;
1716

17+
CODE_SIGN_IDENTITY[sdk=iphone*] = iPhone Developer;
1818
CODE_SIGN_IDENTITY[sdk=macosx*] = Developer ID Application;
19+
PROVISIONING_PROFILE_SPECIFIER[sdk=iphone*] = iOS Development;
1920
PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*] = KeychainAccess Tests;
2021

2122
DEVELOPMENT_TEAM = 27AEDK3C9F;

Diff for: Lib/KeychainAccess.xcodeproj/project.pbxproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -267,12 +267,12 @@
267267
isa = PBXProject;
268268
attributes = {
269269
LastSwiftUpdateCheck = 0730;
270-
LastUpgradeCheck = 0930;
270+
LastUpgradeCheck = 1000;
271271
ORGANIZATIONNAME = "kishikawa katsumi";
272272
TargetAttributes = {
273273
140F195B1A49D79400B0016A = {
274274
CreatedOnToolsVersion = 6.1.1;
275-
LastSwiftMigration = 0900;
275+
LastSwiftMigration = 1000;
276276
ProvisioningStyle = Automatic;
277277
};
278278
140F19661A49D79500B0016A = {

Diff for: Lib/KeychainAccess.xcodeproj/xcshareddata/xcschemes/KeychainAccess.xcscheme

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0930"
3+
LastUpgradeVersion = "1000"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

Diff for: Lib/KeychainAccess.xcodeproj/xcshareddata/xcschemes/TestHost.xcscheme

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0930"
3+
LastUpgradeVersion = "1000"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

Diff for: Lib/Rakefile

+43-9
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,16 @@ end
77

88
def destinations(platform: 'iphonesimulator')
99
if platform == 'iphonesimulator'
10-
if xcode_version.start_with?('9.4')
10+
if xcode_version.start_with?('10')
11+
[ 'name=iPhone 5s,OS=12.0',
12+
'name=iPhone 6,OS=12.0',
13+
'name=iPhone 6s Plus,OS=12.0',
14+
'name=iPhone SE,OS=12.0',
15+
'name=iPad Air 2,OS=12.0',
16+
'name=iPad Pro (9.7-inch),OS=12.0',
17+
'name=iPad Pro (12.9-inch),OS=12.0'
18+
]
19+
elsif xcode_version.start_with?('9.4')
1120
[ 'name=iPhone 5s,OS=11.4',
1221
'name=iPhone 6,OS=11.4',
1322
'name=iPhone 6s Plus,OS=11.4',
@@ -70,7 +79,11 @@ def destinations(platform: 'iphonesimulator')
7079
]
7180
end
7281
elsif platform == 'watchsimulator'
73-
if xcode_version.start_with?('9.4')
82+
if xcode_version.start_with?('10')
83+
[ 'name=Apple Watch Series 4 - 40mm,OS=5.0',
84+
'name=Apple Watch Series 4 - 44mm,OS=5.0'
85+
]
86+
elsif xcode_version.start_with?('9.4')
7487
[ 'name=Apple Watch Series 3 - 38mm,OS=4.3',
7588
'name=Apple Watch Series 3 - 42mm,OS=4.3'
7689
]
@@ -100,7 +113,10 @@ def destinations(platform: 'iphonesimulator')
100113
]
101114
end
102115
elsif platform == 'appletvsimulator'
103-
if xcode_version.start_with?('9.4')
116+
if xcode_version.start_with?('10')
117+
[ 'name=Apple TV 4K,OS=12.0'
118+
]
119+
elsif xcode_version.start_with?('9.4')
104120
[ 'name=Apple TV 4K,OS=11.4'
105121
]
106122
elsif xcode_version.start_with?('9.3')
@@ -157,7 +173,16 @@ namespace :build do
157173
t.add_build_setting('CODE_SIGN_IDENTITY', '')
158174
t.add_build_setting('CODE_SIGNING_REQUIRED', 'NO')
159175
end
160-
if xcode_version.start_with?('9.4')
176+
if xcode_version.start_with?('10')
177+
t.add_build_setting('SWIFT_VERSION', '4.2')
178+
if platform == 'iphonesimulator'
179+
t.add_destination('name=iPhone 7,OS=12.0')
180+
elsif platform == 'watchsimulator'
181+
t.add_destination('name=Apple Watch Series 4 - 44mm,OS=5.0')
182+
elsif platform == 'appletvsimulator'
183+
t.add_destination('name=Apple TV 4K,OS=12.0')
184+
end
185+
elsif xcode_version.start_with?('9.4')
161186
t.add_build_setting('SWIFT_VERSION', '4.1')
162187
if platform == 'iphonesimulator'
163188
t.add_destination('name=iPhone 7,OS=11.4')
@@ -217,12 +242,19 @@ namespace :build do
217242

218243
task :carthage do
219244
sh %[echo 'github \"kishikawakatsumi/KeychainAccess\"' > Cartfile]
220-
if xcode_version.start_with?('8')
221-
sh %[echo SWIFT_VERSION=\"3.0\" > swift3.xcconfig]
222-
sh %[XCODE_XCCONFIG_FILE=`pwd`/swift3.xcconfig carthage update --no-use-binaries]
245+
if xcode_version.start_with?('10')
246+
sh %[echo SWIFT_VERSION=\"4.2\" > swift.xcconfig]
247+
elsif xcode_version.start_with?('9.4')
248+
sh %[echo SWIFT_VERSION=\"4.1\" > swift.xcconfig]
249+
elsif xcode_version.start_with?('9.3')
250+
sh %[echo SWIFT_VERSION=\"4.1\" > swift.xcconfig]
251+
elsif xcode_version.start_with?('9')
252+
sh %[echo SWIFT_VERSION=\"4.0\" > swift.xcconfig]
223253
else
224-
sh %[carthage update --no-use-binaries]
254+
sh %[echo SWIFT_VERSION=\"3.0\" > swift.xcconfig]
225255
end
256+
sh %[XCODE_XCCONFIG_FILE=`pwd`/swift.xcconfig carthage update --no-use-binaries]
257+
sh %[find . -name '*.bcsymbolmap' | xargs grep swiftlang]
226258
end
227259
end
228260

@@ -255,8 +287,10 @@ namespace :test do
255287
t.coverage = true
256288
t.build_dir = 'build'
257289
t.hide_shell_script_environment = true
258-
if xcode_version.start_with?('9.4')
290+
if xcode_version.start_with?('10')
259291
t.add_build_setting('SWIFT_VERSION', '4.2')
292+
elsif xcode_version.start_with?('9.4')
293+
t.add_build_setting('SWIFT_VERSION', '4.1')
260294
elsif xcode_version.start_with?('9.3')
261295
t.add_build_setting('SWIFT_VERSION', '4.1')
262296
elsif xcode_version.start_with?('9')

Diff for: Lib/TestHost/AppDelegate.swift

+6
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,14 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
4242

4343
var window: UIWindow?
4444

45+
#if swift(>=4.2)
46+
private func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
47+
return true
48+
}
49+
#else
4550
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {
4651
return true
4752
}
53+
#endif
4854
}
4955
#endif

Diff for: README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
[![Swift 3.x](https://img.shields.io/badge/Swift-3.x-orange.svg?style=flat)](https://swift.org/)
88
[![Swift 4.0](https://img.shields.io/badge/Swift-4.0-orange.svg?style=flat)](https://swift.org/)
99
[![Swift 4.1](https://img.shields.io/badge/Swift-4.1-orange.svg?style=flat)](https://swift.org/)
10+
[![Swift 4.2](https://img.shields.io/badge/Swift-4.2-orange.svg?style=flat)](https://swift.org/)
1011

1112
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.
1213

@@ -540,7 +541,7 @@ item: [authenticationType: Default, key: honeylemon, server: github.com, class:
540541
| **v2.3.x** | iOS 8+, OSX 10.9+, watchOS 2+, tvOS 9+ | 2.0, 2.1, 2.2 |
541542
| **v2.4.x** | iOS 8+, OSX 10.9+, watchOS 2+, tvOS 9+ | 2.2, 2.3 |
542543
| **v3.0.x** | iOS 8+, OSX 10.9+, watchOS 2+, tvOS 9+ | 3.x |
543-
| **v3.1.x** | iOS 8+, OSX 10.9+, watchOS 2+, tvOS 9+ | 4.0, 4.1 |
544+
| **v3.1.x** | iOS 8+, OSX 10.9+, watchOS 2+, tvOS 9+ | 4.0, 4.1, 4.2 |
544545

545546
## Installation
546547

0 commit comments

Comments
 (0)