Skip to content
This repository was archived by the owner on Mar 10, 2022. It is now read-only.
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
6 changes: 4 additions & 2 deletions Sourcery/Sourcery/Classes/Sourcery/ComplexSourcery.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,10 @@ open class ComplexSourcery: NSObject, TableController {
}

open func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if let constructor = sections[indexPath.section].customConstructors[indexPath.row] {
return constructor(tableView, indexPath.row)
let customConstructors = sections[indexPath.section].customConstructors
if customConstructors.count > indexPath.row {
let constructor = customConstructors[indexPath.row]
return constructor!(tableView, indexPath.row)
}

let type = sections[indexPath.section].cellType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,9 +396,11 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
EMBEDDED_CONTENT_CONTAINS_SWIFT = YES;
INFOPLIST_FILE = "$(SRCROOT)/SourceryExample/Support/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.nodes.SourceryExample;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -408,9 +410,11 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
EMBEDDED_CONTENT_CONTAINS_SWIFT = YES;
INFOPLIST_FILE = "$(SRCROOT)/SourceryExample/Support/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.nodes.SourceryExample;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@ class ColorCell: UITableViewCell {

override func awakeFromNib() {
super.awakeFromNib()
colorView.backgroundColor = UIColor.lightGrayColor()
colorView.backgroundColor = UIColor.lightGray
colorView.layer.cornerRadius = 2
selectionStyle = .None
selectionStyle = .none
}

override func prepareForReuse() {
super.prepareForReuse()
colorView.backgroundColor = UIColor.lightGrayColor()
}
colorView.backgroundColor = UIColor.lightGray }

func populateWithColor(color: UIColor) {
colorView.backgroundColor = color
Expand All @@ -34,4 +33,4 @@ extension ColorCell: TableViewPresentable {
static var staticHeight: CGFloat {
return 80.0
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,31 @@ class ComplexViewController: UIViewController {
var sourcery: ComplexSourcery?

let data = (texts: ["First row", "Second row", "Another row"],
colors: [UIColor.redColor(), UIColor.yellowColor(), UIColor.blueColor()])
colors: [UIColor.red, UIColor.yellow, UIColor.blue])

override func viewDidLoad() {
super.viewDidLoad()

navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .Add, target: self, action: #selector(addSection))

let textSection = Section<String, BasicCell>(title: nil, data: data.texts, configurator: { $0.cell.textLabel?.text = $0.object }, selectionHandler: nil)
let colorSection = Section<UIColor, ColorCell>(title: "Colors", data: data.colors, configurator: { $0.cell.populateWithColor($0.object) }, selectionHandler: nil, headerType: CustomHeaderView.self)
navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(addSection))

let textSection = Section<String, BasicCell>(title: nil, data: data.texts, configurator: { (cell, index, object) in
cell.textLabel?.text = object
}, selectionHandler: nil)
let colorSection = Section<UIColor, ColorCell>(title: "Colors", data: data.colors, configurator: { (cell, index, object) in
cell.populateWithColor(color: object)
}, selectionHandler: nil, headerType: CustomHeaderView.self)
sourcery = ComplexSourcery(tableView: tableView, sections: [textSection, colorSection], headerConfigurator: { section, header, title in
if let header = header as? CustomHeaderView {
header.customTitleLabel.text = title
}
})
}

func addSection() {
@objc func addSection() {
var sections = sourcery?.sections ?? []
sections.append(Section<String, BasicCell>(title: "\(sections.count ?? 0 + 1)", data: data.texts, configurator: { $0.cell.textLabel?.text = $0.object }, selectionHandler: nil))
sourcery?.updateSections(newSections: sections)
sections.append(Section<String, BasicCell>(title: "\(sections.count ?? 0 + 1)", data: data.texts, configurator: { (cell, index, object) in
cell.textLabel?.text = object
}, selectionHandler: nil))
sourcery?.update(sections: sections)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,29 @@ class PagedViewController: UIViewController {
super.viewDidLoad()
}

override func viewWillAppear(animated: Bool) {
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
setupSourcery()
}

func setupSourcery() {
let totalCount = data.reduce(0, combine: { $0.0 + $0.1.count })

sourcery = PagedSourcery<String, BasicCell>(tableView: tableView, pageSize: 3, pageLoader: { [weak self] (page, operationQueue, completion) in
operationQueue.addOperationWithBlock({ [weak self] in
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(0.5 * Double(NSEC_PER_SEC))), dispatch_get_main_queue(), { [weak self] in
guard let strongSelf = self else { return }
completion(totalCount: totalCount, data: strongSelf.data[page])
})
})
}, configurator: { $0.cell.textLabel?.text = $0.object })
let totalCount = data.reduce(0, { value, element in
value + element.count
})

sourcery = PagedSourcery<String, BasicCell>(tableView: tableView, pageSize: 3, pageLoader: {
[weak self] (page, operationQueue, completion) in
operationQueue.addOperation { [weak self] in
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + .milliseconds(500), execute: {
DispatchQueue.main.async {
guard let strongSelf = self else { return }
completion(totalCount, strongSelf.data[page])
}
})
}
}, configurator: { (cell, index, object) in
cell.textLabel?.text = object
})
sourcery?.preloadMargin = nil
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,18 @@ class SimpleViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()

sourcery = SimpleSourcery<String, BasicCell>(tableView: tableView, data: data, configurator: { $0.cell.textLabel?.text = $0.object })
sourcery = SimpleSourcery<String, BasicCell>(tableView: tableView, data: data, configurator: { (cell, index, object) in
cell.textLabel?.text = object
})
// sourcery = SimpleSourcery<String, BasicCell>(tableView: tableView, data: data, configurator: { $0.cell.textLabel?.text = $0.object })
}

override func viewWillAppear(animated: Bool) {
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)

var newData: [String] = (sourcery?.data ?? data)
newData.append("New row")
sourcery?.updateData(newData: newData)
sourcery?.update(data: newData)
}
}