siegesmund / SwiftDDP

A Meteor client, written in Swift
MIT License
145 stars 60 forks source link

Cant get 2 collection from SwiftDDP #58

Closed RonGafni closed 8 years ago

RonGafni commented 8 years ago

Hey,

I don't know how but suddenly two of me 3 collection is not working.

Collection: Users, conversations, contacts

With "Users" Collection there is no problem but with conversations and contacts is always "0 element".

`let conversations = MeteorCollection<UserConversations>(name:"conversations")
    let contacts = MeteorCollection<Contact>(name:"contacts")`

NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(GOChatMessagesTableViewController.collectionDidUpdate), name: METEOR_COLLECTION_SET_DID_CHANGE, object: nil)

    Meteor.subscribe("user_conversations") {
        Meteor.subscribe("conversations_partial_contacts_info")
    }`

`

@objc func collectionDidUpdate() {

        if let conversationsA: MeteorCollection = conversations {
            conversationArray = sortArrayByDate(conversationsA.sorted) as! [UserConversations]

        //    saveConversation()
            self.tableView.reloadData()
        }

    }`

Few days ago everything goes well, but know I don't know what the problem..

Even when I try to crash the app by changing the Conversations MeteorDocument and delete one field its not even crash. What can I do?

Thanks!!

siegesmund commented 8 years ago

I would recommend going back to the last state that worked and look at what has changed.

RonGafni commented 8 years ago

And another question, how can I work with core data?

siegesmund commented 8 years ago

You use documentWasAdded, documentWasChanged and documentWasRemoved to add, update and remove your documents in Core Data. In other words, override those methods and write your own that add the document to Core Data each time a document is added, update it, etc.

RonGafni commented 8 years ago

Oh, thanks!

Can you give me example?

siegesmund commented 8 years ago

Core Data is a complex topic. If you've never used it, you'll need to spend some time with it first.

There is an example here: https://github.com/siegesmund/SwiftTodos.