Created
April 26, 2017 05:03
-
-
Save andersio/179f35ff9ff60c8ebf81f8c6efbb19d1 to your computer and use it in GitHub Desktop.
This file contains 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
// `Entity` protocol. | |
protocol Entity: Codeable { | |
var identifier: UInt { get } | |
} | |
protocol EntityIdentifer: Codeable { | |
var identifier: UInt { get } | |
} | |
struct Identifier<E: Entity>: EntityIdentifer { | |
var identifier: UInt { get } | |
} | |
struct Tweet: Entity { | |
var user: Identifier<User> | |
var content: String | |
var date: Date | |
} | |
// Query | |
let tweets: SignalProducer<[Tweet], NoError> = context.fetch(Tweet.self) | |
.filter(by: .date, condition: .greaterThan(Date().addingTimeInterval(-1000.0))) | |
.filter(by: .user, condition: .equal(Identifier<User>(1))) | |
// Query and Live Updating Instances | |
let tweets: SignalProducer<[Property<Tweet>], NoError> = context.properties(Tweet.self) | |
.filter(by: .date, condition: .greaterThan(Date().addingTimeInterval(-1000.0))) | |
.filter(by: .user, condition: .equal(Identifier<User>(1))) | |
// Live Updating Query | |
let tweets: SignalProducer<ArrayDelta<Tweet>, NoError> = context.collection(Tweet.self) | |
.filter(by: .date, condition: .greaterThan(Date().addingTimeInterval(-1000.0))) | |
.filter(by: .user, condition: .equal(Identifier<User>(1))) | |
// Live updating instance | |
let tweet: Property<Tweet> = context.property(for: Identifier<Tweet>(0)) | |
// Live updating relationship | |
let tweet: Property<User> = context.property(for: Identifier<Tweet>(0)) | |
.flatMap(.latest) { context.property(for: $0.user) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment