iOS开发笔记 七、数据【Preferences、文件、库、Core Data】

程序支付中依据要动用各个各个的多寡,如配制、文件系统、数据库等,iOS对那一个有很好的帮忙

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.

新闻的保存:

一、 保存到文件

二、 保存到数据库:Slqite的并轨

3、 NSUserDefaults方式: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
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 architectures or in
different formats.

framework bundles, application bundles, and settings bundles

NSBundleCFBundle类能够发现更加多的Bundle的新闻

iPhone and iPad in Action例子:

Selfpreferences

Systempreferences

 

文件

软件布置后的目录:

~/Library/Application Support/iPhone Simulator/Users/Applications

本条目录下有应用程序的目录,包蕴:*.app, Documents,Library,tmp目录

把文件拖到Xcode中,默许作为Application Bundle的财富

近期程序的路径处理

NSString *paths = [[NSBundlemainBundle] resourcePath];

NSString *bundlePath = [paths stringByAppendingPathComponent:dbFile];

其余目录的门路处理

NSArray *paths =
NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);

NSString *documentsDirectory = [paths objectAtIndex:0];

NSString *docPath =
[documentsDirectorystringByAppendingPathComponent:dbFile];

文本处理:

NSFileManager *fileManager = [NSFileManagerdefaultManager];

success =
[fileManagercopyItemAtPath:bundlePathtoPath:docPatherror:&error];

iPhone and iPad in Action例子:

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 Action例子:

dbnav

 

Address Book

the Address Book framework and the Address Book UI framework

头文件

sqlite,AddressBook/AddressBook.h and AddressBookUI/AddressBookUI.h

iPhone and iPad in Action例子:

Contactsearch

Contactselect

 

Core Data[IOS 3 以上]

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.

Xcode中树立艺术

File > New File. Then, select Data Model under Resource

其一和O/奥迪Q7 Mapping 工具类似,概念和术语和Ado.net Entity有共同之处

iPhone and iPad in Action例子:

CDJournal

网站地图xml地图