meteor-ios
meteor-ios copied to clipboard
METDatabaseDidChangeNotification : Swift documentation
We are trying to implement the Meteor-iOS framework in Swift and are attempting to translate from Objective-C. How can we get notified when changes occur to the collection? For some reason databaseDidChange does not fire when the collection is changed.
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "databaseDidChange:", name: METDatabaseDidChangeNotification, object: Meteor)
Meteor.addSubscriptionWithName("snippets") { (error) -> Void in
if (error == nil) {
print("success I have subscribet to snippets collection")
}else{
print("error: \(error)")
}
}
let snippets = Meteor.database.collectionWithName("snippets")
let allSnippets = snippets.allDocuments
print(allSnippets)
}
func databaseDidChange(notification:NSNotification){
dispatch_async(dispatch_get_main_queue()) {
print("database did change")
}
}
Also would it be possible to get a working Swift example for this method, it is so central to the functioning of the framework:
METDatabaseChanges *databaseChanges = notification.userInfo[METDatabaseChangesKey];
[databaseChanges enumerateDocumentChangeDetailsUsingBlock:^(METDocumentChangeDetails *documentChangeDetails, BOOL *stop) {
...
}
I figured out the first part myself. The NSNotification observer object has to change from Meteor to Meteor.database
NSNotificationCenter.defaultCenter().addObserver(self, selector: "databaseDidChange:", name: METDatabaseDidChangeNotification, object: Meteor.database)
have you been able to figure out the second part? for the change details?
Also, how do you parse the results?