I have a List<Hashtable>
in my MonoTouch app, and I need to persist it to my settings. NSUserDefaults
, however, only takes in things that inherit from NSObject
.
Is there a simple way to wrap my List in an NSObject
that I can store in my settings, or is a quick generic way to encode and decode a Hashtable
to a JSON string (or similar)?
Or is there a MonoTouch alternative for persisting a small list of Hashtable
s?
Like @Maxim said there are several approach available. If you want to use
NSUserDefaults
to store your data then you can serialize it (a .NET feature available to you using MonoTouch) to either:a binary format. Then use the
Stream
(orbyte[]
) to create anNSData
instance that you'l be able to store withNSUserDefaults
; orinto a string and store it as a
NSString
(string
overloads are also available, but it will do theNSString
conversion);Why not save your data into SQLite-table?
You could create quiet simple table with fields:
For List -> byte[] (and vice versa) conversion try to use such code: