Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jlandon committed Aug 25, 2015
0 parents commit d53a984
Show file tree
Hide file tree
Showing 27 changed files with 3,399 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .gitignore
@@ -0,0 +1,22 @@
# Xcode
#
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate

*.DS_Store

ModelRocket.framework.zip
4 changes: 4 additions & 0 deletions .travis.yml
@@ -0,0 +1,4 @@
language: objective-c
osx_image: xcode6.4
script:
- xcodebuild -project ModelRocket.xcodeproj -scheme ModelRocket -sdk iphonesimulator8.4 test
21 changes: 21 additions & 0 deletions LICENSE
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2015 Oven Bits, LLC

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
46 changes: 46 additions & 0 deletions ModelRocket.playground/Contents.swift
@@ -0,0 +1,46 @@
import ModelRocket

/*:
The **Vehicle** object has four properties, one of
which is required (when using the `strictJSON` initializer).
The underlying value on `Property` is always Optional. However, if the property
is required and the `strictJSON` initializer is used, `value` can be force
unwrapped safely, since the object will be created iff all properties where
`required == true` are found in the JSON object
*/

class Vehicle: ModelRocket {
let model = Property<String>(key: "model")
let year = Property<Int>(key: "year")
let color = Property<UIColor>(key: "color")
let availableColors = PropertyArray<UIColor>(key: "available_colors")
let availableTrims = PropertyDictionary<Int>(key: "available_trims")
/*:
If you would like to avoid the use of `.value` to retrieve
the underlying value of a `Property`, a good pattern to use
is defining the `Property<T>` property as `private` (prefixed with a _)
and declaring a separate, `public` property of type `T`
*/
private let _make = Property<String>(key: "make", required: true)
var make: String {
set { _make.value = newValue }
get { return _make.value ?? "" }
}
}

let json = JSON(data: dataFromResource())
if let vehicle = Vehicle(strictJSON: json) {
vehicle.make
vehicle.model.value
vehicle.year[]

for color in vehicle.availableColors {
println("Color: \(color)")
}

for (key, value) in vehicle.availableTrims {
println("Trim \(key) : \(value)")
}
}
15 changes: 15 additions & 0 deletions ModelRocket.playground/Resources/TestJSON.json
@@ -0,0 +1,15 @@
{
"make" : "BMW",
"model" : "M5",
"year" : 2015,
"color" : "#132F5B",
"available_colors" : [
"#FF0000",
"#00FF00",
"#0000FF"
],
"available_trims" : {
"sedan" : 1024,
"gran-turismo" : 512
}
}
12 changes: 12 additions & 0 deletions ModelRocket.playground/Sources/SupportCode.swift
@@ -0,0 +1,12 @@
//
// 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.
//

import Foundation

public func dataFromResource() -> NSData {
let jsonPath = NSBundle.mainBundle().pathForResource("TestJSON", ofType: "json")
let jsonData = NSData(contentsOfFile: jsonPath!)

return jsonData!
}
4 changes: 4 additions & 0 deletions ModelRocket.playground/contents.xcplayground
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='5.0' target-platform='ios'>
<timeline fileName='timeline.xctimeline'/>
</playground>
6 changes: 6 additions & 0 deletions ModelRocket.playground/timeline.xctimeline
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Timeline
version = "3.0">
<TimelineItems>
</TimelineItems>
</Timeline>
12 changes: 12 additions & 0 deletions ModelRocket.podspec
@@ -0,0 +1,12 @@
Pod::Spec.new do |s|
s.name = "ModelRocket"
s.version = "1.0"
s.license = "MIT"
s.summary = "An iOS framework for creating JSON-based models. Written in Swift."
s.homepage = "https://github.com/ovenbits/ModelRocket"
s.author = { "Jonathan Landon" => "jonathan.landon@ovenbits.com" }
s.source = { :git => "https://github.com/ovenbits/ModelRocket.git", :tag => s.version.to_s }
s.platform = :ios, '8.0'
s.requires_arc = true
s.source_files = ['ModelRocket/*.swift', 'ModelRocket/*.h']
end

0 comments on commit d53a984

Please sign in to comment.