Are pointers to arguments in Objective C methods are const by default? -


there methods in cocoa classes accept address of pointer. commonly argument address of future nserror * object in coredata validation methods (among others). way possible put custom or owned object place of address given argument points to.

my question is: why can't simple pointer arguments? e.g. let's have method:

- (void)addobject:(id)someobject toarray:(nsmutablearray *)array; 

i can pass mutable array second argument, call addobject: on , after method call array modified. why not done nserror * objects? pointers passed methods defined const default? avoid accessing null?

why not done nserror * objects?

because there's no such thing nsmutableerror. example works because can modify contents of array without modifying pointer array itself. however, since nserror instances immutable, cannot modify nserror. such, must create new error object. , if want return error object along other piece of data, @ least 1 of must done via out-parameter (such nserror **).

are pointers passed methods defined const default?

nope. inside method you're welcome this:

- (void)addobject:(id)someobject toarray:(nsmutablearray *)array {   someobject = somethingelse;   [array addobject:someobject]; } 

what's important remember here you're changing pointer in slot in memory. memory slot corresponding someobject space on stack, , you're changing contents of space have value points different allocated object 1 given.

is avoid accessing null?

any null protection need must done yourself.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -