Tutorials For using NSFileManager to store data? - objective-c

Hi I am looking for some tutorials on using NSFileManager to store data in the directories such as cache and such, I havent really been able to find a good one with any nice examples. Any recommendations on where to find some? Thanks. ps. I know there is core Data too but at the moment I am just interested in finding one for NSFileManager

I have an app that displays some photos and I want to cache the seen photos so that I dont have to redownload the photos that have already been viewed
see NSURLCache
Class Overview:
NSURLCache implements the caching of responses to URL load
requests by mapping NSURLRequest objects to NSCachedURLResponse
objects. It is a composite of an in-memory and an on-disk cache.
Methods are provided to manipulate the sizes of each of these
caches as well as to control the path on disk to use for persistent
storage of cache data.

Related

Proper way to name objects in mass storage service

I wonder as one of my personal projects development goes further forward how should i organize the files ( images, videos, audio files ) uploaded by the users onto AWS's S3/GCE Cloud Storage, i'm used to see these kinds of URL below;
Facebook fbcdn-sphotos-g-a.akamaihd.net/hphotos-ak-xft1/v/t1.0-9/11873531_1015...750483_5263546700711467249_n.jpg?oh=b3f06f7e...b7ebf7&oe=56392950&__gda__=1446569890_628...c7765669456
Tumblr 36.media.tumblr.com/686b47...e93fa09c2478/tumblr_nt7lnyP3ld1rqbl96o1_500.png
Twitter pbs.twimg.com/media/CMimixsV...AcZeM.jpg
Does these random characters carry some kind of meaning? or they're just "UUIDs"? Is there a performance/organization issue in using, for instance this kind of URL below?
content.socialnetworkX.com/userY/post/customName_dinosaurs.jpg
EDIT: Let be clear that i'm considering millions of files.
For S3, see the Performance Considerations page where it talks about object naming. Specifically, if you plan to upload objects at a high rate, you should avoid sequentially named objects, as they can be a bottleneck.
Google Cloud Storage does not have this performance bottleneck. See this answer.

NSUserDefaults and adding UIImages to an application via the web

I have an app that uses chat stickers. I would like to add more stickers to the app over time without having to make the user download an update. I understand that I can store data in NSUserDefaults so was wondering if it's possible to get an app to download images from a server to the NSDefaults? Say via parse or a similar service? Is this kind of thing allowed in an app? I read something in the developer guidelines that placeholders could not be used. Any advice on this would be really appreciated. Thanks!
If you want to use parse the store all the images in a table in the parse file storage. Download the images using the Parse SDK. The downloaded images will be cached appropriately by the SDK so you won't need to handle the cache yourself.
You can read more about how to store files with Parse here: https://www.parse.com/docs/ios_guide#files/iOS
NSUserdefaults is not meant to store big files like images. It should only contain small amounts of data.
You will need to download the images and save them locally. To download the image to a file use NSURLDownload.

iCloud NSFileManager API - game score storage

I currently have an iOS application for which I would like to enable iCloud score storage so that users will have their game progress synced across their devices. The users progress is stored in multiple plist files in the sandboxes documents folder.
I read a few articles online about iCloud and the various "helper classes" (NSFileManager, UIDocument, NSFileCoordinator etc.) but am a little confused which one is the right one for me (does NSFileManager do the job or will i need to subclass UIDocument).
The API's are all a bit confusing to me.
You should use iCloud with Key-Value Data Storage. It's by far the simplest and most reliable at the moment, and suits your case perfectly.

iCloud Support in an application for Mac OS X Lion

Within a Mac OS X (10.7 Lion) Non-Document Based application, I want to include iCloud support so I can share data across other instances of the same application on other macs (not to iOS devices). After surfing around the Apple documentation a bit, I've discovered I should use a key value list storage in iCloud, as the document I want to upload contains only an array of custom objects (that have simple properties such as a name (string), date (date object), ...). This file is the only thing I want to upload to iCloud. Within the application, I have already implemented saving the file to the disk using NSFileManager's - (void)writeData:(NSData*)data toPath:(NSString *)path (or whatever it was, I've forgotten). It is loaded from the file using NSFileManager again (using - (NSData *)dataInFileAtPath:(NSString*)path, or whatever it was). The file is stored in a subdirectory, in the user's Application Support directory. It is saved whenever a new item is added to the array, or an item in the array is modified.
I was wondering if anyone could provide a link to a tutorial, or point me in the right direction, to writing that file to iCloud, then downloading it again on other instances of the same application? All the tutorials and documentation I have found have only been for iOS. Any help will be greatly appreciated!
Thanks in Advance!
Ben
Just use NSUbiquitousKeyValueStore, which is a lot like NSUserDefaults except that it's written to iCloud. You should read the iCloud Storage section of the Mac App Programming guide, but what you need to do may be as simple as enabling entitlements in the Summary tab of your App Target in Xcode, and then doing something like:
NSData *dataToStore = [NSKeyedArchiver dataWithRootObject:yourArray];
[[NSUbiquitousKeyValueStore defaultStore] setData:dataToStore forKey:#"yourKey"];
Then, to retrieve your data, just do
NSData *retrievedData = [[NSUbiquitousKeyValueStore defaultStore] dataForKey:#"yourKey"];
NSArray *retrievedArray = [NSKeyedUnarchiver unarchiveObjectWithData:retrievedData];
The one caveat here is that for this to work with an array of custom objects, these objects must all implement the NSCoding protocol. This is just a matter of implementing two methods; here's a good tutorial.
P.S. You use the same APIs whether you're developing for OS X or iOS, so there's no reason why you couldn't just follow an iOS tutorial for iCloud storage.

PubSub framework + Core Data?

Is it possible to persist PubSub framework objects in a Core Data persistent store? Or is there a better way to do this...? I'm working on an RSS reader and looking for ways to cache RSS/Atom feeds retrieved by PubSub..
Thanks in advance
It is possible to persist PubSub objects in the persistent store, however, I am not sure if it is needed as I believe those objects are persisted in an operating system database.
Regardless, to do this, all you have to is add a transformable property, i.e. feedObject. The docs have a good explanation of how to do this:DOCS
The only real trick is that you have to import the PubSub framework on the Entity header file.
Like I said though, the feeds and associated entries are all persisted (I believe) in the operating system as long as you subscribe to the feed. The only time it retrieves entries is (a) when you first subscribe to a feed and (b) when it decides that is time to refresh the feed.
If you don't subscribe to the feed and you are only taking the feeds manually then you might want to consider adding them to your persistent store.
there is an example in the mac developer site regarding reading news feeds. The sample code can be downloaded by clicking here. Hope it will be useful for you.
here is another example by Colin Wheeler