文件都是用来读写数据的,可是哪里都会有潜规则,ios里面读写数据的潜规则你知不知道,你知道不知道!!!

你有没有觉得NSUserDefaults和NSBundle,plist这些玩意阴魂不散,有时候搞不清楚谁是谁。谁又会在哪里出现

看看下面,NSUserDefaults里面基本没存啥啊,只有语言国度对不对,剩下的是自己填的,是嘛

[NSUserDefaults standardUserDefaults]可以用来保存:NSString, NSNumber, NSDate, NSArray, NSDictionary。
系统默认保存到/Library/Preferences/.plist这个文件中

写入数据:
//Bool
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setBool:YES forKey:@"switchValue"];
 
//String
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setObject:@"star" forKey:@"inputValue"];

读取数据:
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
BOOL sw = [userDefaults boolForKey:@"switchValue"];
 
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
NSString *str = [userDefaults stringForKey:@"inputValue"];

默认的
 [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]:{
    AppleITunesStoreItemKinds =     (
        eBook,
        document,
        "software-update",
        booklet,
        "itunes-u",
        newsstand,
        artist,
        podcast,
        "podcast-episode",
        software
    );
    AppleLanguages =     (
        "zh-Hans",
        en,
        fr,
        de,
        ja,
        nl,
        it,
        es,
        pt,
        "pt-PT",
        da,
        fi,
        nb,
        sv,
        ko,
        "zh-Hant",
        ru,
        pl,
        tr,
        uk,
        ar,
        hr,
        cs,
        el,
        he,
        ro,
        sk,
        th,
        id,
        ms,
        "en-GB",
        ca,
        hu,
        vi
    );
    AppleLocale = "en_US";
    NSInterfaceStyle = macintosh;
    NSLanguages =     (
        "zh-Hans",
        en,
        fr,
        de,
        ja,
        nl,
        it,
        es,
        pt,
        "pt-PT",
        da,
        fi,
        nb,
        sv,
        ko,
        "zh-Hant",
        ru,
        pl,
        tr,
        uk,
        ar,
        hr,
        cs,
        el,
        he,
        ro,
        sk,
        th,
        id,
        ms,
        "en-GB",
        ca,
        hu,
        vi
    );
}

NSBundle这斯里面存了比NSUserDefaults里面多得多的东西啊,怎么分配的哦

程序版本号,程序名称,路径,启动nib,好嘛。。。。

NSBundle mainBundle:{
    CFBundleDevelopmentRegion = English;
    CFBundleDisplayName = iVersion;
    CFBundleExecutable = iVersion;
    CFBundleExecutablePath = "/Users/yongjack/Library/Application Support/iPhone Simulator/6.1/Applications/D0556446-FFD6-4C33-81F2-5917B48907F6/iVersion.app/iVersion";
    CFBundleIdentifier = "com.charcoaldesign.iVersion";
    CFBundleInfoDictionaryVersion = "6.0";
    CFBundleInfoPlistURL = "Info.plist -- file://localhost/Users/yongjack/Library/Application%20Support/iPhone%20Simulator/6.1/Applications/D0556446-FFD6-4C33-81F2-5917B48907F6/iVersion.app/";
    CFBundleName = iVersion;
    CFBundlePackageType = APPL;
    CFBundleSignature = "????";
    CFBundleSupportedPlatforms =     (
        iPhoneSimulator
    );
    CFBundleVersion = "1.0";
    DTPlatformName = iphonesimulator;
    DTSDKName = "iphonesimulator6.1";
    LSRequiresIPhoneOS = 1;
    NSBundleInitialPath = "/Users/yongjack/Library/Application Support/iPhone Simulator/6.1/Applications/D0556446-FFD6-4C33-81F2-5917B48907F6/iVersion.app";
    NSBundleResolvedPath = "/Users/yongjack/Library/Application Support/iPhone Simulator/6.1/Applications/D0556446-FFD6-4C33-81F2-5917B48907F6/iVersion.app";
    NSMainNibFile = MainWindow;
    UIDeviceFamily =     (
        1
    );
    UISupportedInterfaceOrientations =     (
        UIInterfaceOrientationPortrait,
        UIInterfaceOrientationPortraitUpsideDown,
        UIInterfaceOrientationLandscapeLeft,
        UIInterfaceOrientationLandscapeRight
    );
}

NSDocumentDirectory    <Application_Home>/Documents        
 


NSCachesDirectory    <Application_Home>/Library/Caches        
 


NSApplicationSupportDirectory    <Application_Home>/Library/Application Support  

