Skip to content

Commit 1509afd

Browse files
committed
Update to swift 4.2
1 parent a5eb1df commit 1509afd

File tree

5 files changed

+79
-58
lines changed

5 files changed

+79
-58
lines changed

.swift-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4.0
1+
4.2

Prephirences.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Pod::Spec.new do |s|
22

33
# ――― Spec Metadata ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
44
s.name = "Prephirences"
5-
s.version = "4.0.4"
5+
s.version = "4.1.0"
66
s.summary = "A Swift library to manage preferences"
77
s.description = <<-DESC
88
Prephirences is a Swift library that provides useful protocols and methods to manage preferences.

Prephirences.xcodeproj/project.pbxproj

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@
589589
};
590590
C42114DA1AE7D84900A09DD9 = {
591591
CreatedOnToolsVersion = 6.3;
592-
LastSwiftMigration = 0900;
592+
LastSwiftMigration = 1000;
593593
};
594594
C42114FD1AE7D8E200A09DD9 = {
595595
CreatedOnToolsVersion = 6.3;
@@ -600,7 +600,7 @@
600600
};
601601
C4FF650A1B6B7C7300BFE4F4 = {
602602
CreatedOnToolsVersion = 7.0;
603-
LastSwiftMigration = 0800;
603+
LastSwiftMigration = 1000;
604604
};
605605
};
606606
};
@@ -864,7 +864,7 @@
864864
PRODUCT_NAME = Prephirences;
865865
SDKROOT = watchos;
866866
SKIP_INSTALL = YES;
867-
SWIFT_VERSION = 4.0;
867+
SWIFT_VERSION = 4.2;
868868
TARGETED_DEVICE_FAMILY = 4;
869869
WATCHOS_DEPLOYMENT_TARGET = 3.0;
870870
};
@@ -886,7 +886,7 @@
886886
PRODUCT_NAME = Prephirences;
887887
SDKROOT = watchos;
888888
SKIP_INSTALL = YES;
889-
SWIFT_VERSION = 4.0;
889+
SWIFT_VERSION = 4.2;
890890
TARGETED_DEVICE_FAMILY = 4;
891891
VALIDATE_PRODUCT = YES;
892892
WATCHOS_DEPLOYMENT_TARGET = 3.0;
@@ -910,7 +910,7 @@
910910
SDKROOT = appletvos;
911911
SKIP_INSTALL = YES;
912912
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
913-
SWIFT_VERSION = 4.0;
913+
SWIFT_VERSION = 4.2;
914914
TARGETED_DEVICE_FAMILY = 3;
915915
TVOS_DEPLOYMENT_TARGET = 9.2;
916916
};
@@ -932,7 +932,7 @@
932932
PRODUCT_NAME = Prephirences;
933933
SDKROOT = appletvos;
934934
SKIP_INSTALL = YES;
935-
SWIFT_VERSION = 4.0;
935+
SWIFT_VERSION = 4.2;
936936
TARGETED_DEVICE_FAMILY = 3;
937937
TVOS_DEPLOYMENT_TARGET = 9.2;
938938
VALIDATE_PRODUCT = YES;
@@ -1069,8 +1069,7 @@
10691069
PRODUCT_NAME = Prephirences;
10701070
SDKROOT = iphoneos;
10711071
SKIP_INSTALL = YES;
1072-
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
1073-
SWIFT_VERSION = 4.0;
1072+
SWIFT_VERSION = 4.2;
10741073
TARGETED_DEVICE_FAMILY = "1,2";
10751074
};
10761075
name = Debug;
@@ -1092,8 +1091,7 @@
10921091
PRODUCT_NAME = Prephirences;
10931092
SDKROOT = iphoneos;
10941093
SKIP_INSTALL = YES;
1095-
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
1096-
SWIFT_VERSION = 4.0;
1094+
SWIFT_VERSION = 4.2;
10971095
TARGETED_DEVICE_FAMILY = "1,2";
10981096
VALIDATE_PRODUCT = YES;
10991097
};
@@ -1119,7 +1117,7 @@
11191117
PRODUCT_BUNDLE_IDENTIFIER = tv.phimage.Prephirences;
11201118
PRODUCT_NAME = Prephirences;
11211119
SKIP_INSTALL = YES;
1122-
SWIFT_VERSION = 4.0;
1120+
SWIFT_VERSION = 4.2;
11231121
};
11241122
name = Debug;
11251123
};
@@ -1139,7 +1137,7 @@
11391137
PRODUCT_BUNDLE_IDENTIFIER = tv.phimage.Prephirences;
11401138
PRODUCT_NAME = Prephirences;
11411139
SKIP_INSTALL = YES;
1142-
SWIFT_VERSION = 4.0;
1140+
SWIFT_VERSION = 4.2;
11431141
};
11441142
name = Release;
11451143
};
@@ -1162,7 +1160,7 @@
11621160
PRODUCT_BUNDLE_IDENTIFIER = org.phimage.PrephirencesMacTests;
11631161
PRODUCT_NAME = "$(TARGET_NAME)";
11641162
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
1165-
SWIFT_VERSION = 4.0;
1163+
SWIFT_VERSION = 4.2;
11661164
};
11671165
name = Debug;
11681166
};
@@ -1184,7 +1182,7 @@
11841182
MACOSX_DEPLOYMENT_TARGET = 10.13;
11851183
PRODUCT_BUNDLE_IDENTIFIER = org.phimage.PrephirencesMacTests;
11861184
PRODUCT_NAME = "$(TARGET_NAME)";
1187-
SWIFT_VERSION = 4.0;
1185+
SWIFT_VERSION = 4.2;
11881186
};
11891187
name = Release;
11901188
};
@@ -1198,7 +1196,7 @@
11981196
PRODUCT_BUNDLE_IDENTIFIER = tv.phimage.PrephirencesiOSTests;
11991197
PRODUCT_NAME = "$(TARGET_NAME)";
12001198
SDKROOT = iphoneos;
1201-
SWIFT_VERSION = 4.0;
1199+
SWIFT_VERSION = 4.2;
12021200
};
12031201
name = Debug;
12041202
};
@@ -1211,7 +1209,7 @@
12111209
PRODUCT_BUNDLE_IDENTIFIER = tv.phimage.PrephirencesiOSTests;
12121210
PRODUCT_NAME = "$(TARGET_NAME)";
12131211
SDKROOT = iphoneos;
1214-
SWIFT_VERSION = 4.0;
1212+
SWIFT_VERSION = 4.2;
12151213
VALIDATE_PRODUCT = YES;
12161214
};
12171215
name = Release;

Sources/UserDefaults/UserDefaults+Adds.swift

Lines changed: 59 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -54,64 +54,37 @@ public extension Foundation.UserDefaults {
5454
return nil
5555
}
5656

57-
// MARK: CGRect,CGSize,CGPoint
58-
#if os(OSX)
59-
private func NSStringFromCGRect(_ value: CGRect) -> String {
60-
return NSStringFromRect(NSRectFromCGRect(value))
61-
}
62-
63-
private func NSStringFromCGSize(_ value: CGSize) -> String {
64-
return NSStringFromSize(NSSizeFromCGSize(value))
65-
}
66-
67-
private func NSStringFromCGPoint(_ value: CGPoint) -> String {
68-
return NSStringFromPoint(NSPointFromCGPoint(value))
69-
}
70-
71-
private func CGRectFromString(_ value: String) -> CGRect {
72-
return NSRectToCGRect(NSRectFromString(value))
73-
}
74-
75-
private func CGSizeFromString(_ value: String) -> CGSize {
76-
return NSSizeToCGSize(NSSizeFromString(value))
77-
}
78-
79-
private func CGPointFromString(_ value: String) -> CGPoint {
80-
return NSPointToCGPoint(NSPointFromString(value))
81-
}
82-
#endif
83-
8457
public func cgRect(forKey key: PreferenceKey) -> CGRect? {
8558
if let string = self.string(forKey: key) {
86-
return CGRectFromString(string)
59+
return NSCoder.cgRect(for: string)
8760
}
8861
return nil
8962
}
9063

9164
@nonobjc public func set(_ value: CGRect, forKey key: PreferenceKey) {
92-
self.set(NSStringFromCGRect(value), forKey: key)
65+
self.set(NSCoder.string(for: value), forKey: key)
9366
}
9467

9568
public func cgSize(forKey key: PreferenceKey) -> CGSize? {
9669
if let string = self.string(forKey: key) {
97-
return CGSizeFromString(string)
70+
return NSCoder.cgSize(for: string)
9871
}
9972
return nil
10073
}
10174

