0

i have searched a lot also here on SO but i haven't find a way to start what i want, in my app i want to save some custom object on iCloud, i think the best way is using UIDocument, this is the custom Object:

@interface AppState : NSObject

@property (nonatomic, strong) NSNumber *timestamp;
@property (nonatomic, strong) NSNumber *type;
@property (nonatomic, strong) NSString *note;
@property (nonatomic, strong) NSString *device;

@end

then i doesn't know how, i want store this information on iCloud and retrieve it on the other device, i know i have to subclass the UIDocument class, but i can't figure out how i store this information, i have to insert it in an array? or something else? any help will be appreciate because i have find a lot of tutorial on how store nsstring, but i have a custom object, and i want also know if possible how this information is stored on iCloud, a single file for every Custom Object, or are all insert in one single file?

1 Answer 1

0

First of all, you have to put it in a file (or files). Then, you'll have to write a method to read and write it to a file (or files). So the big decision is what format of file: You could just open a plain file and write the data in using delimiters, or you could open 4 files and write each data item in its own file. You could also get fancy and store it as serialized data using encoders, or you could even store it in a SQLite database. Or, you could show off your programming ability and store it in core data, though both the SQLite and CoreData solutions seem overkill for what you currently have. As long as you write the file to a directory that is shared by iCloud, it will be stored in iCloud. You can make sure that the "don't store this file to iCloud" bit is not set, but I think it comes set to store it on creation.

How you store your data is often dependent on how you want to use it. In this case, with such small amounts of data, I'd just write it out to a file, and use delimiters.

3
  • but if i store it out in a file using delimters you talk about write a NSString right? i think it's not the best choice because i have to retrieve that information in other device to see the change of state, and i have to parse all file to retrieve the information, a prefer something clean, you talk about store use serialized data using encoders, or store in sqlite, i prefer one of this implementation, but what you think is the best? how you store the sqlite database on the cloud? it's not likely to become corrupt? and can you make an example please of serialized data using encoders?
    – Piero
    Oct 7, 2013 at 19:06
  • give me a sample, of how you store for example five of that custom object on icloud...
    – Piero
    Oct 7, 2013 at 19:07
  • I don't see any reason why you'd want to store four small pieces of data in anything other than a simple file. If you don't want to parse, store each piece of data in its own file, for 4 files. You can then check the modification dates to see what's changed. Anything else is programming for the sake of programming, given you haven't given any reasons why the data should be stored otherwise. Oct 7, 2013 at 19:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.