Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

说说你对assign,strong,weak,unsafe_unretained,copy的理解 #6

Open
tbfungeek opened this issue Jan 4, 2020 · 0 comments

Comments

@tbfungeek
Copy link
Owner

  • strongcopy都会持有对象,一个是持有对象的本身,一个是持有对象的副本。copy 多用于修饰有可变类型的不可变对象例如 NSString,NSArray,NSDictionary上。

  • weakunsafe_unretained 更像一个旁观者,它们不会对数据的引用计数起到任何的改变,它看着对象被持有,被销毁却无能为力,weak,unsafe_unretained 二者的区别在于weak会在对象被销毁的时候会将其置为nil。而unsafe_unretained不会,unsafe_unretained 在开发中用得比较少, 如果对性能有极高的要求方可以考虑使用 unsafe_unretained 替换 weak,因为weak 其实对性能还是有影响的,只不过少量使用的时候是不会察觉到的。weak的最主要作用就是解决循环引用的问题。

  • assign 表明 setter 仅仅是一个简单的赋值操作,没有持有不持有这一说,通常用于基本的数值类型

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant