开发者

A Couple Obj-C Questions

开发者 https://www.devze.com 2023-03-10 05:51 出处:网络
EDIT: My internet went out last night ._. Well I\'m new to the language. I got some basics down but: -(XYPoint *)origin

EDIT: My internet went out last night ._.

Well I'm new to the language. I got some basics down but:

  1. -(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.

  2. 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.


  1. 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.

  2. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号