Comparing two NSManagedObjects

后端 未结 3 1454
眼角桃花
眼角桃花 2021-02-07 02:02

I have some code that loops through an array of NSManagedObjects and stops when it finds a certain record that is stored in an instance variable. The only way I can manage to se

3条回答
  •  我在风中等你
    2021-02-07 02:44

    Clarification:

    ImHuntingWabbits refers to isEqual:, but then advises Nick to stick with his first example, which actually uses isEqualTo:.

    Per Peter Hosey's comment to the post isEqual vs isEqualTo, there is a difference and you're better off using isEqual:.

    Following the present posts, I originally used isEqualTo: to compare objectID URLs, which worked fine in Cocoa, but when I moved this code over to iOS, I got warnings that "NSURL may not respond to isEqualTo." When I changed to isEqual:, the warnings went away.

    So if you're following these examples, you should probably do this:

    if ([[[obj1 objectID] URIRepresentation] isEqual:[[_obj2 objectID] URIRepresentation]] {
        NSLog(@"Match");
    }
    

提交回复
热议问题