NSDictionary* defaults = [[NSUserDefaults standardUserDefaults] dictionaryRepresentation];
創新互聯公司專注于企業全網整合營銷推廣、網站重做改版、肥東網站定制設計、自適應品牌網站建設、H5響應式網站、成都做商城網站、集團公司官網建設、外貿網站建設、高端網站制作、響應式網頁設計等建站業務,價格優惠性價比高,為肥東等各大城市提供網站開發制作服務。if([[NSUserDefaults standardUserDefaults] objectForKey:@"message"]==nil){
[[NSUserDefaults standardUserDefaults] setObject:@"This is message" forKey:@"message"];
}
代碼意思是判斷NSUserDefaults的“message”key 在dictionaryRepresentation中是否存在,如果不存在就
設置“message”。
在加上句[[NSUserDefaults standardUserDefaults] synchronize];////立刻同步,沒有這句,它不會立刻創建文件的,要等個時間戳之后
也見過別人把默認參數的設置寫到applicationDidFinishLaunching注冊的
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
NSDictionary *defaultValues = [NSDictionary dictionaryWithObjectsAndKeys:
@"This is message", @"message",
nil];
[[NSUserDefaults standardUserDefaults] registerDefaults:defaultValues];
[[NSUserDefaultsController sharedUserDefaultsController] setInitialValues:defaultValues];
}
////////////////////下邊是另外一個高手的講解/////////////////////////
例子簡單點:
[[NSUserDefaults standardUserDefaults]setBool:YESforKey:@"sendversion"];//寫入
[[NSUserDefaults standardUserDefaults]synchronize];//立刻同步,沒有這句,它不會立刻創建文件的,要等個時間戳之后
k,你的plist文件就會有這東西了
然后你就可以判斷了
if ([[NSUserDefaultsstandardUserDefaults] boolForKey:NSDEFAULT_SEND_VERSION] ==NO)
{
你的操作
}
另外
在說說這個東西創建完了之后的位置(好多人找不到)
/Users/apple/Library/Application Support/iPhone Simulator/5.0/Applications/
然后里面就是你的模擬器里面各個項目的文件夾,找到你的(全是一對號碼,找不到?那就都刪了,留你自己那個,不就找到了嗎)
然后就是下圖(我自己的)xxxxxxxxx-Library-Preferences-com.xxxxx(你的項目名字) 就找到了
下面是大神們的講解和例子
http://www.cocoachina.com/bbs/read.php?tid=6125&page=1 (有例子哦)
http://www.cocoachina.com/bbs/read.php?tid=9414&keyword=NSUserDefaults
網頁題目:NSUserDefaults教程-創新互聯
標題URL:http://vcdvsql.cn/article34/cccpse.html
成都網站建設公司_創新互聯,為您提供虛擬主機、網站排名、ChatGPT、網站營銷、搜索引擎優化、網站導航
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