问题描述:

I thought about using NSUserDefaults to store a single image, but i know this is discouraged.

Now, I tried using the new Asset library mechanism, but I failed to get it to work.

I tried this because my original idea of storing/retrieving the image URL (path on local disk) is not supported (Apple did away with this for some reason).

So now I'm here asking for ideas on where/how to store information so that I can load a pre-selected image. And note that I am already using Core Data (a single entity type) to populate a tableview. I suppose I could create a 2nd entity type just for this. Is this the recommendation, or is there still yet a simpler or more clever way?

Ex: User "favorites" a specific image. The next time the app loads I'd like to display that image.

网友答案:

You can use the app's document directory:

+ (NSString *) applicationDocumentsDirectory 
{    
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
    return basePath;
}

Note that this directory is erased when the user removes the app.

相关阅读:
Top