程式開發中根據要使用各種各樣的資料,如配製、檔案系統、資料庫等,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.
資訊的儲存:
1、 儲存到檔案
2、 儲存到資料庫: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
標頭檔
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/R Mapping 工具類似,概念和術語和Ado.net Entity有共同之處
iPhone and iPad in Action例子:
CDJournal