Skip to content

Commit cc1da41

Browse files
committed
Refactor and create framework project
1 parent cde3ff6 commit cc1da41

34 files changed

+2277
-669
lines changed

Demo/Demo.xcodeproj/project.pbxproj

Lines changed: 516 additions & 0 deletions
Large diffs are not rendered by default.

Demo/Demo/AppDelegate.swift

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//
2+
// AppDelegate.swift
3+
// Demo
4+
//
5+
// Created by Matthew Cheok on 18/7/15.
6+
// Copyright © 2015 matthewcheok. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
@UIApplicationMain
12+
class AppDelegate: UIResponder, UIApplicationDelegate {
13+
14+
var window: UIWindow?
15+
16+
17+
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
18+
// Override point for customization after application launch.
19+
return true
20+
}
21+
22+
func applicationWillResignActive(application: UIApplication) {
23+
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
24+
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
25+
}
26+
27+
func applicationDidEnterBackground(application: UIApplication) {
28+
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
29+
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
30+
}
31+
32+
func applicationWillEnterForeground(application: UIApplication) {
33+
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
34+
}
35+
36+
func applicationDidBecomeActive(application: UIApplication) {
37+
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
38+
}
39+
40+
func applicationWillTerminate(application: UIApplication) {
41+
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
42+
}
43+
44+
45+
}
46+
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "iphone",
5+
"size" : "29x29",
6+
"scale" : "2x"
7+
},
8+
{
9+
"idiom" : "iphone",
10+
"size" : "29x29",
11+
"scale" : "3x"
12+
},
13+
{
14+
"idiom" : "iphone",
15+
"size" : "40x40",
16+
"scale" : "2x"
17+
},
18+
{
19+
"idiom" : "iphone",
20+
"size" : "40x40",
21+
"scale" : "3x"
22+
},
23+
{
24+
"idiom" : "iphone",
25+
"size" : "60x60",
26+
"scale" : "2x"
27+
},
28+
{
29+
"idiom" : "iphone",
30+
"size" : "60x60",
31+
"scale" : "3x"
32+
}
33+
],
34+
"info" : {
35+
"version" : 1,
36+
"author" : "xcode"
37+
}
38+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="8150" systemVersion="15A204g" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" initialViewController="01J-lp-oVM">
3+
<dependencies>
4+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8122"/>
5+
</dependencies>
6+
<scenes>
7+
<!--View Controller-->
8+
<scene sceneID="EHf-IW-A2E">
9+
<objects>
10+
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
11+
<layoutGuides>
12+
<viewControllerLayoutGuide type="top" id="Llm-lL-Icb"/>
13+
<viewControllerLayoutGuide type="bottom" id="xb3-aO-Qok"/>
14+
</layoutGuides>
15+
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
16+
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
17+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
18+
<animations/>
19+
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
20+
</view>
21+
</viewController>
22+
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
23+
</objects>
24+
<point key="canvasLocation" x="53" y="375"/>
25+
</scene>
26+
</scenes>
27+
</document>

