Skip to content

Commit d68e490

Browse files
committed
Rename ModelRocket class to fix namespacing issue
1 parent 5ffa7ce commit d68e490

File tree

8 files changed

+43
-47
lines changed

8 files changed

+43
-47
lines changed

ModelRocket.playground/Contents.swift

Lines changed: 1 addition & 1 deletion
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")
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' requires-full-environment='true' last-migration='0700'>
2+
<playground version='5.0' target-platform='ios' requires-full-environment='true'>
33
<timeline fileName='timeline.xctimeline'/>
44
</playground>

ModelRocket.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 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
);
@@ -242,7 +242,7 @@
242242
files = (
243243
810653291A847016004CA201 /* PropertyArray.swift in Sources */,
244244
81BECF1A1B8BBBF5000F08E9 /* JSON.swift in Sources */,
245-
81F54F711A82D5F5005C8275 /* ModelRocket.swift in Sources */,
245+
81F54F711A82D5F5005C8275 /* Model.swift in Sources */,
246246
81629FCE1A95780100C2C42D /* PropertyDictionary.swift in Sources */,
247247
81F54F6B1A82D5E1005C8275 /* JSONTransformable.swift in Sources */,
248248
81F54F6E1A82D5ED005C8275 /* Property.swift in Sources */,

ModelRocket/JSONTransformable.swift

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ public protocol JSONTransformable {
3333
func toJSON() -> AnyObject
3434
}
3535

36-
// MARK: Default implementation for ModelRocket subclasses
36+
// MARK: Default implementation for Model subclasses
3737

38-
extension JSONTransformable where Self: ModelRocket {
38+
extension JSONTransformable where Self: Model {
3939
public static func fromJSON(json: JSON) -> Self? {
4040
return Self(json: json)
4141
}
@@ -48,10 +48,7 @@ extension JSONTransformable where Self: ModelRocket {
4848

4949
extension JSONTransformable where Self: RawRepresentable, Self.RawValue == String {
5050
public static func fromJSON(json: JSON) -> Self? {
51-
if let string = json.string {
52-
return Self(rawValue: string)
53-
}
54-
return nil
51+
return Self(rawValue: json.stringValue)
5552
}
5653
public func toJSON() -> AnyObject {
5754
return rawValue
@@ -60,10 +57,7 @@ extension JSONTransformable where Self: RawRepresentable, Self.RawValue == Strin
6057

6158
extension JSONTransformable where Self: RawRepresentable, Self.RawValue == Int {
6259
public static func fromJSON(json: JSON) -> Self? {
63-
if let int = json.int {
64-
return Self(rawValue: int)
65-
}
66-
return nil
60+
return Self(rawValue: json.intValue)
6761
}
6862
public func toJSON() -> AnyObject {
6963
return rawValue

ModelRocket/ModelRocket.swift renamed to ModelRocket/Model.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// ModelRocket.swift
1+
// Model.swift
22
//
33
// Copyright (c) 2015 Oven Bits, LLC
44
//
@@ -22,7 +22,7 @@
2222

2323
import Foundation
2424

25-
public class ModelRocket: NSObject, NSCoding {
25+
public class Model: NSObject, NSCoding {
2626

2727
private var JSONMappings: [PropertyDescription] {
2828
let mirror = Mirror(reflecting: self)
@@ -90,12 +90,12 @@ public class ModelRocket: NSObject, NSCoding {
9090
}
9191
}
9292

93-
public class func modelForJSON(json: JSON) -> ModelRocket {
94-
return ModelRocket(json: json)
93+
public class func modelForJSON(json: JSON) -> Model {
94+
return Model(json: json)
9595
}
9696

97-
public class func modelForStrictJSON(json: JSON) -> ModelRocket? {
98-
return ModelRocket(strictJSON: json)
97+
public class func modelForStrictJSON(json: JSON) -> Model? {
98+
return Model(strictJSON: json)
9999
}
100100

101101
// MARK: JSON

ModelRocket/PropertyDescription.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ public protocol PropertyDescription {
4545
/// Encode object from NSCoder
4646
func decode(decoder: NSCoder)
4747

48-
/// After the whole ModelRocket object has been initialized and its Property properties initalized fromJSON(),
48+
/// After the whole Model object has been initialized and its Property properties initalized fromJSON(),
4949
/// invoked to permit further post-processing of the Property that may depend upon other information from the
50-
/// whole of the ModelRocket object.
50+
/// whole of the Model object.
5151
func initPostProcess()
5252
}

ModelRocketTests/ModelRocketTests.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ class ModelRocketTests: XCTestCase {
492492

493493
// MARK: - Models
494494

495-
class TestModel: ModelRocket {
495+
class TestModel: Model {
496496
let string = Property<String>(key: "string")
497497
let date = Property<NSDate>(key: "date")
498498
let color = Property<UIColor>(key: "color")
@@ -505,27 +505,27 @@ class TestModel: ModelRocket {
505505
let uInt = Property<UInt>(key: "u_int")
506506
}
507507

508-
class TestArrayModel: ModelRocket {
508+
class TestArrayModel: Model {
509509
let strings = PropertyArray<String>(key: "strings")
510510
}
511511

512-
class TestDictionaryModel: ModelRocket {
512+
class TestDictionaryModel: Model {
513513
let ints = PropertyDictionary<Int>(key: "ints")
514514
}
515515

516-
class TestSimpleNestedModel: ModelRocket {
516+
class TestSimpleNestedModel: Model {
517517
let nestedInt = Property<Int>(key: "nest1.nestedInt")
518518
let nestedString = Property<String>(key: "nest1.nest2.nestedString")
519519
}
520520

521-
class TestComplexNestedModel: ModelRocket {
521+
class TestComplexNestedModel: Model {
522522
let int1 = Property<Int>(key: "int1")
523523
let int2 = Property<Int>(key: "nest1.nest2.int2")
524524
let string1 = Property<String>(key: "nest1.nest2.nest3.nest4.string1")
525525
let string2 = Property<String>(key: "nest1.string2")
526526
}
527527

528-
class TestVeryComplexNestedModel: ModelRocket {
528+
class TestVeryComplexNestedModel: Model {
529529
let string1 = Property<String>(key: "nest1.nest2.nest3.nest4.string1")
530530
let string2 = Property<String>(key: "nest1.nest2.nest3.nest5.string2")
531531
let string3 = Property<String>(key: "nest1.nest2.nest6.nest7.string3")
@@ -536,7 +536,7 @@ class TestSubclassModel: TestModel {
536536
let string2 = Property<String>(key: "string2")
537537
}
538538

539-
class TestRequiredModel: ModelRocket {
539+
class TestRequiredModel: Model {
540540
let requiredString = Property<String>(key: "required_string", required: true)
541541
let unrequiredInt = Property<Int>(key: "unrequired_int")
542542
}

README.md

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,10 @@ Then, run `pod install`.
6565

6666
### Creating a custom object
6767

68+
> NOTE: Due to a namespacing issue in v1.0 with the framework and the base model class (`ModelRocket`) having the same name, we decided to rename the `ModelRocket` class to simply `Model`. This change will be effective in the v1.1 release when Swift 2 is officially released. Hooray namespacing!
69+
6870
```swift
69-
class Vehicle: ModelRocket {
71+
class Vehicle: Model {
7072
let make = Property<String>(key: "make")
7173
let model = Property<String>(key: "model", required: true)
7274
let year = Property<Int>(key: "year") { year in
@@ -77,7 +79,7 @@ class Vehicle: ModelRocket {
7779
let color = Property<UIColor>(key: "color", defaultValue: UIColor.blackColor())
7880
}
7981
```
80-
> NOTE: As with all Swift variables, `let` should always be used, unless `var` is absolutely needed. In the case of ModelRocket objects, `let` should be used for all `Property[Array|Dictionary]` properties, as it still allows the underlying `value` to be changed, unless you truly need to reassign the property
82+
> NOTE: As with all Swift variables, `let` should always be used, unless `var` is absolutely needed. In the case of Model objects, `let` should be used for all `Property[Array|Dictionary]` properties, as it still allows the underlying `value` to be changed, unless you truly need to reassign the property
8183
8284
#### Supported Types
8385

@@ -99,7 +101,7 @@ classes out of the box:
99101
### Creating an object with a typed array
100102

101103
```swift
102-
class Vehicles: ModelRocket {
104+
class Vehicles: Model {
103105
let vehicles = PropertyArray<Vehicle>(key: "vehicles")
104106
}
105107
```
@@ -157,7 +159,7 @@ if let make = vehicle.make.value {
157159
}
158160
```
159161

160-
ModelRocket objects also contain a failable initializer, which will only return an initialized object if all properties marked as `required = true` are non-nil.
162+
Model objects also contain a failable initializer, which will only return an initialized object if all properties marked as `required = true` are non-nil.
161163

162164
```swift
163165
// instantiate object, only if `json` contains a value for the `make` property
@@ -187,11 +189,11 @@ The custom object must conform to the JSONTransformable protocol by defining the
187189

188190

189191
```swift
190-
class Vehicle: ModelRocket {
192+
class Vehicle: Model {
191193
let manufacturer = Property<Manufacturer>(key: "manufacturer")
192194
}
193195

194-
class Manufacturer: ModelRocket {
196+
class Manufacturer: Model {
195197
let companyName = Property<String>(key: "company_name")
196198
let headquarters = Property<String>(key: "headquarters")
197199
let founded = Property<NSDate>(key: "founded")
@@ -209,11 +211,11 @@ extension Manufacturer: JSONTransformable {
209211

210212
### Property `postProcess` hook
211213

212-
The `Property` `postProcess` closure (also available on `PropertyArray` and `PropertyDictionary`) provides a mechanism for work to be done after all properties of a `ModelRocket` object have been initialized from JSON but before the `ModelRocket` object has finished initializing.
214+
The `Property` `postProcess` closure (also available on `PropertyArray` and `PropertyDictionary`) provides a mechanism for work to be done after all properties of a `Model` object have been initialized from JSON but before the `Model` object has finished initializing.
213215

214216

215217
```swift
216-
class Vehicles: ModelRocket {
218+
class Vehicles: Model {
217219
let vehicles = PropertyArray<Vehicle>(key: "vehicles") { (values) -> Void in
218220
for vehicle in values {
219221
println("postHook vehicle: \(vehicle.make.value!)")
@@ -256,24 +258,24 @@ This usage pattern enables:
256258

257259

258260
### Implementing a class cluster
259-
Override the `modelForJSON(json: JSON) -> ModelRocket` function
261+
Override the `modelForJSON(json: JSON) -> Model` function
260262

261263
```swift
262-
class Vehicle: ModelRocket {
264+
class Vehicle: Model {
263265
let make = Property<String>(key: "make")
264266
let model = Property<String>(key: "model")
265267
let year = Property<Int>(key: "year")
266268
let color = Property<UIColor>(key: "color")
267269
let manufacturer = Property<Manufacturer>(key: "manufacturer")
268270

269-
override class func modelForJSON(json: JSON) -> ModelRocket {
271+
override class func modelForJSON(json: JSON) -> Vehicle {
270272

271-
switch json["type"].string {
272-
case .Some("car"):
273+
switch json["type"].stringValue {
274+
case "car":
273275
return Car(json: json)
274-
case .Some("plane"):
276+
case "plane":
275277
return Plane(json: json)
276-
case .Some("bike"):
278+
case "bike":
277279
return Bike(json: json)
278280
default:
279281
return Vehicle(json: json)
@@ -301,7 +303,7 @@ default:
301303

302304
### Obtaining the object's JSON representation
303305

304-
Calling the `json()` function on a ModelRocket subclass returns a tuple containing:
306+
Calling the `json()` function on a Model subclass returns a tuple containing:
305307

306308
- `dictionary: [String : AnyObject]`
307309
- `json: JSON`

0 commit comments

Comments
 (0)