Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift-在应用程序运行期间,如何在缓存中存储对象?-当显示其他vc时,NSCache()将被清除_Swift_Xcode_Uikit_Swift4_Nscache - Fatal编程技术网

Swift-在应用程序运行期间,如何在缓存中存储对象?-当显示其他vc时,NSCache()将被清除

Swift-在应用程序运行期间,如何在缓存中存储对象?-当显示其他vc时,NSCache()将被清除,swift,xcode,uikit,swift4,nscache,Swift,Xcode,Uikit,Swift4,Nscache,我正在尝试将自定义类保存到缓存中,这样就不必每次调用vc时都下载它。 我的问题是,当我打开另一个vc时,缓存会被清除,因此当返回到“旧”vc时,缓存中不再存储任何对象:( 我甚至尝试过:cache.executesObjectsWithDiscardedContent=false 非常感谢您的帮助!您可以使用singleton类临时存储数据。欢迎访问StackOverFlow查看此@vivekDas我如何在缓存中存储singleton类的实例?您不需要在缓存中存储singleton类,而是可以创

我正在尝试将自定义类保存到缓存中,这样就不必每次调用vc时都下载它。 我的问题是,当我打开另一个vc时,缓存会被清除,因此当返回到“旧”vc时,缓存中不再存储任何对象:(

我甚至尝试过:cache.executesObjectsWithDiscardedContent=false


非常感谢您的帮助!

您可以使用singleton类临时存储数据。欢迎访问StackOverFlow查看此@vivekDas我如何在缓存中存储singleton类的实例?您不需要在缓存中存储singleton类,而是可以创建singleton实例,在singleton类中,您可以拥有所有需要的数据只要你的应用还在运行,就可以保存。