文件都是用来读写数据的,可是哪里都会有潜规则,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
);
}
NSCachesDirectory <Application_Home>/Library/Caches
NSApplicationSupportDirectory <Application_Home>/Library/Application Support