Reputation: 948
IsolatedStorage its a class in .net for windowsphone that enables local storage, without database.
Exist a similar class to make or worship me in objective c?
Upvotes: 0
Views: 119
Reputation: 3748
It sounds like NSUserDefaults
will suit your purpose. It's dead simple. You use a known Key to Set/Get objects ( like that of NSDictionary
)
// Setting a String value
[[NSUserDefaults standardUserDefaults] setObject: localPath forKey:@"NSStringMediaLocalpath"
// and Getting a string
NSString *localMediaPath = [[NSUserDefaults standardUserDefaults] objectForKey:@"NSStringMediaLocalpath"];
You should provide default values in your App init method, as follows:
NSMutableDictionary *initialValues = [NSMutableDictionary dictionary];
// Careful with BOOL. Is actually a NSNumber object
[initialValues setObject:[NSNumber numberWithBool:NO] forKey:@"NSManagedObjectContextSaveisAutoSave"];
[initialValues setObject:[NSNumber numberWithInteger:20] forKey:@"NSURLConnectionTimeoutPeriod"];
[[NSUserDefaults standardUserDefaults] registerDefaults:initialValues];
Upvotes: 1
Reputation: 70976
Many core classes like NSArray
, NSDictionary
, and NSString
include methods to read/write their data to/from files directly. Literally, just tell an array to write itself to a file, and it does so. Tell NSArray
to create an instance from a file, and it does so.
There's also a scheme called NSCoding
that any class can implement to assist in converting itself to/from NSData
. NSData
can write itself directly to files, so this covers any class where instances can be serialized into a binary blob.
Specialized classes often have their own file conveniences. For example, UIImage
can be initialized directly from any file containing a compatible image format (which is anything common-- PNG, JPG, GIF, etc, there are a lot).
If you need finer grained control, you can use NSFileHandle
to read/write arbitrary data streams to/from files. NSFileManager
also has methods to read and write files.
This is all just at the Cocoa Touch level. On iOS you also have access to the entire Unix system of reading and writing files, if that's what you prefer.
Upvotes: 0