Demo/Demo/Base.lproj/Main.storyboard

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="8152.3" systemVersion="14E46" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
3+
<dependencies>
4+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8124.4"/>
5+
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
6+
</dependencies>
7+
<scenes>
8+
<!--View Controller-->
9+
<scene sceneID="tne-QT-ifu">
10+
<objects>
11+
<viewController id="BYZ-38-t0r" customClass="ViewController" customModule="Demo" customModuleProvider="target" sceneMemberID="viewController">
12+
<layoutGuides>
13+
<viewControllerLayoutGuide type="top" id="y3c-jy-aDJ"/>
14+
<viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
15+
</layoutGuides>
16+
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
17+
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
18+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
19+
<subviews>
20+
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Check console for output" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="HCZ-5t-kN4">
21+
<rect key="frame" x="20" y="20" width="560" height="580"/>
22+
<fontDescription key="fontDescription" type="system" pointSize="17"/>
23+
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
24+
<nil key="highlightedColor"/>
25+
</label>
26+
</subviews>
27+
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
28+
<constraints>
29+
<constraint firstAttribute="trailingMargin" secondItem="HCZ-5t-kN4" secondAttribute="trailing" id="2Za-wu-AH4"/>
30+
<constraint firstItem="HCZ-5t-kN4" firstAttribute="top" secondItem="y3c-jy-aDJ" secondAttribute="bottom" id="esP-dj-fuc"/>
31+
<constraint firstItem="wfy-db-euE" firstAttribute="top" secondItem="HCZ-5t-kN4" secondAttribute="bottom" id="hYl-9V-jCV"/>
32+
<constraint firstItem="HCZ-5t-kN4" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leadingMargin" id="uwP-hf-Fv0"/>
33+
</constraints>
34+
</view>
35+
</viewController>
36+
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
37+
</objects>
38+
</scene>
39+
</scenes>
40+
</document>

Demo/Demo/Company.swift

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//
2+
// Company.swift
3+
// Demo
4+
//
5+
// Created by Matthew Cheok on 18/7/15.
6+
// Copyright © 2015 matthewcheok. All rights reserved.
7+
//
8+
9+
import Foundation
10+
import JSONCodable
11+
12+
struct Company {
13+
let name: String
14+
var address: String?
15+
}
16+
17+
extension Company: JSONCodable {
18+
init?(JSONDictionary: [String : AnyObject]) {
19+
do {
20+
name = try JSONDictionary.decode("name")
21+
address = try JSONDictionary.decode("address")
22+
}
23+
catch {
24+
print(error)
25+
return nil
26+
}
27+
}
28+
29+
func toJSON() throws -> AnyObject {
30+
var result = [String: AnyObject]()
31+
try result.encode(name, key: "name")
32+
try result.encode(address, key: "address")
33+
return result
34+
}
35+
}

Demo/Demo/Info.plist

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>en</string>
7+
<key>CFBundleExecutable</key>
8+
<string>$(EXECUTABLE_NAME)</string>
9+
<key>CFBundleIdentifier</key>
10+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
11+
<key>CFBundleInfoDictionaryVersion</key>
12+
<string>6.0</string>
13+
<key>CFBundleName</key>
14+
<string>$(PRODUCT_NAME)</string>
15+
<key>CFBundlePackageType</key>
16+
<string>APPL</string>
17+
<key>CFBundleShortVersionString</key>
18+
<string>1.0</string>
19+
<key>CFBundleSignature</key>
20+
<string>????</string>
21+
<key>CFBundleVersion</key>
22+
<string>1</string>
23+
<key>LSRequiresIPhoneOS</key>
24+
<true/>
25+
<key>UILaunchStoryboardName</key>
26+
<string>LaunchScreen</string>
27+
<key>UIMainStoryboardFile</key>
28+
<string>Main</string>
29+
<key>UIRequiredDeviceCapabilities</key>
30+
<array>
31+
<string>armv7</string>
32+
</array>
33+
<key>UISupportedInterfaceOrientations</key>
34+
<array>
35+
<string>UIInterfaceOrientationPortrait</string>
36+
<string>UIInterfaceOrientationLandscapeLeft</string>
37+
<string>UIInterfaceOrientationLandscapeRight</string>
38+
</array>
39+
</dict>
40+
</plist>

