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

Move reuseIdentifier into static string #5

Merged
merged 10 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
158 changes: 129 additions & 29 deletions Example/Base Demo/Components.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,98 @@
objects = {

/* Begin PBXBuildFile section */
A802709A14B2B09B40B27C24 /* Pods.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 28622753AFF41826673AFB29 /* Pods.framework */; settings = {ATTRIBUTES = (Weak, ); }; };
BD4A62441BC1A47D0037C380 /* .gitkeep in Resources */ = {isa = PBXBuildFile; fileRef = BD4A623C1BC1A47D0037C380 /* .gitkeep */; settings = {ASSET_TAGS = (); }; };
BD4A62451BC1A47D0037C380 /* ComponentController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD4A623D1BC1A47D0037C380 /* ComponentController.swift */; settings = {ASSET_TAGS = (); }; };
BD4A62461BC1A47D0037C380 /* ListComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD4A623F1BC1A47D0037C380 /* ListComponent.swift */; settings = {ASSET_TAGS = (); }; };
BD4A62471BC1A47D0037C380 /* components.json in Resources */ = {isa = PBXBuildFile; fileRef = BD4A62401BC1A47D0037C380 /* components.json */; settings = {ASSET_TAGS = (); }; };
BD4A62481BC1A47D0037C380 /* Parser.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD4A62421BC1A47D0037C380 /* Parser.swift */; settings = {ASSET_TAGS = (); }; };
BD4A624B1BC1A4D20037C380 /* ListItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD4A624A1BC1A4D20037C380 /* ListItem.swift */; settings = {ASSET_TAGS = (); }; };
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 = (); }; };
BD6F81A71BC02DFE006ADA1D /* Parser.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD6F81A21BC02DFE006ADA1D /* Parser.swift */; settings = {ASSET_TAGS = (); }; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
28622753AFF41826673AFB29 /* Pods.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods.framework; sourceTree = BUILT_PRODUCTS_DIR; };
5E70EB4CC092C66A8663C4B9 /* Pods.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.debug.xcconfig; path = "Pods/Target Support Files/Pods/Pods.debug.xcconfig"; sourceTree = "<group>"; };
87CF5208C24D6284F4E697DD /* Pods.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.release.xcconfig; path = "Pods/Target Support Files/Pods/Pods.release.xcconfig"; sourceTree = "<group>"; };
BD4A623C1BC1A47D0037C380 /* .gitkeep */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = .gitkeep; sourceTree = "<group>"; };
BD4A623D1BC1A47D0037C380 /* ComponentController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ComponentController.swift; sourceTree = "<group>"; };
BD4A623F1BC1A47D0037C380 /* ListComponent.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ListComponent.swift; sourceTree = "<group>"; };
BD4A62401BC1A47D0037C380 /* components.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = components.json; sourceTree = "<group>"; };
BD4A62421BC1A47D0037C380 /* Parser.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Parser.swift; sourceTree = "<group>"; };
BD4A624A1BC1A4D20037C380 /* ListItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ListItem.swift; sourceTree = "<group>"; };
BD6973631BBFE4FB001DC32F /* Components.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Components.app; sourceTree = BUILT_PRODUCTS_DIR; };
BD6973661BBFE4FB001DC32F /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
BD69736D1BBFE4FB001DC32F /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
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 */
BD4A623B1BC1A47D0037C380 /* Source */ = {
isa = PBXGroup;
children = (
BD4A623C1BC1A47D0037C380 /* .gitkeep */,
BD4A623D1BC1A47D0037C380 /* ComponentController.swift */,
BD4A623E1BC1A47D0037C380 /* Components */,
BD4A62401BC1A47D0037C380 /* components.json */,
BD4A62411BC1A47D0037C380 /* Library */,
BD4A62491BC1A4BB0037C380 /* Models */,
BD4A62431BC1A47D0037C380 /* Protocols */,
);
name = Source;
path = ../../Source;
sourceTree = "<group>";
};
BD4A623E1BC1A47D0037C380 /* Components */ = {
isa = PBXGroup;
children = (
BD4A623F1BC1A47D0037C380 /* ListComponent.swift */,
);
path = Components;
sourceTree = "<group>";
};
BD4A62411BC1A47D0037C380 /* Library */ = {
isa = PBXGroup;
children = (
BD4A62421BC1A47D0037C380 /* Parser.swift */,
);
path = Library;
sourceTree = "<group>";
};
BD4A62431BC1A47D0037C380 /* Protocols */ = {
isa = PBXGroup;
children = (
);
path = Protocols;
sourceTree = "<group>";
};
BD4A62491BC1A4BB0037C380 /* Models */ = {
isa = PBXGroup;
children = (
BD4A624A1BC1A4D20037C380 /* ListItem.swift */,
);
path = Models;
sourceTree = "<group>";
};
BD69735A1BBFE4FB001DC32F = {
isa = PBXGroup;
children = (
BD6F819D1BC02DFE006ADA1D /* Source */,
BD4A623B1BC1A47D0037C380 /* Source */,
BD6973651BBFE4FB001DC32F /* Components */,
BD6973641BBFE4FB001DC32F /* Products */,
DC20B8ABF3750CE9A8F94AD8 /* Pods */,
Expand Down Expand Up @@ -66,19 +126,6 @@
path = Components;
sourceTree = "<group>";
};
BD6F819D1BC02DFE006ADA1D /* Source */ = {
isa = PBXGroup;
children = (
BD6F819E1BC02DFE006ADA1D /* .gitkeep */,
BD6F819F1BC02DFE006ADA1D /* ComponentController.swift */,
BD6F81A01BC02DFE006ADA1D /* components.json */,
BD6F81A11BC02DFE006ADA1D /* ListComponent.swift */,
BD6F81A21BC02DFE006ADA1D /* Parser.swift */,
);
name = Source;
path = ../../Source;
sourceTree = "<group>";
};
DC20B8ABF3750CE9A8F94AD8 /* Pods */ = {
isa = PBXGroup;
children = (
Expand All @@ -103,8 +150,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 @@ -152,24 +203,73 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
BD6F81A51BC02DFE006ADA1D /* components.json in Resources */,
BD4A62441BC1A47D0037C380 /* .gitkeep in Resources */,
BD4A62471BC1A47D0037C380 /* 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;
buildActionMask = 2147483647;
files = (
BD6F81A71BC02DFE006ADA1D /* Parser.swift in Sources */,
BD4A624B1BC1A4D20037C380 /* ListItem.swift in Sources */,
BD4A62481BC1A47D0037C380 /* Parser.swift in Sources */,
BD6973671BBFE4FB001DC32F /* AppDelegate.swift in Sources */,
BD6F81A41BC02DFE006ADA1D /* ComponentController.swift in Sources */,
BD6F81A61BC02DFE006ADA1D /* ListComponent.swift in Sources */,
BD4A62451BC1A47D0037C380 /* ComponentController.swift in Sources */,
BD4A62461BC1A47D0037C380 /* ListComponent.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
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.

2 changes: 1 addition & 1 deletion Example/Base Demo/Components/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
let json = try! NSJSONSerialization.JSONObjectWithData(data!, options: .AllowFragments)

let components = Parser.parse(json as! [String : AnyObject])
let componentController = ComponentsController(components: components)
let componentController = ComponentsController(views: components)

navigationController = UINavigationController(rootViewController: componentController)
window?.rootViewController = navigationController
Expand Down
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
15 changes: 8 additions & 7 deletions Source/ComponentController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@ import UIKit

class ComponentsController: UIViewController {

private let components: [Component]
private let componentViews: [ComponentView]
static let reuseIdentifier = "ComponentCell"

lazy var collectionView: UICollectionView = { [unowned self] in
let layout = UICollectionViewFlowLayout()
layout.itemSize = self.view.bounds.size

let collectionView = UICollectionView(frame: UIScreen.mainScreen().bounds, collectionViewLayout: layout)
collectionView.dataSource = self
collectionView.registerClass(UICollectionViewCell.self, forCellWithReuseIdentifier: "ComponentCell")
collectionView.registerClass(UICollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier)

return collectionView
}()

required init(components: [Component]) {
self.components = components
required init(views: [ComponentView]) {
self.componentViews = views
super.init(nibName: nil, bundle: nil)
self.view.addSubview(collectionView)
}
Expand All @@ -29,12 +30,12 @@ class ComponentsController: UIViewController {
extension ComponentsController: UICollectionViewDataSource {

func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return components.count
return componentViews.count
}

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let view = components[indexPath.item]
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("ComponentCell", forIndexPath: indexPath)
let view = componentViews[indexPath.item]
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(ComponentsController.reuseIdentifier, forIndexPath: indexPath)
cell.contentView.addSubview(view.render())
return cell
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,12 @@
import UIKit
import Tailor
import Sugar

protocol Component {
protocol ComponentView {
func render() -> UIView
}

struct ListItem {
var title = ""
var subtitle = ""
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
}
}

class ListComponent: NSObject, Component {
class ListComponent: NSObject, ComponentView {

lazy var tableView: UITableView = { [unowned self] in
let tableView = UITableView()
Expand Down
25 changes: 25 additions & 0 deletions Source/Library/Parser.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import UIKit
import Sugar

struct Parser {

static func parse(json: JSONDictionary) -> [ComponentView] {
guard let components = json["components"] as? JSONArray else { return [ComponentView]() }
var views = [ComponentView]()
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 {
guard let json = item as? JSONDictionary else { continue }
componentItems.append(ListItem(json: json))
}

views.append(ListComponent(items: componentItems))
}
}

return views
}

}
18 changes: 18 additions & 0 deletions Source/Models/ListItem.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import Tailor
import Sugar

struct ListItem {
var title = ""
var subtitle = ""
var image = ""
var type = ""
var uri: String?

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")
}
}
Loading