iOS开发笔记 7、数据【Preferences、文件、库、Core Data】-阿里云开发者社区

开发者社区> 狗尾巴呢> 正文

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.
+关注继续查看

程序开发中根据要使用各种各样的数据,如配制、文件系统、数据库等,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

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
ASP.NET CORE入门之读取Json配置文件
首先新建一.net core控制台项目,命名为jsonReader 然后选中引用,选择NuGet包管理器,点击浏览引入mircosoft.aspnetcore.all并安装 选中解决方案,填加,新建项目,添加Json文件,命名为test.
1021 0
ASP.NET Core轻松入门Bind读取配置文件到C#实例
首先新建一个ASP.NET Core空项目,命名为BindReader 然后 向项目中添加一个名为appsettings.json的json文件,为什么叫appsettings呢?  打开Program.
885 0
asp.net core轻松入门之MVC中Options读取配置文件
接上一篇中讲到利用Bind方法读取配置文件 ASP.NET Core轻松入门Bind读取配置文件到C#实例 那么在这篇文章中,我将在上一篇文章的基础上,利用Options方法读取配置文件 首先注册MVC服务并添加MVC路由 注册MVC的方法是在ConfigureServices中添加   services.
1182 0
DLA如何分析Table Store的数据
数据湖(Data Lake)是时下热门的概念,基于数据湖,可以不用做任何ETL、数据搬迁等过程,实现跨各种异构数据源进行大数据关联分析,从而极大的节省成本和提升用户体验。
886 0
【Spring开发】—— Spring Core
原文:【Spring开发】—— Spring Core 前言   最近由于一些工作的需要,还有自己知识的匮乏再次翻开spring。正好整理了一下相关的知识,弥补了之前对spring的一些错误认知。
883 0
证书转换-SSL证书生成:cer,jks文件 韩俊强的博客
一.生成.jks文件 资料:HTTPS-老司机手把手教你SSL证书申购-TrustAsia证书 HTTPS时代已来,手把手指导申请免费SSL证书 1、keystore的生成: 分阶段生成: keytool -genkey -alias yushan(...
4980 0
+关注
狗尾巴呢
从事研发20年 涉及桌面软件、嵌入式设备、C/S分层系统、B/S业务系统、互联网系统等等各类系统 语言涉及C/C++ .net系统 java系列 前端系列等等不同的类别 主控和主导了国家863项目,企业业务应用系统,自然语言翻译系统,数据库审计等系列的软件研发
435
文章
2
问答
文章排行榜
最热
最新
相关电子书
更多
《Nacos架构&原理》
立即下载
《看见新力量:二》电子书
立即下载
云上自动化运维(CloudOps)白皮书
立即下载