Skip to Content
Swift游戏开发经典实例
book

Swift游戏开发经典实例

by Jonathon Manning, Paris Buttfield-Addison
January 2020
Intermediate to advanced
356 pages
6h 4m
Chinese
China Electric Power Press Ltd.
Content preview from Swift游戏开发经典实例
166
5
}
}
func endGame() {
//
当游戏结束,金币数清零,但钻石数不清零
gold = 0
}
}
讨论
在这个解决方案中,
gems
属性将它的值保存到
UserDefaults
系统,而不是简单地
放到内存里(而
gold
属性是放到内存里的)。对于其他对象来说,可能会这样使
用这个属性:
let currency = CurrencyManager()
currency.gold = 45
currency.gems = 21
currency.endGame()
一旦数据被保存到
UserDefaults
,它会在
App
多次运行中保持存在。也就是说,
哪怕是应用程序退出后,有的玩家就喜欢这样干,但不管怎么样,钻石数仍然是之
前保存的值。注意,保存在用户
Defaults
系统中的数据是可以被玩家修改的,这
样也是有可能作弊的。
5.10
保存到
CloudKit
问题
你想将游戏数据保存到
CloudKit
,即苹果的云存储方案。
解决方案
要使用
iCloud
,你首先需要开启
App
iCloud
能力,请参考问题
5.3
中所说的步骤。
然后你必须单独为项目配置
CloudKit
。在
iCloud
设置中,勾选
CloudKit
Xcode
会为将你的
APP
iCloud
容器设置为
CloudKit
存储数据
167
如果你点击
CloudKit Dashboard
按钮,你将进入网页版的
CloudKit
dashboard
,通过它你可以查看和管理你存储到
CloudKit
中的数据。 ...
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

精通機器學習

精通機器學習

Aurélien Géron
FreeBSD® Unleashed

FreeBSD® Unleashed

Brian Tiemann, Michael C. Urban
深入淺出代數

深入淺出代數

Tracey Pilone, Dan Pilone
Swift学习手册

Swift学习手册

Jon Manning, Paris Buttfield-Addison, Tim Nugent

Publisher Resources

ISBN: 9787519840129