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

Revert ComponentView renaming #7

Merged
merged 3 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
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 componentViews: [ComponentView]
private let Components: [Component]
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(views: [ComponentView]) {
self.componentViews = views
required init(views: [Component]) {
self.Components = 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 componentViews.count
return Components.count
}

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let view = componentViews[indexPath.item]
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("ComponentCell", forIndexPath: indexPath)
let view = Components[indexPath.item]
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(ComponentsController.reuseIdentifier, forIndexPath: indexPath)
cell.contentView.addSubview(view.render())
return cell
}
Expand Down
4 changes: 2 additions & 2 deletions Source/Components/ListComponent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import UIKit
import Tailor
import Sugar

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

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

lazy var tableView: UITableView = { [unowned self] in
let tableView = UITableView()
Expand Down
14 changes: 6 additions & 8 deletions Source/Library/Parser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,21 @@ import Sugar

struct Parser {

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

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

return views
}

}