0

Lets say I have two models/objects for realm 1.0.0 - ArticleMO, and TagMO:

class ArticleMO: Object {
    dynamic var title: String = ""
    let tags = List<TagMO>()
}

class TagMO: Object {
    dynamic var name: String = ""
    let articles = LinkingObjects(fromType: ArticleMO.self, property: "tags")
}

How can I remove all articles with a tag?

I've tried:

if let tag = realm.objects(TagMO).filter("name == '\(tagName)'").first {
    realm.delete(tag.articles)
}

But it results in an error like this:

RLMArray has been invalidated or the containing object has been deleted

All my attempts around the issue - such as iterating through the objects after trying to store/detach them, result in the same error. What am I missing?

Austin
  • 1,369
  • 1
  • 13
  • 19
  • 1
    Are the objects you're operating on really as independent as you've shown here by the example code you've shared? I can't reproduce the error from that. If you base your query on an object, which would be deleted, this is expected to fail. – marius May 30 '16 at 09:48
  • @marius You're right, the database operation executes and the error is after the fact when a NSTokenField delegate is called. Thank you for pointing me in the right direction. – Austin May 31 '16 at 05:03

0 Answers0