Skip to content

Instantly share code, notes, and snippets.

@jarsen
Created April 23, 2015 21:32
Show Gist options
  • Save jarsen/add44240f1ec0b1ac4b6 to your computer and use it in GitHub Desktop.
Save jarsen/add44240f1ec0b1ac4b6 to your computer and use it in GitHub Desktop.
public protocol Section {
typealias U
var count: Int { get }
func itemAtRow(row: Int) -> U
subscript(index: Int) -> U { get }
}
public struct ArraySection<T>: Section {
typealias U = T
public let items: [T]
public init(items: [T]) {
self.items = items
}
public var count: Int {
get {
return items.count
}
}
public func itemAtRow(row: Int) -> U {
return items[row]
}
public subscript(index: Int) -> U {
return itemAtRow(index)
}
}
public struct RLMArraySection<T: RLMObject>: Section {
typealias U = T
public let items: RLMArray
public init(items: RLMArray, type: T.Type) {
self.items = items
}
public var count: Int {
get {
return Int(items.count)
}
}
public func itemAtRow(row: Int) -> U {
return items[UInt(row)] as! U
}
public subscript(index: Int) -> U {
return itemAtRow(index)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment