Skip to content

Instantly share code, notes, and snippets.

@rnystrom
Last active February 5, 2018 18:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rnystrom/d36a1c221574005f9b38a661a47c63eb to your computer and use it in GitHub Desktop.
Save rnystrom/d36a1c221574005f9b38a661a47c63eb to your computer and use it in GitHub Desktop.
// ListSwiftAdapterDataSource.swift
public class Value {
public let value: ListSwiftDiffable
public let constructor: () -> ListSectionController
public init<T>(value: T, constructor: @escaping () -> ListSwiftSectionController<T>) {
self.value = value
self.constructor = constructor
}
}
public protocol ListSwiftAdapterDataSource: class {
func values(adapter: ListSwiftAdapter) -> [ Value ]
}
// ViewController.swift
var values: [ListSwiftDiffable] = // ....
func values(adapter: ListSwiftAdapter) -> [Value] {
return values.flatMap({ (value: Any) -> Value? in
if let value = value as? Person {
return Value(value: value, constructor: { PersonSectionController() })
}
return nil
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment