Skip to content

Commit d53a984

Browse files
committed
Initial commit
0 parents  commit d53a984

27 files changed

Lines changed: 3399 additions & 0 deletions

.gitignore

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Xcode
2+
#
3+
build/
4+
*.pbxuser
5+
!default.pbxuser
6+
*.mode1v3
7+
!default.mode1v3
8+
*.mode2v3
9+
!default.mode2v3
10+
*.perspectivev3
11+
!default.perspectivev3
12+
xcuserdata
13+
*.xccheckout
14+
*.moved-aside
15+
DerivedData
16+
*.hmap
17+
*.ipa
18+
*.xcuserstate
19+
20+
*.DS_Store
21+
22+
ModelRocket.framework.zip

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
language: objective-c
2+
osx_image: xcode6.4
3+
script:
4+
- xcodebuild -project ModelRocket.xcodeproj -scheme ModelRocket -sdk iphonesimulator8.4 test

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 Oven Bits, LLC
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import ModelRocket
2+
3+
/*:
4+
The **Vehicle** object has four properties, one of
5+
which is required (when using the `strictJSON` initializer).
6+
7+
The underlying value on `Property` is always Optional. However, if the property
8+
is required and the `strictJSON` initializer is used, `value` can be force
9+
unwrapped safely, since the object will be created iff all properties where
10+
`required == true` are found in the JSON object
11+
12+
*/
13+
14+
class Vehicle: ModelRocket {
15+
let model = Property<String>(key: "model")
16+
let year = Property<Int>(key: "year")
17+
let color = Property<UIColor>(key: "color")
18+
let availableColors = PropertyArray<UIColor>(key: "available_colors")
19+
let availableTrims = PropertyDictionary<Int>(key: "available_trims")
20+
/*:
21+
If you would like to avoid the use of `.value` to retrieve
22+
the underlying value of a `Property`, a good pattern to use
23+
is defining the `Property<T>` property as `private` (prefixed with a _)
24+
and declaring a separate, `public` property of type `T`
25+
*/
26+
private let _make = Property<String>(key: "make", required: true)
27+
var make: String {
28+
set { _make.value = newValue }
29+
get { return _make.value ?? "" }
30+
}
31+
}
32+
33+
let json = JSON(data: dataFromResource())
34+
if let vehicle = Vehicle(strictJSON: json) {
35+
vehicle.make
36+
vehicle.model.value
37+
vehicle.year[]
38+
39+
for color in vehicle.availableColors {
40+
println("Color: \(color)")
41+
}
42+
43+
for (key, value) in vehicle.availableTrims {
44+
println("Trim \(key) : \(value)")
45+
}
46+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"make" : "BMW",
3+
"model" : "M5",
4+
"year" : 2015,
5+
"color" : "#132F5B",
6+
"available_colors" : [
7+
"#FF0000",
8+
"#00FF00",
9+
"#0000FF"
10+
],
11+
"available_trims" : {
12+
"sedan" : 1024,
13+
"gran-turismo" : 512
14+
}
15+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//
2+
// This file (and all other Swift source files in the Sources directory of this playground) will be precompiled into a framework which is automatically made available to ModelRocket.playground.
3+
//
4+
5+
import Foundation
6+
7+
public func dataFromResource() -> NSData {
8+
let jsonPath = NSBundle.mainBundle().pathForResource("TestJSON", ofType: "json")
9+
let jsonData = NSData(contentsOfFile: jsonPath!)
10+
11+
return jsonData!
12+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<playground version='5.0' target-platform='ios'>
3+
<timeline fileName='timeline.xctimeline'/>
4+
</playground>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Timeline
3+
version = "3.0">
4+
<TimelineItems>
5+
</TimelineItems>
6+
</Timeline>

ModelRocket.podspec

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Pod::Spec.new do |s|
2+
s.name = "ModelRocket"
3+
s.version = "1.0"
4+
s.license = "MIT"
5+
s.summary = "An iOS framework for creating JSON-based models. Written in Swift."
6+
s.homepage = "https://github.com/ovenbits/ModelRocket"
7+
s.author = { "Jonathan Landon" => "jonathan.landon@ovenbits.com" }
8+
s.source = { :git => "https://github.com/ovenbits/ModelRocket.git", :tag => s.version.to_s }
9+
s.platform = :ios, '8.0'
10+
s.requires_arc = true
11+
s.source_files = ['ModelRocket/*.swift', 'ModelRocket/*.h']
12+
end

0 commit comments

Comments
 (0)