Re: What, exactly constitutes a mutable action on an instance?
Re: What, exactly constitutes a mutable action on an instance?
- Subject: Re: What, exactly constitutes a mutable action on an instance?
- From: Alex Zavatone <email@hidden>
- Date: Tue, 28 May 2013 10:43:44 -0400
On May 28, 2013, at 9:50 AM, Roland King wrote:
>
> On 28 May, 2013, at 9:39 PM, Alex Zavatone <email@hidden> wrote:
>
>> Though it's clearly defined in the docs when to use NSMubleAnything vs. NSAnything (insert Array, Dictionary, String, etc for Anything), there is no compiler warning when you perform a simple action such as allocate a string and then reassign values to it.
>>
>> With this in mind, what exactly constitutes a mutable action?
>>
>> If we take this:
>>
>> NSString *myString;
>> myString = @"Hi";
>> myString = @"Hi there";
>>
>> I'm clearly expecting some type of warning from the compiler when myString is redefined, but I don't see one in Xcode 4.6.1. Is this redefinition not a mutable action? It sure seems like it is.
>
>
> myString is a pointer to an NSString (or subclass thereof). It's not const, it's not static so the pointer can point to any NSString (or subclass thereof) and be reassigned at will. There is a huge difference between an NSString, which cannot be mutated and a pointer to an NSString which can.
>
> This is pretty basic.
Yes, it's pretty basic, and this is why I am asking. To make sure I've got it 100% right.
Though you stated that myString is a pointer to "an NSString" I'm expecting that myString is a pointer not to NSString, but an instance of NSString. Which is correct?
I'm having to explain mutabie vs nonmutable to web devs and am providing concrete examples of what constitutes legit/non legit actions, so wanted to make sure that I have everything properly understood in my head and am interpreting the compiler feedback correctly.
Thanks much.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden