casatwy / CTPersistance

iOS Database Persistence Layer with SQLite, your next Persistence Layer!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NSArray

mythodeia opened this issue · comments

Hello and thanks for the great source code.
I have a question. How can i handle an NSArray in the testrecord for example in your demo?
as i see it i need to add the column in the testtable.m file as well.
how will i add the array in the table?

thanks

the testrecord is extended from CTPersistanceRecord, but actually, you don't have to do this.

Any object who confirms to CTPersistanceRecordProtocol can be a record, and can be accepted by CTPersistance, even a customized UIView.

so, in your case, you can implement an object who confirms to CTPersistanceRecordProtocol, in - (void)objectRepresentationWithDictionary:(NSDictionary *)dictionary; and - (NSDictionary *)dictionaryRepresentationWithTable:(CTPersistanceTable <CTPersistanceTableProtocol> *)table; you can handle NSArray.

thanks a lot for your answer.
Can you add this case in your existing demo project for everyone to have?
great project
👍

I think CTPersistanceRecord is the very case of this...

as i see it i should add the array in the - (NSDictionary *)columnInfo method too.
so should i save the NSArray as a BLOB in the table?

you can save the array data as a json string, and when you get data from database, you parse this json string into NSArray, while in - (void)objectRepresentationWithDictionary:(NSDictionary *)dictionary.

though sqlite support blob and CTPersistance is based on sqlite,I do not want to support blob type in first place, because I think all blob data like image should be saved as a file, and we save the path of image file in database.