Skip to content

Commit 1978ec9

Browse files
committed
Merge swift2 branch
2 parents 14e3ac5 + 93031be commit 1978ec9

18 files changed

+324
-236
lines changed

.travis.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
language: objective-c
2-
osx_image: xcode6.4
3-
# blacklist
4-
branches:
5-
except:
6-
- swift2
2+
osx_image: xcode7
73
script:
8-
- xcodebuild -project ModelRocket.xcodeproj -scheme ModelRocket -sdk iphonesimulator8.4 test
4+
- xcodebuild -project ModelRocket.xcodeproj -scheme ModelRocket -sdk iphonesimulator9.0 test

ModelRocket.playground/Contents.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ unwrapped safely, since the object will be created iff all properties where
1111

1212
*/
1313

14-
class Vehicle: ModelRocket {
14+
class Vehicle: Model {
1515
let model = Property<String>(key: "model")
1616
let year = Property<Int>(key: "year")
1717
let color = Property<UIColor>(key: "color")
@@ -37,10 +37,10 @@ if let vehicle = Vehicle(strictJSON: json) {
3737
vehicle.year[]
3838

3939
for color in vehicle.availableColors {
40-
println("Color: \(color)")
40+
print("Color: \(color)")
4141
}
4242

4343
for (key, value) in vehicle.availableTrims {
44-
println("Trim \(key) : \(value)")
44+
print("Trim \(key) : \(value)")
4545
}
4646
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2-
<playground version='5.0' target-platform='ios'>
2+
<playground version='5.0' target-platform='ios' requires-full-environment='true'>
33
<timeline fileName='timeline.xctimeline'/>
44
</playground>

ModelRocket.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "ModelRocket"
3-
s.version = "1.0"
3+
s.version = "1.1"
44
s.license = "MIT"
55
s.summary = "An iOS framework for creating JSON-based models. Written in Swift."
66
s.homepage = "https://github.com/ovenbits/ModelRocket"

ModelRocket.xcodeproj/project.pbxproj

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
81F54F681A82D5D9005C8275 /* PropertyDescription.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81F54F671A82D5D9005C8275 /* PropertyDescription.swift */; };
1919
81F54F6B1A82D5E1005C8275 /* JSONTransformable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81F54F6A1A82D5E1005C8275 /* JSONTransformable.swift */; };
2020
81F54F6E1A82D5ED005C8275 /* Property.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81F54F6D1A82D5ED005C8275 /* Property.swift */; };
21-
81F54F711A82D5F5005C8275 /* ModelRocket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81F54F701A82D5F5005C8275 /* ModelRocket.swift */; };
21+
81F54F711A82D5F5005C8275 /* Model.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81F54F701A82D5F5005C8275 /* Model.swift */; };
2222
/* End PBXBuildFile section */
2323

2424
/* Begin PBXContainerItemProxy section */
@@ -46,7 +46,7 @@
4646
81F54F671A82D5D9005C8275 /* PropertyDescription.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = PropertyDescription.swift; path = ../ModelRocket/PropertyDescription.swift; sourceTree = "<group>"; };
4747
81F54F6A1A82D5E1005C8275 /* JSONTransformable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = JSONTransformable.swift; path = ../ModelRocket/JSONTransformable.swift; sourceTree = "<group>"; };
4848
81F54F6D1A82D5ED005C8275 /* Property.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Property.swift; path = ../ModelRocket/Property.swift; sourceTree = "<group>"; };
49-
81F54F701A82D5F5005C8275 /* ModelRocket.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ModelRocket.swift; path = ../ModelRocket/ModelRocket.swift; sourceTree = "<group>"; };
49+
81F54F701A82D5F5005C8275 /* Model.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Model.swift; sourceTree = "<group>"; };
5050
/* End PBXFileReference section */
5151

