Created
April 23, 2015 21:32
-
-
Save jarsen/add44240f1ec0b1ac4b6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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