实现在ios文件读写的更多相关文章

  1. Apache POI 实现对 Excel 文件读写

    1. Apache POI 简介 Apache POI是Apache软件基金会的开放源码函式库. 提供API给Java应用程序对Microsoft Office格式档案读和写的功能. 老外起名字总是很 ...

  2. iOS 文件读写

    #import <Foundation/Foundation.h> @interface Utils : NSObject +(void) writeFile:(NSString *) f ...

  3. C#实现对Word文件读写[转]

    手头上的一个项目报表相对比较简单,所以报表打印采用VBA引擎,通过定制Word模版,然后根据模版需要填充数据,然后OK,打印即可. 实现方法:首先需要引用VBA组建,我用的是Office2003 Pr ...

  4. iOS数据持久化文件读写之偏好设置

    很多iOS应用都支持偏好设置,比如保存用户名.密码.字体大小等设置,iOS提供了一套标准的解决方案来为应用加入偏好设置功能.每个应用都有个NSUserDefaults实例,通过它来存取偏好设置.比如, ...

  5. Cocos2d-x在win32,android和IOS下的文件读写问题

    最近在学习和使用Cocos2d-x框架,虽然说的是跨平台,但是在用VS进行开发,然后移植到android或IOS下,也可能会出现各种问题,需要做细微的调整. 例如我在做文件读写操作的时候,很可能在wi ...

  6. ios本地文件内容读取,.json .plist 文件读写

    ios本地文件内容读取,.json .plist 文件读写 本地文件.json .plist文件是较为常用的存储本地数据的文件,对这些文件的操作也是一种常用的基础. 本文同时提供初始化变量的比较标准的 ...

  7. ios 简单的plist文件读写操作(Document和NSUserDefaults)

    最近遇到ios上文件读写操作的有关知识,记录下来,以便以后查阅,同时分享与大家. 一,简单介绍一下常用的plist文件. 全名是:Property List,属性列表文件,它是一种用来存储串行化后的对 ...

  8. iOS文件和文件夹的创建,删除,移动, 拷贝,是否存在及简单数据类型的读写

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launc ...

  9. 【iOS】线程安全的文件读写

    前段时间看了一遍GCD(Grand Central Dispatch)多线程,GCD是苹果为多核开发提供的解决方案 多线程最常见的问题就是读写,比如数据库读写,文件读写,读取是共享的,写是互斥,允许多 ...

随机推荐

  1. SemaphoreFullException when checking user role via ASP.NET membership

    将指定的计数添加到该信号量中会导致其超过最大计数 This issue was fixed by restarting ASP.NET Development Server on windows ta ...

  2. 保存mysql用户的登录信息到~.my.cnf文件;用于方便登录操作。

    原理说明: 在用户调用mysql 这个客户端程序去登录目标服务器时,mysql客户端程序会从本地读取配置文件信息,它要去读的配置文件包括 /etc/my.cnf /etc/mysql/my.cnf ~ ...

  3. js里面“===”与“==”的区别

    首先,== equality 等同,=== identity 恒等. ==, 两边值类型不同的时候,要先进行类型转换,再比较. ==,不做类型转换,类型不同的一定不等.  下面分别说明: 先说 === ...

  4. android透明度和css透明度

    值越小,越透明 css:0.1-------1 android:#00-----------#ff

  5. 【Xamarin 挖墙脚系列:Windows 10 一个包罗万象的系统平台】

    build2016 结束后,证实了微软之前的各种传言.当然,都是好消息. Windows10 上基本可以运行主流的任意的操作系统. Windows Linux(在内部版本143216中,支持了bash ...

  6. boost的并发库

    thread: http://www.boost.org/doc/libs/1_61_0/libs/thread/ asio: http://www.boost.org/doc/libs/1_61_0 ...

  7. ASP.NET MVC4(Razor)从客户端中检测到有潜在危险的 Request.Form 值

    SP.NET MVC4(Razor)从客户端中检测到有潜在危险的 Request.Form 值 “/”应用程序中的服务器错误. 从客户端(Content=" sdfdddd ..." ...

  8. C#操作XML的完整例子——XmlDocument篇(转载,仅做学习之用)

    原文地址:http://www.cnblogs.com/serenatao/archive/2012/09/05/2672621.html 这是一个用c#控制台程序下,  用XmlDocument 进 ...

  9. Singleton 单例模式 泛型 窗体控制

    MDI子窗体 控制单例 /// <summary> /// 单例提供者 /// </summary> /// <typeparam name="T"& ...

  10. 杭电oj 2719

    Tips:本程序没有什么难度,只要按照逻辑进行替换即可,需要注意的是,由于输入串中含有空格符号,所以不能使用scanf("%s",ch);来读取一串,可以使用gets()函数读取一 ...