Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature object mapping during parsing #2

Merged
merged 5 commits into from
Oct 4, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 64 additions & 4 deletions Example/Base Demo/Components.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
objects = {

/* Begin PBXBuildFile section */
A802709A14B2B09B40B27C24 /* Pods.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 28622753AFF41826673AFB29 /* Pods.framework */; settings = {ATTRIBUTES = (Weak, ); }; };
BD6973671BBFE4FB001DC32F /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD6973661BBFE4FB001DC32F /* AppDelegate.swift */; };
BD69736E1BBFE4FB001DC32F /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = BD69736D1BBFE4FB001DC32F /* Assets.xcassets */; };
BD6973711BBFE4FB001DC32F /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = BD69736F1BBFE4FB001DC32F /* LaunchScreen.storyboard */; };
BD6F81A31BC02DFE006ADA1D /* .gitkeep in Resources */ = {isa = PBXBuildFile; fileRef = BD6F819E1BC02DFE006ADA1D /* .gitkeep */; settings = {ASSET_TAGS = (); }; };
BD6F81A41BC02DFE006ADA1D /* ComponentController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD6F819F1BC02DFE006ADA1D /* ComponentController.swift */; settings = {ASSET_TAGS = (); }; };
BD6F81A51BC02DFE006ADA1D /* components.json in Resources */ = {isa = PBXBuildFile; fileRef = BD6F81A01BC02DFE006ADA1D /* components.json */; settings = {ASSET_TAGS = (); }; };
BD6F81A61BC02DFE006ADA1D /* ListComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD6F81A11BC02DFE006ADA1D /* ListComponent.swift */; settings = {ASSET_TAGS = (); }; };
Expand All @@ -27,13 +27,23 @@
BD6973701BBFE4FB001DC32F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
BD6973721BBFE4FB001DC32F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
BD6973781BBFE56D001DC32F /* components.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = components.json; sourceTree = "<group>"; };
BD6F819E1BC02DFE006ADA1D /* .gitkeep */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = .gitkeep; sourceTree = "<group>"; };
BD6F819F1BC02DFE006ADA1D /* ComponentController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ComponentController.swift; sourceTree = "<group>"; };
BD6F81A01BC02DFE006ADA1D /* components.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = components.json; sourceTree = "<group>"; };
BD6F81A11BC02DFE006ADA1D /* ListComponent.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ListComponent.swift; sourceTree = "<group>"; };
BD6F81A21BC02DFE006ADA1D /* Parser.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Parser.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
E0AF9B8B55A2D13A348A0B23 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
A802709A14B2B09B40B27C24 /* Pods.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
BD69735A1BBFE4FB001DC32F = {
isa = PBXGroup;
Expand Down Expand Up @@ -69,7 +79,6 @@
BD6F819D1BC02DFE006ADA1D /* Source */ = {
isa = PBXGroup;
children = (
BD6F819E1BC02DFE006ADA1D /* .gitkeep */,
BD6F819F1BC02DFE006ADA1D /* ComponentController.swift */,
BD6F81A01BC02DFE006ADA1D /* components.json */,
BD6F81A11BC02DFE006ADA1D /* ListComponent.swift */,
Expand Down Expand Up @@ -103,8 +112,12 @@
isa = PBXNativeTarget;
buildConfigurationList = BD6973751BBFE4FB001DC32F /* Build configuration list for PBXNativeTarget "Components" */;
buildPhases = (
3A1DBEB5A38CEFA65588E4F9 /* Check Pods Manifest.lock */,
BD69735F1BBFE4FB001DC32F /* Sources */,
BD6973611BBFE4FB001DC32F /* Resources */,
E0AF9B8B55A2D13A348A0B23 /* Frameworks */,
20C7BFE4D4EDD01FD2F3C432 /* Embed Pods Frameworks */,
D5F866A6FE97C76B984066C5 /* Copy Pods Resources */,
);
buildRules = (
);
Expand Down Expand Up @@ -155,12 +168,59 @@
BD6F81A51BC02DFE006ADA1D /* components.json in Resources */,
BD6973711BBFE4FB001DC32F /* LaunchScreen.storyboard in Resources */,
BD69736E1BBFE4FB001DC32F /* Assets.xcassets in Resources */,
BD6F81A31BC02DFE006ADA1D /* .gitkeep in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
20C7BFE4D4EDD01FD2F3C432 /* Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "Embed Pods Frameworks";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods/Pods-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
3A1DBEB5A38CEFA65588E4F9 /* Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "Check Pods Manifest.lock";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n";
showEnvVarsInLog = 0;
};
D5F866A6FE97C76B984066C5 /* Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "Copy Pods Resources";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods/Pods-resources.sh\"\n";
showEnvVarsInLog = 0;
};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
BD69735F1BBFE4FB001DC32F /* Sources */ = {
isa = PBXSourcesBuildPhase;
Expand Down
10 changes: 10 additions & 0 deletions Example/Base Demo/Components.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Example/Base Demo/Podfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
source 'https://github.com/CocoaPods/Specs.git'

platform :ios, '8.0'

use_frameworks!
inhibit_all_warnings!

pod 'Sugar', git: 'https://github.com/hyperoslo/Sugar'
pod 'Tailor', git: 'https://github.com/zenangst/Tailor'
27 changes: 27 additions & 0 deletions Example/Base Demo/Podfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
PODS:
- Sugar (0.1.0)
- Tailor (0.2.0)

DEPENDENCIES:
- Sugar (from `https://github.com/hyperoslo/Sugar`)
- Tailor (from `https://github.com/zenangst/Tailor`)

EXTERNAL SOURCES:
Sugar:
:git: https://github.com/hyperoslo/Sugar
Tailor:
:git: https://github.com/zenangst/Tailor

CHECKOUT OPTIONS:
Sugar:
:commit: 964d31e847af1498a019e3d8a0cd94885e4c2d4d
:git: https://github.com/hyperoslo/Sugar
Tailor:
:commit: 6caa8930227fe3c1e62030989bba2df9870dfff5
:git: https://github.com/zenangst/Tailor

SPEC CHECKSUMS:
Sugar: d33f2a3ae10e40c14eb49a2e859f12e82e614817
Tailor: 214469e948557ac67a0d3d93674aeaa686f74e4f

COCOAPODS: 0.39.0.beta.4
16 changes: 9 additions & 7 deletions Source/ListComponent.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import UIKit
import Tailor
import Sugar

protocol Component {
func render() -> UIView
Expand All @@ -10,13 +12,13 @@ struct ListItem {
var image = ""
var type = ""
var uri: String?

init(title: String, subtitle: String, image: String, type: String, uri: String? = nil) {
self.title = title
self.subtitle = subtitle
self.image = image
self.type = type
self.uri = uri
init(json: JSONDictionary) {
self.title <- json.property("title")
self.subtitle <- json.property("subtitle")
self.image <- json.property("image")
self.type <- json.property("type")
self.uri <- json.property("uri")
}
}

Expand Down
23 changes: 6 additions & 17 deletions Source/Parser.swift
Original file line number Diff line number Diff line change
@@ -1,32 +1,21 @@
import UIKit
import Sugar

struct Parser {

static func parse(json: [String : AnyObject]) -> [Component] {
guard let components = json["components"] as? [[String : AnyObject]] else { return [Component]() }

static func parse(json: JSONDictionary) -> [Component] {
guard let components = json["components"] as? JSONArray else { return [Component]() }
var views = [Component]()

for component in components {
if let type = component["type"] as? String,
items = component["items"] as? [AnyObject] where type == "list" {
var componentItems = [ListItem]()
for item in items {
if let title = item["title"] as? String,
subtitle = item["subtitle"] as? String,
image = item["image"] as? String,
type = item["type"] as? String {
var uri: String?
if let target = item["target"] as? [String : String] {
uri = target["uri"]
}
let listItem = ListItem(title: title, subtitle: subtitle, image: image, type: type, uri: uri)
componentItems.append(listItem)
}
guard let json = item as? JSONDictionary else { continue }
componentItems.append(ListItem(json: json))
}

let listComponent = ListComponent(items: componentItems)
views.append(listComponent)
views.append(ListComponent(items: componentItems))
}
}

Expand Down