// Updating Objects with primary keys // This will make properties no settled be NULL [GWClassmate createOrUpdateInDefaultRealmWithValue:newClassmate];
- (BOOL)canBecomeFirstResponder; // default is NO - (BOOL)becomeFirstResponder;
- (BOOL)canResignFirstResponder; // default is YES - (BOOL)resignFirstResponder;
- (BOOL)isFirstResponder;
// Generally, all responders which do custom touch handling should override all four of these methods. // Your responder will receive either touchesEnded:withEvent: or touchesCancelled:withEvent: for each // touch it is handling (those touches it received in touchesBegan:withEvent:). // *** You must handle cancelled touches to ensure correct behavior in your application. Failure to // do so is very likely to lead to incorrect behavior or crashes. - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event; - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event; - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event; - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender NS_AVAILABLE_IOS(3_0); // Allows an action to be forwarded to another target. By default checks -canPerformAction:withSender: to either return self, or go up the responder chain. - (id)targetForAction:(SEL)action withSender:(id)sender NS_AVAILABLE_IOS(7_0);
Model 是不可变的,所以我们可以只在初始化的时候指定我们 View Model 的属性。对于可变 Model,我们还需要使用一些绑定机制,这样 View Model 就能在背后的 Model 改变时更新自身的属性。此外,一旦 View Model 上的 Model 发生改变,那 View 的属性也需要更新。Model 的改变应该级联向下通过 View Model 进入 View。
I will often create a singleton manager class that handles setting up the Core Data stack, and deals with all of the fetching/saving that is involved with the stack. As the quote you mentioned says, this makes it very easy to not only call those methods, but to adjust them if needed, as opposed to having saving/fetching calls all over the place in different view controllers.
AFNetworkReachabilityManager monitors the reachability of domains, and addresses for both WWAN and WiFi network interfaces.
Do not use Reachability to determine if the original request should be sent.
You should try to send it. You can use Reachability to determine when a request should be automatically retried. Although it may still fail, a Reachability notification that the connectivity is available is a good time to retry something. Network reachability is a useful tool for determining why a request might have failed. After a network request has failed, telling the user they’re offline is better than giving them a more technical but accurate error, such as “request timed out.”
AFNetworking takes advantage of Foundation URL Loading System caching using NSURLCache, as well as a configurable in-memory cache for UIImageView and UIButton, which uses NSCache by default. Caching behavior can be further specified in the caching policy of a corresponding NSURLRequest. Other SDWebImage features, like background decompression of image data is also provided by AFNetworking.
If you’re already using AFNetworking and just want an easy async image loading category, the built-in UIKit extensions will probably fit your needs.
lazyvar applicationDocumentsDirectory: NSURL= { // The directory the application uses to store the Core Data store file. This code uses a directory named "org.gewill.test_Core_Data" in the application's documents Application Support directory. let urls =NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask) return urls[urls.count-1] as!NSURL }()
lazyvar managedObjectModel: NSManagedObjectModel= { // The managed object model for the application. This property is not optional. It is a fatal error for the application not to be able to find and load its model. let modelURL =NSBundle.mainBundle().URLForResource("test_Core_Data", withExtension: "momd")! returnNSManagedObjectModel(contentsOfURL: modelURL)! }()
lazyvar persistentStoreCoordinator: NSPersistentStoreCoordinator? = { // The persistent store coordinator for the application. This implementation creates and return a coordinator, having added the store for the application to it. This property is optional since there are legitimate error conditions that could cause the creation of the store to fail. // Create the coordinator and store var coordinator: NSPersistentStoreCoordinator? =NSPersistentStoreCoordinator(managedObjectModel: self.managedObjectModel) let url =self.applicationDocumentsDirectory.URLByAppendingPathComponent("test_Core_Data.sqlite") var error: NSError? =nil var failureReason ="There was an error creating or loading the application's saved data." if coordinator!.addPersistentStoreWithType(NSSQLiteStoreType, configuration: nil, URL: url, options: nil, error: &error) ==nil { coordinator =nil // Report any error we got. var dict = [String: AnyObject]() dict[NSLocalizedDescriptionKey] ="Failed to initialize the application's saved data" dict[NSLocalizedFailureReasonErrorKey] = failureReason dict[NSUnderlyingErrorKey] = error error =NSError(domain: "YOUR_ERROR_DOMAIN", code: 9999, userInfo: dict) // Replace this 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. NSLog("Unresolved error \(error), \(error!.userInfo)") abort() } return coordinator }()
lazyvar managedObjectContext: NSManagedObjectContext? = { // Returns the managed object context for the application (which is already bound to the persistent store coordinator for the application.) This property is optional since there are legitimate error conditions that could cause the creation of the context to fail. let coordinator =self.persistentStoreCoordinator if coordinator ==nil { returnnil } var managedObjectContext =NSManagedObjectContext() managedObjectContext.persistentStoreCoordinator = coordinator return managedObjectContext }()
// MARK: - Core Data Saving support
funcsaveContext () { iflet moc =self.managedObjectContext { var error: NSError? =nil if moc.hasChanges &&!moc.save(&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. NSLog("Unresolved error \(error), \(error!.userInfo)") abort() } } }
}
Debug:
1 2
p applicationDocumentsDirectory (NSURL) $R0 = 0x00000001740a8b20 "file:///var/mobile/Containers/Data/Application/601088B9-EB64-4E8D-9817-96E23D0D5D7E/Documents/"
1 2 3 4 5 6 7 8 9
ssh root@192.168.0.101 root# cd /var/mobile/Containers/Data/Application/601088B9-EB64-4E8D-9817-96E23D0D5D7E/Documents/ root# ls -la total 192 drwxr-xr-x 2 mobile mobile 170 Aug 21 22:16 ./ drwxr-xr-x 5 mobile mobile 204 Aug 21 22:16 ../ -rw-r--r-- 1 mobile mobile 20480 Aug 21 22:16 test_Core_Data.sqlite -rw-r--r-- 1 mobile mobile 32768 Aug 21 22:24 test_Core_Data.sqlite-shm -rw-r--r-- 1 mobile mobile 140112 Aug 21 22:24 test_Core_Data.sqlite-wal