IOS Development notes 7. Data [preferences, files, libraries, and Core Data]

Source: Internet
Author: User

ProgramIOS provides great support for various types of data, such as preparation, file systems, and databases, to be used during development.

Preferences

If you're going to create a program that has built-in preferences, you should do so using the Utility application template.

To create the special cartouched list used by preferences, you must create a table View Controller with the special uitableviewgrouped style. you can do this by choosing the grouped style for your table view in interface builder or by using the initwithstyle: Method in xcode.

Saving information:

1. Save to file

2. Save to database: slqite Integration

3. nsuserults ults: nsuserdefaults is a persistent shared object that you can use to remember a user's preferences from one session to another.

4. system settings:

Xcode allows you to tie multiple files together into a coherent whole called a bundle.

In practice, a bundle is just a directory. often a bundle is made opaque, so that users can't casually see its contents; in this case, it's called a package. the main advantage of a bundle is that it can be invisibly store multiple variants of a file, using the right one when the circumstances are appropriate. for example, an application bundle can include executable files for different chip ubuntures or in different formats.

Framework bundles, application bundles, and settings Bundles

The nsbundlecfbundle class can find more bundle information.

IPhone and iPad in actionExample:

Selfpreferences

Systempreferences

 

File

Directory after software deployment:

~ /Library/Application Support/iPhone simulator/users/Applications

This directory contains the application directories, including *. app, documents, library, and TMP.

Drag the file to xcode and use it as the resource of application Bundle by default.

Path processing of the current program

Nsstring * paths = [[nsbundlemainbundle] resourcepath];

Nsstring * bundlepath = [paths stringbyappendingpathcomponent: dbfile];

Path processing for other directories

Nsarray * paths = nssearchpathfordirectoriesindomains (nsdocumentdirectory, nsuserdomainmask, yes );

Nsstring * documentsdirectory = [paths objectatindex: 0];

Nsstring * docpath = [documentsdirectorystringbyappendingpathcomponent: dbfile];

File Processing:

Nsfilemanager * filemanager = [nsfilemanagerdefaultmanager];

Success = [filemanagercopyitematpath: bundlepathtopath: docpatherror: & error];

IPhone and iPad in actionExample:

Filesaver

 

SQLite

First add the framework, which you can find under/usr/lib/libsqlite3.0.dylib, rather than in the standard framework directory.

Second, you must add an import of sqlite3.h

IPhone and iPad in actionExample:

Dbnav

 

Address book

The address book framework and the address book UI framework

Header file

Addressbook/addressbook. h and addressbookui/addressbookui. h

IPhone and iPad in actionExample:

Contactsearch

Contactselect

 

Core Data [IOS 3 and later]

Ore data is a powerful layer that sits on top of an SQLite database. it removes much of the complexities of SQL and allows you to interface with the database in a more natural way. it does this by making the database rows into real objective-C objects (called managed objects) and lets you manipulate them without any knowledge of SQL.

Managed object

A managed object is a representation of an object you want to store in a database. think of it as a record in SQL. it generally contains fields that match up with the properties of an object being saved in your application. after you create a managed object, you must insert it into a managed object context before you can save it to the Data Store.

Managed object context

The managed object context holds all of your managed objects until they're ready to be committed to the database. inside this context, managed objects can be added, modified, and deleted. this is like a buffer between your application and the database.

Managed object table

This object describes the schema of your database. it's used when interfacing the managed object context with the database. A managed object table contains a collection of Entity Descriptions. each of these entities describes a table in your database and is used when mapping managed objects to database entries.

Build in xcodeCubeMethod

File> New file. Then, select data model under resource

This is similar to the O/R Mapping Tool. concepts and terminologies share the same with ado.net entity.

IPhone and iPad in actionExample:

Cdjournal

Related Article

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.