-
Notifications
You must be signed in to change notification settings - Fork 57
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
Another Suggestion Needed : Boxing Swift Structs #70
Comments
You can integrate CoreData using You can put a struct in a But lately, I've been using the following items in my data model. It takes a configuration block and so typically, the block captures whatever data I need, including structs, to configure the cell: public typealias ConfigureViewType = (view: UIView) -> Void
public class ConfigurableIndexPathItem: TLIndexPathItem {
public let configure: ConfigureViewType?
public init!(identifier: NSObject!, configure: ConfigureViewType?) {
self.configure = configure
super.init(identifier: identifier, sectionName: nil, cellIdentifier: nil, data: nil)
}
public init!(identifier: NSObject, sectionName: String?, cellIdentifier: String?, data: AnyObject!, configure: ConfigureViewType?) {
self.configure = configure
super.init(identifier: identifier, sectionName: sectionName, cellIdentifier: cellIdentifier, data: data)
}
} Here is a typical usage in a subclass of func updateDataModel(dataItems: [DataModelType]) {
var items: [ConfigurableIndexPathItem] = []
for dataItem in dataItems {
let item = ConfigurableIndexPathItem(identifier: dataItem.id, sectionName: nil, cellIdentifier: CustomCell.identifier, data: nil) { [weak self] in
guard let strongSelf = self else { return }
let cell = $0 as! CustomCell
cell.configureWithDataModel(dataItem)
theme.themeView(cell, type: .SomeThemeType)
}
items.append(item)
}
indexPathController.items = items
}
override func tableView(tableView: UITableView!, configureCell cell: UITableViewCell!, atIndexPath indexPath: NSIndexPath!) {
if let item = indexPathController.dataModel?.itemAtIndexPath(indexPath) as? ConfigurableIndexPathItem {
item.configure?(view: cell)
}
} |
So in
the array of DataModels, a DataModel could be an object that could contain a struct, a managedObject, flags and the like? |
Sure. They're just captured and used internally by the configuration, so TLIPT has no knowledge of them. |
One more last one... so let's say you have inside the struct custom cell classes, say five or six different ones. You would have to set the cell identifier in the stock TLIPT item in the configuration block, correct? And I'm assuming that TLIPT is smart enough to read those stock cell identifiers and register the appropriate cell for dequeuing. |
Tim,
I'm slowing cutting over to Swift from a bunch of ObjC projects that use TLIndexPathTools. I'm a swift noob...
I know you use TTIndexPathTools in a bunch of swift projects. I'm wondering what you have found to be the best/most efficient approach to wrap structs into something that can be used to init a dataModel.
I usually structure a presenter for a viewController that prepares a viewModel...but I'm curious as to what you think would be the best practice for using IndexPathTools and CoreData in a Swift project.
Thanx in advance
The text was updated successfully, but these errors were encountered: