Apply this attribute to a stored variable property of a class. This
attribute causes the property’s setter to be synthesized with a copy
of the property’s value—returned by the copyWithZone method—instead of
the value of the property itself. The type of the property must
conform to the NSCopying protocol.The NSCopying attribute behaves in a way similar to the Objective-C
copy property attribute.
但是,在String属性的特定情况下,没有必要这样做.
字符串是Swift中的值类型.因此,当将现有String分配给新变量时,该变量实际上存储了String的副本,而不是对现有变量的引用.
Swift’s String type is a value type. If you create a new String value,
that String value is copied when it is passed to a function or method,
or when it is assigned to a constant or variable. In each case,a new
copy of the existing String value is created,and the new copy is
passed or assigned,not the original version.
因此,当您具有要使用复制行为设置的引用类型的属性时,将使用@NSCopying属性.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。