Simple use of coredata in IOS

Source: Internet
Author: User

Original link: http://www.jianshu.com/p/4411f507dd9f

Description: The coredata described in this article is not created in the Appdelegate, new project is used in the program, that is, the creation of a local database, cache data, after a few hours to update the database

1. Create CoreData: I named Zhzmodel, insert a table: News:

Remark: How to create: Command+n->ios/coredate->datamodel


Describe the data type: True/false with a Boolean, if it is a nsarray or dictionary, with the transformable type, the data type is ID (that is, any type)

2. Generate Nsmanagedobject Subclass: (The Ads property value is self-modified to Nsarray type, generated by ID type)

Remark: (1) Creation method: Command+n->ios/coredate->nsmanagedobject Subclass (2) menu bar editor->create nsmanagedobject SubCl The


3. Create a project that inherits from NSObject: write the following code








Note: If it is not a blog address, please use the address in Baidu Open

Detailed Address: http://blog.csdn.net/rhljiayou/article/details/18037729/

4. In the network parsing data: (self.alldata to customize a mutable array, accept the parsed value)



-Note: This article is from the network reference, for learning only

The above is used in other programs, and now uses a create project directly with CoreData:
Create


Next, create the table, insert the fields, and then generate the files:


Create a table directly (Qhusermodel), insert the fields you want, and then generate the qhusermodel.h/m file

Then create a new inheritance and NSObject Direct management additions and deletions: qhdatabase


Where Qhcommitidymodel is another table I created, no tube, Singleton is a singleton created

Simply take a look at this single example: (Just a. h header file), you can actually write a single-case method in your project:


And then we'll go ahead and see QHDATABASE.M.





Then take a look at the use of the project:


Simple use of coredata in IOS

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.