zoukankan      html  css  js  c++  java
  • iOS开发笔记 7、数据【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.

    信息的保存:

    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

  • 相关阅读:
    keyset与entryset
    solr4.9r+ Eclipse 4.3+ tomcat 7.5 +winds7(二)
    如何解决This system is not registered with RHN.
    堆和栈的差别(转过无数次的文章)
    墨菲定律、二八法则、马太效应、手表定理、“不值得”定律、彼得原理、零和游戏、华盛顿合作规律、酒与污水定律、水桶定律、蘑菇管理原理、钱的问题、奥卡姆剃刀等13条是左右人生的金科玉律
    atitit.软件开发GUI 布局管理优缺点总结java swing wpf web html c++ qt php asp.net winform
    漫谈并发编程(二):java线程的创建与基本控制
    exosip
    PostgreSQL服务端监听设置及client连接方法
    APK反编译。
  • 原文地址:https://www.cnblogs.com/2018/p/1942344.html
Copyright © 2011-2022 走看看