5252
/* Begin PBXFrameworksBuildPhase section */
@@ -95,7 +95,7 @@
9595
81F54F6D1A82D5ED005C8275 /* Property.swift */,
9696
810653281A847016004CA201 /* PropertyArray.swift */,
9797
81629FCD1A95780100C2C42D /* PropertyDictionary.swift */,
98-
81F54F701A82D5F5005C8275 /* ModelRocket.swift */,
98+
81F54F701A82D5F5005C8275 /* Model.swift */,
9999
81BECF191B8BBBF5000F08E9 /* JSON.swift */,
100100
8143C8E41A82BA480077DE22 /* Supporting Files */,
101101
);
@@ -185,7 +185,9 @@
185185
8143C8D81A82BA480077DE22 /* Project object */ = {
186186
isa = PBXProject;
187187
attributes = {
188-
LastUpgradeCheck = 0610;
188+
LastSwiftMigration = 0700;
189+
LastSwiftUpdateCheck = 0700;
190+
LastUpgradeCheck = 0700;
189191
ORGANIZATIONNAME = "Oven Bits";
190192
TargetAttributes = {
191193
8143C8E01A82BA480077DE22 = {
@@ -240,7 +242,7 @@
240242
files = (
241243
810653291A847016004CA201 /* PropertyArray.swift in Sources */,
242244
81BECF1A1B8BBBF5000F08E9 /* JSON.swift in Sources */,
243-
81F54F711A82D5F5005C8275 /* ModelRocket.swift in Sources */,
245+
81F54F711A82D5F5005C8275 /* Model.swift in Sources */,
244246
81629FCE1A95780100C2C42D /* PropertyDictionary.swift in Sources */,
245247
81F54F6B1A82D5E1005C8275 /* JSONTransformable.swift in Sources */,
246248
81F54F6E1A82D5ED005C8275 /* Property.swift in Sources */,
@@ -289,6 +291,7 @@
289291
COPY_PHASE_STRIP = NO;
290292
CURRENT_PROJECT_VERSION = 1;
291293
ENABLE_STRICT_OBJC_MSGSEND = YES;
294+
ENABLE_TESTABILITY = YES;
292295
GCC_C_LANGUAGE_STANDARD = gnu99;
293296
GCC_DYNAMIC_NO_PIC = NO;
294297
GCC_OPTIMIZATION_LEVEL = 0;
@@ -367,6 +370,7 @@
367370
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
368371
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
369372
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
373+
PRODUCT_BUNDLE_IDENTIFIER = "com.ovenbits.$(PRODUCT_NAME:rfc1034identifier)";
370374
PRODUCT_NAME = ModelRocket;
371375
SKIP_INSTALL = YES;
372376
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
@@ -387,6 +391,7 @@
387391
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
388392
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
389393
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
394+
PRODUCT_BUNDLE_IDENTIFIER = "com.ovenbits.$(PRODUCT_NAME:rfc1034identifier)";
390395
PRODUCT_NAME = ModelRocket;
391396
SKIP_INSTALL = YES;
392397
};
@@ -405,6 +410,7 @@
405410
);
406411
INFOPLIST_FILE = ModelRocketTests/Info.plist;
407412
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
413+
PRODUCT_BUNDLE_IDENTIFIER = "com.ovenbits.$(PRODUCT_NAME:rfc1034identifier)";
408414
PRODUCT_NAME = ModelRocketTests;
409415
};
410416
name = Debug;
@@ -418,6 +424,7 @@
418424
);
419425
INFOPLIST_FILE = ModelRocketTests/Info.plist;
420426
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
427+
PRODUCT_BUNDLE_IDENTIFIER = "com.ovenbits.$(PRODUCT_NAME:rfc1034identifier)";
421428
PRODUCT_NAME = ModelRocketTests;
422429
};
423430
name = Release;

