开发者

Return in Objective-C

What is the us开发者_开发知识库e of returning an integer for main in Objective-C programs.


I assume the same as in C programs. Return value is useful when you run application from command line it gives you indication if it failed or not.

Most commands in shell give indication like that. You can then build shell script and run your app, check return value and do something based on that.

C was originally created for writing operating systems like Unix.

For example take some linux/unix utility like ls command:

> ls
bla1 bla2
> echo $?
0
> ls bla3
/bin/ls: bla3: No such file or directory
> echo $?
1

Now you can use the return value in shell script.


As Stefan assumes, Cocoa apps return an integer from main() because they follow the UNIX conventions. In practice, we rarely return anything other than zero unless the app has crashed.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