简体   繁体   English

快速保存到本地存储

[英]save to local storage swift

I am designing an idle clicker style app, as I am quite new to programming and thought it would be a good personal project. 我正在设计一个空闲的Clicker风格的应用程序,因为我对编程很陌生,因此认为这将是一个不错的个人项目。 However I am trying to design the upgrades on a second ViewController menu, however every time that the user leaves the first ViewController, all the settings on that page are lost eg stats. 但是,我试图在第二个ViewController菜单上设计升级,但是,每当用户离开第一个ViewController时,该页面上的所有设置都会丢失,例如统计信息。 I know that there are already similar questions, but they don't relate to my issue and I am having difficulties trying to understand them. 我知道已经有类似的问题,但是它们与我的问题无关,并且我在尝试理解它们方面遇到困难。

I was just wondering if someone had any way to save this progress both when the user moves to a new viewController and when the app is closed and reopened. 我只是想知道在用户移动到新的viewController以及关闭并重新打开应用程序时,是否有人可以保存此进度。 Also this might be pushing it, but if you could describe what each part of the code does it would be very helpful. 这也可能会推动它,但是如果您可以描述代码各部分的功能,将非常有帮助。

Thanks 谢谢

Best is to use UserDefaults to store page contents. 最好是使用UserDefaults存储页面内容。 You can define key/value pairs and save and load values as needed. 您可以定义键/值对,并根据需要保存和加载值。 Look for it in the IOS documentation. 在IOS文档中查找它。 It is very easy to implement it. 实施起来非常容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM