Common bugs. File System vs Core Data: the image cache test. Code for this project is on GitHub While doing a full re-write of Droplr's iOS app for the 2.0 launch, I couldn't find any good file/image caches out there had a particular feature I really wanted: extending item expiration whenever it's touched. I set out to write my own — which wasn't that much of a challenge — but somewhere along the process I had this crazy idea that perhaps (SQLite-backed) Core Data would be a much better tool for the job: No mismatch between cache index file and actual data stored;Trivial querying;Nice and easy object oriented code. Being a structured data store with Object-Relational Mapping, it's only logical that it would be slower. One protocol to rule them all The number one goal with this pet project was that both the file system and Core Data cache implementations had to present the exact same signature to the programmer, while being consistent in the way they work.
Super simple stuff... The File System cache implementation The Core Data cache implementation Woah! NSUndoManager Class Reference. How To Save Your App Data With NSCoding and NSFileManager. If you're new here, you may want to subscribe to my RSS feed or follow me on Twitter. Thanks for visiting! This bug doesn't look so scary on disk! There are many different ways to save your data to disk in iOS – raw file APIs, Property List Serialization, SQLite, Core Data, and of course NSCoding. For apps with heavy data requirements, Core Data is often the best way to go. However, for apps with light data requirements, NSCoding with NSFileManager can be a nice way to go because it’s such a simple alternative. In this NSCoding tutorial, we’re going to take the “Scary Bugs” app that we’ve been working on in the How To Create A Simple iPhone App Tutorial Series and extend it so that it saves the app’s data to disk.
Along the way, we’ll cover how you can use NSCoding to persist your normal app data, and use NSFileManager to store large files for efficiency. If you don’t have the project already, grab a copy of the Scary Bugs project where we left off last time. Implementing NSCoding That’s it! CoreData. Efficient Scalar Attributes in Core Data « Lory’s Blob. I spent some time today on improving performance in my iOS development project, and I came up with some results that may be of interest to others working with Core Data.
Note that the hacks demonstrated below are based on Time Profiler measurements taken on my (egregiously unoptimized) app under development. The underlying “performance issue” only occurs when you’re using standard Core Data scalar accessors unusually frequently, like my app did. It is overwhelmingly likely that your application does not exhibit the same behavior; therefore, please use Instruments to verify that read accessors are actually slowing down your app before applying any of these tweaks. Standard accessors Implementing accessors for scalar attributes in Core Data is somewhat inconvenient, as the framework only generates primitive accessors for scalars, and you’re supposed to write the normal accessors yourself, complete with correct access and change notifications.
Use instance variables Results Like this: