ios Core Data Fetch a specific value -
So I'm reading a question on Apple's Core Data Guide and Stack and it's all right, but it's not just enough "Clicking" in my head
I have bookshops in which books have multiple relationships.
I entered a bookshop called "Jenny's Bookshop" and called the bookshop "Big World Book"
In the same way, I will add a 'new book' to a new bookstore:
BookShop * myBookShop = [NSEntityDescription insertNewObjectForEntityForName: @ "Bookshop" Managed object contexts in: context]; MyBookShop.books = [[NSMutableSet alloc] init]; Book * myBook = [NSEntityDescription insertNewObjectForEntityForName: @ Managed object contact in "book": context]; MyBook.BookShop = myBookShop; [myBookShop addbookObject: myBook]; Say I want a book that is related to "Big World Books" and not "Jenny's Bookshop"
I'm assuming that I have a fetch Use the request and take a pointer on "Big World Books" and then provide a book in this special bookstore? This is where I keep it confusing.
Edit: Answer: NSPredicate * predicate = [NSPredicate predicateWithFormat: @ "name ==% @"]; [Request to certification: count]; [Request Settem Limit: 1]; BookShop * resultBookShop = [[_managedObjectContext executeFetchRequest: Request error: & amp; Error] lastObject]; [MyBook setBookShop: resultBookShop];
// if BigWorld books exist with BookShop No Surgeon If it is in existence, then it is called Bookshope * BookShop = [is itself an eXxtendiTweetname: @ "Big World Books" unit: @ "BookShop"]; If (Book Book Store) {// insertNewObjectForEntityForName} other {// bookstore is present / enter new book book * b = [NSEntityDescription insertNewObjectForEntityForName: @ "Book" Managed Object Contents in: Reference]; // Add new book to NSSET of Book Bookshop (B), and you have NSSET * books booksshop.books = books; }
Comments
Post a Comment