gpt4 book ai didi

ios - NSUserDefault , Alloc init 与标准 Userdefault

转载 作者:可可西里 更新时间:2023-11-01 06:22:47 27 4
gpt4 key购买 nike

我很困惑

之间有什么区别

NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];

NSUserDefaults *userDefault = [[NSUserDefaults alloc] init];

谁能帮帮我……

提前致谢

最佳答案

NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];

the above line gives you the singleton object by using the class method standardUserDefaults the object received by this method is allocated single memory throughout the application.

NSUserDefaults *userDefault = [[NSUserDefaults alloc] init];

this will gives you the new object, each object is allocated a different memory and deallocated when object scope is finished.

如果您想在整个应用程序中存储和使用该值,那么最好使用单例对象,当您删除您的应用程序时,它将被释放

关于ios - NSUserDefault , Alloc init 与标准 Userdefault,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36615260/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com