A Couple Obj-C Questions
EDIT: My internet went out last night ._.
Well I'm new to the language. I got some basics down but:
-(XYPoint *)origin
In this, why does the return value for this method look like a pointer? I'm confused. I know what void, id, double, etc are but I don't get why this has a pointer.
I was going through Kochans book, and I got to a program.
myRect.origin = myPoint NSLog(@"origin:(%i,%i)",myRect.origin.x,myRect.origin.y)
Or something like that.
But after the NsLog I put In a release. Then called the origin again, but it still got printed. Shouldn't it have gave an error?
Later, I printed another NSLog calling another variable, then after, I called the origin again, but this time I was given an error, though I was not when I tried calling it after the release. Sor开发者_如何学Pythonry if this seems vague, but I will elaborate if needed.
Simply because the return type is a pointer type, so it's designated as returning a pointer.
Note that anything can be turned into a pointer type where the pointer is returned rather than the object it points to in memory, but that's probably something more advanced than just Objective-C classes.
Release doesn't always mean the object gets deallocated right away. It can be instantaneous, or in a second, or a few, that it actually happens. Or, if the object was retained elsewhere, then it doesn't get deallocated yet at all.
精彩评论