Demo/Demo/User.swift

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//
2+
// User.swift
3+
// Demo
4+
//
5+
// Created by Matthew Cheok on 18/7/15.
6+
// Copyright © 2015 matthewcheok. All rights reserved.
7+
//
8+
9+
import Foundation
10+
import JSONCodable
11+
12+
struct User {
13+
let id: Int
14+
let name: String
15+
var email: String?
16+
var company: Company?
17+
var friends: [User] = []
18+
var website: NSURL?
19+
}
20+
21+
extension User: JSONCodable {
22+
init?(JSONDictionary: [String : AnyObject]) {
23+
do {
24+
id = try JSONDictionary.decode("id")
25+
name = try JSONDictionary.decode("full_name")
26+
email = try JSONDictionary.decode("email")
27+
company = try JSONDictionary.decode("company")
28+
friends = try JSONDictionary.decode("friends")
29+
website = try JSONDictionary.decode("website", transformer: JSONTransformers.StringToNSURL)
30+
}
31+
catch {
32+
print(error)
33+
return nil
34+
}
35+
}
36+
37+
func toJSON() throws -> AnyObject {
38+
var result = [String: AnyObject]()
39+
try result.encode(id, key: "id")
40+
try result.encode(name, key: "full_name")
41+
try result.encode(email, key: "email")
42+
try result.encode(company, key: "company")
43+
try result.encode(friends, key: "friends")
44+
try result.encode(website, key: "website", transformer: JSONTransformers.StringToNSURL)
45+
return result
46+
}
47+
}

Demo/Demo/ViewController.swift

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
//
2+
// ViewController.swift
3+
// Demo
4+
//
5+
// Created by Matthew Cheok on 18/7/15.
6+
// Copyright © 2015 matthewcheok. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
class ViewController: UIViewController {
12+
13+
override func viewDidLoad() {
14+
super.viewDidLoad()
15+
// Do any additional setup after loading the view, typically from a nib.
16+
17+
18+
let JSON = [
19+
"id": 24,
20+
"full_name": "John Appleseed",
21+
"email": "[email protected]",
22+
"company": [
23+
"name": "Apple",
24+
"address": "1 Infinite Loop, Cupertino, CA"
25+
],
26+
"friends": [
27+
["id": 27, "full_name": "Bob Jefferson"],
28+
["id": 29, "full_name": "Jen Jackson"]
29+
]
30+
]
31+
32+
print("Initial JSON:\n\(JSON)\n\n")
33+
34+
let user = User(JSONDictionary: JSON)!
35+
36+
print("Decoded: \n\(user)\n\n")
37+
38+
do {
39+
let dict = try user.toJSON()
40+
print("Encoded: \n\(dict as! [String: AnyObject])\n\n")
41+
}
42+
catch {
43+
print("Error: \(error)")
44+
}
45+
46+
//do {
47+
// let string = try user.JSONString()
48+
// print(string)
49+
//
50+
// let userAgain = User(JSONString: string)
51+
// print(userAgain)
52+
//} catch {
53+
// print("Error: \(error)")
54+
//}
55+
56+
}
57+
58+
override func didReceiveMemoryWarning() {
59+
super.didReceiveMemoryWarning()
60+
// Dispose of any resources that can be recreated.
61+
}
62+
63+
64+
}
65+

Demo/DemoTests/DemoTests.swift

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//
2+
// DemoTests.swift
3+
// DemoTests
4+
//
5+
// Created by Matthew Cheok on 18/7/15.
6+
// Copyright © 2015 matthewcheok. All rights reserved.
7+
//
8+
9+
import XCTest
10+
@testable import Demo
11+
12+
class DemoTests: XCTestCase {
13+
14+
override func setUp() {
15+
super.setUp()
16+
// Put setup code here. This method is called before the invocation of each test method in the class.
17+
}
18+
19+
override func tearDown() {
20+
// Put teardown code here. This method is called after the invocation of each test method in the class.
21+
super.tearDown()
22+
}
23+
24+
func testExample() {
25+
// This is an example of a functional test case.
26+
// Use XCTAssert and related functions to verify your tests produce the correct results.
27+
}
28+
29+
func testPerformanceExample() {
30+
// This is an example of a performance test case.
31+
self.measureBlock {
32+
// Put the code you want to measure the time of here.
33+
}
34+
}
35+
36+
}

0 commit comments

Comments
 (0)