• 实现在ios文件读写


    文件都是用来读写数据的,可是哪里都会有潜规则,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  
  • 相关阅读:
    使用C语言实现面相对对象三大特性
    ResNet王者归来:ImageNet上刷新到80.7!
    VAE生成模型
    DeeplabV3++语义分割训练自制数据集
    CUDA编程入门极简教程
    加载预训练模型修改类别数与不修改类别数
    python使用opencv将Labelme生成的分割图转化成二值化分割图
    pytorch 单卡加载多卡模型module
    【pytorch】常用图像处理与数据增强方法合集(torchvision.transforms)(详细)
    C++11:原子交换函数compare_exchange_weak和compare_exchange_strong
  • 原文地址:https://www.cnblogs.com/riskyer/p/3331356.html
Copyright © 2020-2023  润新知