Skip to Content
COCOA學習手冊--使用OBJECTIVE-C第三版
book

COCOA學習手冊--使用OBJECTIVE-C第三版

by Paris Buttfield-Addison, Jonathon Manning
June 2013
Intermediate to advanced
360 pages
6h 50m
Chinese
GoTop Information, Inc.
Content preview from COCOA學習手冊--使用OBJECTIVE-C第三版
模型物件與資料儲存
|
153
一旦完成,你可以向預設物件要求值。
你用
registerDefaults:
方法登記的預設值並未被儲存在磁碟上,這表
示,你必須在每次應用程式啟動時呼叫這個方法。然而。你在應用程式中
設定的預設值 [ 參見〈設定偏好設定〉(第 154 頁)] 確實有被儲存下
來。
存取偏好設定
一旦建立,
NSUserDefaults
物件可以很像字典那樣被處理,但具有一些限制。你可以透
objectForKey:
方法從預設物件擷取值︰
// 使用 "greeting" 鍵從預設物件擷取字串
NSString* greeting = [[NSUserDefaults standardUserDefaults]
objectForKey:@"greeting"];
不過,與
NSDictionary
不同,只有幾種物件可以被儲存在預設物件中。能夠被儲存在預
設物件裡的物件只有
特性清單物件
property list object
),包括︰
NSString
NSArray
NSDictionary
NSData
NSNumber
NSDate
如果你必須把任何其他種類的物件儲存在預設物件中,應該透過歸檔(archive)將它轉
換成
NSData
(參見第 3 章的〈序列化與反序列化〉(第 51 ))。
儲存在
NSUserDefaults
裡的所有一切都必須是
NSObject
,那表示,如果你想要從
NSUserDefaults
取得整數,實際上取回的是包含該數字的
NSNumber
物件︰
// ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

網頁互動式資料視覺化:使用D3

網頁互動式資料視覺化:使用D3

Scott Murray
深入淺出代數

深入淺出代數

Tracey Pilone, Dan Pilone
自然语言处理实战:从入门到项目实践

自然语言处理实战:从入门到项目实践

Sowmya Vajjala, Bodhisattwa Majumder, Anuj Gupta, Harshit Surana

Publisher Resources

ISBN: 9789862768136