ModelRocket.xcodeproj/xcshareddata/xcschemes/ModelRocket.xcscheme

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0610"
3+
LastUpgradeVersion = "0700"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"
@@ -37,10 +37,11 @@
3737
</BuildActionEntries>
3838
</BuildAction>
3939
<TestAction
40+
buildConfiguration = "Debug"
4041
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
4142
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
4243
shouldUseLaunchSchemeArgsEnv = "YES"
43-
buildConfiguration = "Debug">
44+
codeCoverageEnabled = "YES">
4445
<Testables>
4546
<TestableReference
4647
skipped = "NO">
@@ -62,15 +63,18 @@
6263
ReferencedContainer = "container:ModelRocket.xcodeproj">
6364
</BuildableReference>
6465
</MacroExpansion>
66+
<AdditionalOptions>
67+
</AdditionalOptions>
6568
</TestAction>
6669
<LaunchAction
70+
buildConfiguration = "Debug"
6771
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
6872
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
6973
launchStyle = "0"
7074
useCustomWorkingDirectory = "NO"
71-
buildConfiguration = "Debug"
7275
ignoresPersistentStateOnLaunch = "NO"
7376
debugDocumentVersioning = "YES"
77+
debugServiceExtension = "internal"
7478
allowLocationSimulation = "YES">
7579
<MacroExpansion>
7680
<BuildableReference
@@ -85,10 +89,10 @@
8589
</AdditionalOptions>
8690
</LaunchAction>
8791
<ProfileAction
92+
buildConfiguration = "Release"
8893
shouldUseLaunchSchemeArgsEnv = "YES"
8994
savedToolIdentifier = ""
9095
useCustomWorkingDirectory = "NO"
91-
buildConfiguration = "Release"
9296
debugDocumentVersioning = "YES">
9397
<MacroExpansion>
9498
<BuildableReference

ModelRocket/Info.plist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
<key>CFBundleExecutable</key>
88
<string>$(EXECUTABLE_NAME)</string>
99
<key>CFBundleIdentifier</key>
10-
<string>com.ovenbits.$(PRODUCT_NAME:rfc1034identifier)</string>
10+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
1111
<key>CFBundleInfoDictionaryVersion</key>
1212
<string>6.0</string>
1313
<key>CFBundleName</key>
1414
<string>$(PRODUCT_NAME)</string>
1515
<key>CFBundlePackageType</key>
1616
<string>FMWK</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>1.0</string>
18+
<string>1.1</string>
1919
<key>CFBundleSignature</key>
2020
<string>????</string>
2121
<key>CFBundleVersion</key>

ModelRocket/JSON.swift

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public struct JSON {
3535
}
3636

