开发者

When to use functions and when to use messages

I am really feeling like a nube today, i didn't realise Object开发者_如何学JAVAive-C had functions - I simply thought that you always use to use messages!

When should one use functions and when should one use messages?

For example if I am creating a object within my class should I use a function?


Objective-C is a strict superset of C, so anything you can do in C you can do in Objective-C, including functions.

Even though you can, technically, use functions for everything in Objective-C, you shouldn't. Clarity should be your first concern and writing classes that are a mixture of methods and functions is confusing. Strive to emulate the APIs that you are using. If you're writing UIKit code, stick with methods only. If you're doing drawing in Core Graphics, use functions.

If you aren't sure, use methods. If you're creating an object in your class use methods.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