10275
@nonobjc public func set(_ value: CGSize, forKey key: PreferenceKey) {
103-
self.set(NSStringFromCGSize(value), forKey: key)
76+
self.set(NSCoder.string(for: value), forKey: key)
10477
}
10578

10679
public func cgPoint(forKey key: PreferenceKey) -> CGPoint? {
10780
if let string = self.string(forKey: key) {
108-
return CGPointFromString(string)
81+
return NSCoder.cgPoint(for: string)
10982
}
11083
return nil
11184
}
11285

11386
@nonobjc public func set(_ value: CGPoint, forKey key: PreferenceKey) {
114-
self.set(NSStringFromCGPoint(value), forKey: key)
87+
self.set(NSCoder.string(for: value), forKey: key)
11588
}
11689

11790
#if os(OSX)
@@ -126,7 +99,7 @@ public extension Foundation.UserDefaults {
12699
// MARK: NSSize
127100
public func nsSizeForKey(key: String) -> NSSize? {
128101
if let string = self.string(forKey: key) {
129-
return NSSizeFromString(string)
102+
return NSCoder.cgSize(for: string)
130103
}
131104
return nil
132105
}
@@ -138,12 +111,58 @@ public extension Foundation.UserDefaults {
138111
public var UserDefaultsKeySeparator = "."
139112

140113
#if os(OSX)
141-
import AppKit
142-
public var UserDefaultsController = NSUserDefaultsController.shared
114+
import AppKit
115+
public var UserDefaultsController = NSUserDefaultsController.shared
116+
117+
// http://stackoverflow.com/questions/29312106/xcode-6-os-x-storyboard-multiple-user-defaults-controllers-bug-with-multiple-sce/29509031#29509031
118+
@objc(SharedUserDefaultsControllerProxy)
119+
public class SharedUserDefaultsControllerProxy: NSObject {
120+
lazy var defaults = UserDefaultsController
121+
}
143122

144-
// http://stackoverflow.com/questions/29312106/xcode-6-os-x-storyboard-multiple-user-defaults-controllers-bug-with-multiple-sce/29509031#29509031
145-
@objc(SharedUserDefaultsControllerProxy)
146-
public class SharedUserDefaultsControllerProxy: NSObject {
147-
lazy var defaults = UserDefaultsController
123+
extension NSCoder {
124+
static func cgRect(for string: String) -> CGRect {
125+
return NSRectToCGRect(NSRectFromString(string))
148126
}
127+
static func cgSize(for string: String) -> CGSize {
128+
return NSSizeToCGSize(NSSizeFromString(string))
129+
}
130+
static func cgPoint(for string: String) -> CGPoint {
131+
return NSPointToCGPoint(NSPointFromString(string))
132+
}
133+
static func string(for value: CGRect) -> String {
134+
return NSStringFromRect(NSRectFromCGRect(value))
135+
}
136+
static func string(for value: CGSize) -> String {
137+
return NSStringFromSize(NSSizeFromCGSize(value))
138+
}
139+
static func string(for value: CGPoint) -> String {
140+
return NSStringFromPoint(NSPointFromCGPoint(value))
141+
}
142+
}
143+
#else
144+
145+
#if swift(>=4.2)
146+
#else
147+
extension NSCoder {
148+
static func cgRect(for string: String) -> CGRect {
149+
return CGRectFromString(string)
150+
}
151+
static func cgSize(for string: String) -> CGSize {
152+
return CGSizeFromString(string))
153+
}
154+
static func cgPoint(for string: String) -> CGPoint {
155+
return CGPointFromString(string)
156+
}
157+
static func string(for value: CGRect) -> String {
158+
return NSStringFromCGRect(value)
159+
}
160+
static func string(for value: CGSize) -> String {
161+
return NSStringFromCGSize(value)
162+
}
163+
static func string(for value: CGPoint) -> String {
164+
return NSStringFromCGPoint(value)
165+
}
166+
}
167+
#endif
149168
#endif

Tests/KeychainTests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import XCTest
1010
@testable import Prephirences
1111

12+
#if os(OSX)
13+
1214
class KeychainTests: XCTestCase {
1315

1416
let mykey = "key"
@@ -78,3 +80,5 @@ class KeychainTests: XCTestCase {
7880
keychain["keychainall"] = nil
7981
}
8082
}
83+
84+
#endif

0 commit comments

Comments
 (0)