IOS sqlite3 Save Array Nsarray

Source: Internet
Author: User

Four Points of note: 1. When you create a table, the Declaration field type is binary blobnsstring *ineditortablename = @ "CREATE TABLE In_editor (Picurls blob not null)"; 2. Insert the SQL statement, Convert Nsarray to NSData type NSData *dataimageurls = [Nskeyedarchiver archiveddatawithrootobject:model.imageurls];3. cannot be used [ NSString stringWithFormat: @ "SQL"]; [_db executeupdate: @ "INSERT into In_editor (Picurls) values (?);", dataimageurls];4. Read data: Nsarray *imagearr = [Nskeyeduna Rchiver unarchiveobjectwithdata:picurls]//If you are not aware of the above points, the following error may appear: * Terminating app due to uncaught exception ' Nsinvalidargumentexception ', Reason: '-[__nscfdata objectforkey:]: Unrecognized selector sent to instance 0x6b46c80 '


Note: Nsarray and NSData convert the binary nsarray to NSData type: nsdata *data = [Nskeyedarchiver Archiveddatawithrootobject:array]; Convert NSData to Nsarray type: nsarray *array = [Nskeyedunarchiver Unarchiveobjectwithdata:data];integer: Value is Signedinteger type, Size can be 1,2,3,4,6,8bytesreal: floating-point type text: Character type blob stored in UTF-8,UTF-16BEORUTF-16LE encoding: binary data




Reference:

Http://www.4byte.cn/question/22141/saving-nsarray-in-sqlite-and-retrieving-it.html

Http://www.chengxuyuans.com/iPhone_IOS/37789.html


IOS sqlite3 Save Array Nsarray

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.