Objective-C copy properties

When I have a property like this:

@property (nonatomic, readonly, copy) NSURL *sourceURL; And then I call:

NSURL *url = self.sourceURL;

Assuming that ARC is disabled, to ensure this object does not leak, must I manually release url? If so, how come I don't have to with:

NSURL *url = [NSURL URLWithString:@"http://www.apple.com"];
NSURL *absURL = url.absoluteURL;

Despite the absoluteString property also being readonly and copy:

As per Apple:

@property(nullable, readonly, copy) NSURL *absoluteURL;

I believe "copy" means that it copies the object you supply when you assign to the property. It's not relevant when you read from the property, as in your url = self.sourceURL example.

If true why would Apple have @property(nullable, readonly, copy) … ?

Because it’s common for APIs to have a private setter. For that to make sense you have to declare the property like that in the header and then, in a private class extension, you declare it readwrite. The copy is saying If this property were settable, it’d use copy semantics.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Objective-C copy properties
 
 
Q