How does Swift implement ARC in property attributes? -
How does Swift implement ARC in property attributes? -
how swift implement arc in property attributes? example, how create string variable utilize re-create instead of strong in swift?
you can utilize @nscopying
attribute when want copy
behaviour objective-c.
from swift book:
apply attribute stored variable property of class. attribute causes property’s setter synthesized re-create of property’s value—returned copywithzone method—instead of value of property itself. type of property must conform nscopying protocol.
the nscopying attribute behaves in way similar objective-c re-create property attribute.
however, in specific case of string
properties, it's not necessary so.
strings value type in swift. such, when existing string
assigned new variable, variable stores re-create of string, rather reference existing one.
swift’s string type value type. if create new string value, string value copied when passed function or method, or when assigned constant or variable. in each case, new re-create of existing string value created, , new re-create passed or assigned, not original version.
so, @nscopying
attribute used when have properties of reference type want set using re-create behaviour.
swift
Comments
Post a Comment