3737
public init(data: NSData?) {
38-
if let data = data, let object: AnyObject = NSJSONSerialization.JSONObjectWithData(data, options: .AllowFragments, error: nil) {
38+
if let data = data, let object: AnyObject = try? NSJSONSerialization.JSONObjectWithData(data, options: .AllowFragments) {
3939
self.init(object)
4040
}
4141
else {
@@ -69,17 +69,21 @@ public struct JSON {
6969
return JSON()
7070
}
7171
}
72+
73+
public var isNil: Bool {
74+
return (object == nil)
75+
}
7276
}
7377

74-
// MARK: - Printable
78+
// MARK: - CustomStringConvertible
7579

76-
extension JSON: Printable {
80+
extension JSON: CustomStringConvertible {
7781
public var description: String {
7882
if let object: AnyObject = object {
7983
switch object {
8084
case is String, is NSNumber, is Float, is Double, is Int, is UInt, is Bool: return "\(object)"
8185
case is [AnyObject], is [String : AnyObject]:
82-
if let data = NSJSONSerialization.dataWithJSONObject(object, options: .PrettyPrinted, error: nil) {
86+
if let data = try? NSJSONSerialization.dataWithJSONObject(object, options: .PrettyPrinted) {
8387
return NSString(data: data, encoding: NSUTF8StringEncoding) as? String ?? ""
8488
}
8589
default: return ""
@@ -90,9 +94,9 @@ extension JSON: Printable {
9094
}
9195
}
9296

93-
// MARK: - DebugPrintable
97+
// MARK: - CustomDebugStringConvertible
9498

95-
extension JSON: DebugPrintable {
99+
extension JSON: CustomDebugStringConvertible {
96100
public var debugDescription: String {
97101
return description
98102
}
@@ -265,7 +269,7 @@ extension JSON {
265269
extension JSON {
266270
public var dictionary: [String : JSON]? {
267271
if let dictionary = object as? [String : AnyObject] {
268-
return Dictionary(map(dictionary) { ($0, JSON($1)) })
272+
return Dictionary(dictionary.map { ($0, JSON($1)) })
269273
}
270274
return nil
271275
}
@@ -286,27 +290,29 @@ extension Dictionary {
286290
extension JSON: Equatable {}
287291

288292
public func ==(lhs: JSON, rhs: JSON) -> Bool {
289-
if let lhsObject: AnyObject = lhs.object, rhsObject: AnyObject = rhs.object {
290-
switch (lhsObject, rhsObject) {
291-
case (let left as String, let right as String):
292-
return left == right
293-
case (let left as Double, let right as Double):
294-
return left == right
295-
case (let left as Float, let right as Float):
296-
return left == right
297-
case (let left as Int, let right as Int):
298-
return left == right
299-
case (let left as UInt, let right as UInt):
300-
return left == right
301-
case (let left as Bool, let right as Bool):
302-
return left == right
303-
case (let left as [AnyObject], let right as [AnyObject]):
304-
return left.map { JSON($0) } == right.map { JSON ($0) }
305-
case (let left as [String : AnyObject], let right as [String : AnyObject]):
306-
return Dictionary(map(left) { ($0, JSON($1)) }) == Dictionary(map(right) { ($0, JSON($1)) })
307-
default: return false
308-
}
293+
guard let lhsObject: AnyObject = lhs.object, rhsObject: AnyObject = rhs.object else { return false }
294+
295+
switch (lhsObject, rhsObject) {
296+
case (let left as String, let right as String):
297+
return left == right
298+
case (let left as Double, let right as Double):
299+
return left == right
300+
case (let left as Float, let right as Float):
301+
return left == right
302+
case (let left as Int, let right as Int):
303+
return left == right
304+
case (let left as UInt, let right as UInt):
305+
return left == right
306+
case (let left as Bool, let right as Bool):
307+
return left == right
308+
case (let left as NSURL, let right as NSURL):
309+
return left == right
310+
case (let left as NSNumber, let right as NSNumber):
311+
return left == right
312+
case (let left as [AnyObject], let right as [AnyObject]):
313+
return left.map { JSON($0) } == right.map { JSON ($0) }
314+
case (let left as [String : AnyObject], let right as [String : AnyObject]):
315+
return Dictionary(left.map { ($0, JSON($1)) }) == Dictionary(right.map { ($0, JSON($1)) })
316+
default: return false
309317
}
310-
311-
return false
312318
}

ModelRocket/JSONTransformable.swift

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,37 @@ public protocol JSONTransformable {
3333
func toJSON() -> AnyObject
3434
}
3535

36+
// MARK: Default implementation for Model subclasses
37+
38+
extension JSONTransformable where Self: Model {
39+
public static func fromJSON(json: JSON) -> Self? {
40+
return Self(strictJSON: json)
41+
}
42+
public func toJSON() -> AnyObject {
43+
return json().dictionary
44+
}
45+
}
46+
47+
// MARK: Default implementation for RawRepresentable types
48+
49+
extension JSONTransformable where Self: RawRepresentable, Self.RawValue == String {
50+
public static func fromJSON(json: JSON) -> Self? {
51+
return Self(rawValue: json.stringValue)
52+
}
53+
public func toJSON() -> AnyObject {
54+
return rawValue
55+
}
56+
}
57+
58+
extension JSONTransformable where Self: RawRepresentable, Self.RawValue == Int {
59+
public static func fromJSON(json: JSON) -> Self? {
60+
return Self(rawValue: json.intValue)
61+
}
62+
public func toJSON() -> AnyObject {
63+
return rawValue
64+
}
65+
}
66+
3667
// MARK: String
3768

3869
extension String: JSONTransformable {
@@ -117,7 +148,7 @@ extension NSURL: JSONTransformable {
117148
return json.URL
118149
}
119150
public func toJSON() -> AnyObject {
120-
return absoluteString ?? ""
151+
return absoluteString
121152
}
122153
}
123154

0 commit comments

Comments
 (0)