tailieunhanh - iPhone SDK Programming A Beginner’s Guide phần 10
NSManagedObjects không có phương pháp dealloc, như là khuôn khổ dữ liệu cốt lõi quản lý chu kỳ cuộc sống của họ. Cốt lõi dữ liệu cũng là trách nhiệm để tạo ra các phương pháp accessor NSManagedObjects trong thời gian chạy | Chapter 17 Core Data 417 import implementation Apple @end Listing 17-3 import import import import import NOTE NSManagedObjects have no dealloc methods as the Core Data framework manages their life cycle. Core Data is also responsible for generating NSManagedObjects accessor methods at runtime. Try This Adding Core Data to the Application s Code 1. Open FruitStand in Xcode open and import the Core Data header file Listing 17-4 . Create a property called managedObjectContext for the NSManagedObjectContext class. 2. Create a new method called loadCoreData and implement it Listing 17-5 . 3. Add code that calls the loadCoreData method in applicationDidFinishLaunching. 4. Open and import Core Data in FruitStandController s header file. Add a property referencing NSManagedObjectContext and name the property managedObjectContext Listings 17-6 and 17-7 . 5. Return to the applicationDidFinishLaunching method in and add code that sets the FruitStandViewController s managedObjectContext property. 6. Build the application. Listing 17-4 import UIKit import CoreData class FruitStandViewController continued 418 iPhone SDK Programming A Beginner s Guide interface FruitStandAppDelegate NSObject UIApplicationDelegate UlWindow window FruitStandViewController viewController NSManagedObjectContext managedObjectContext property nonatomic retain IBOutlet UlWindow window property nonatomic retain IBOutlet FruitStandViewController viewController property nonatomic retain NSManagedObjectContext managedObjectContext - void loadCoreData end Listing 17-5 import import implementation FruitStandAppDelegate synthesize window synthesize viewController synthesize managedObjectContext - void loadCoreData NSArray paths .
đang nạp các trang xem trước