Objective-C (aClassName *) -


i'm kind of self-programmer-made-man, i'm missing basic knowledge time time.

that's why i'm unable define topic of question, because don't know how name , how works (but know answer seem trivial many of you). when know what's you're looking it's lot easier find answers.

in objective-c, can see lines of code :

aclassname *myobject = (aclassname *)[nsentitydescription insertnewobjectforentityforname:@"aclassname" inmanagedobjectcontext:app.managedobjectcontext]; 

what's bother me (aclass *) part. what's ?

i know/feel it's related basic knowledge can't name can't find it.

my guess (and that's how use now) that's used calling class methods (+) i'm not sure of , may more deep understand.

thanks explanation.

it's cast, in case down cast (even because casts implicit).

a cast operation developer while writing code hint compiler type narrower 1 compiler thinking about.

think following situation:

class *a = [[subclass alloc] init]; subclass *b = a; 

(assume subclass subclass of class)

this won't compile because a statically defined type not contained in subclass. assignment wouldn't create problem dynamically because a used store subclass object in practice.

so do? place cast subclass *b = (subclass*)a; tell compiler "trust me , ignore typechecking assignment, assert valid runtime", , automagically remove compilation error. forcing behaviour of course removes type safety code, must know doing.

of course understand meaning of cast in situation must @ least know inheritance , objects..

in specific situation return type of method +(id)insertnewobjectforentityforname:... id, least specific kind of object in objectivec, needs casted if not stored plain id


Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -