tailieunhanh - Phát triển ứng dụng cho iPhone và iPad - part 17

Tham khảo tài liệu 'phát triển ứng dụng cho iphone và ipad - part 17', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | Using Core Data A Simple Task Manager 129 initWithManagedObjectModel self managedObjectModel if persistentStoreCoordinator addPersistentStoreWithType NSSQLiteStoreType configuration nil URL storeUrl options nil error error Replace this implementation with code to handle the error appropriately. abort causes the application to generate a crash log and terminate. You should not use this function in a shipping application although it may be useful during development. If it is not possible to recover from the error display an alert panel that instructs the user to quit the application by pressing the Home button. Typical reasons for an error here include The persistent store is not accessible The schema for the persistent store is incompatible with current managed object model Check the error message to determine what the actual problem was. NSLog @ Unresolved error @ @ error error userinfo abort return persistentStoreCoordinator The code first determines if the Persistent Store Coordinator already exists. If it exists the method returns it to you. If the coordinator does not exist the code must create it. In order to create the coordinator you need to pass in a URL that points to the data store. The template uses the fileURLWithPath method on the NSURL class to create the URL. You can see that the store name will be . Next the code allocates an NSError object to hold the error data that the Persistent Store Coordinator generates if there is a problem configuring the coordinator. The next line allocates and initializes the coordinator using the Managed Object Model. You will look at the managedObjectModel getter method in a moment. Remember that you use the Persistent Store Coordinator to mediate between the Managed Object Context the Managed Object Model and the data store. Therefore it makes sense that the coordinator would need to have a reference to the model. Now that the coordinator knows about the model the code goes on to tell it