码迷,mamicode.com
首页 > 其他好文 > 详细

Objective-C level-2

时间:2015-11-02 00:12:23      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:

1 Sending a message

真正好玩的才伴随着 “sending messages”开始了. Sending a message will be the basic building block of your Objective-C apps because it is how you tell an object to perform some action or to give you some piece of information.

发送消息需要两样东西 - 一个object和一个message name:

[objectName messageName]; #方括号不能少

发送一个简单的消息:

[tryobjc completeThisChallenge];

2 发送描述信息

The tryobjc object is something we made up, but the objects built-in to Objective-C, like NSString, NSNumber, and NSArray, are real and have a bunch of messages you can send to them.

One of those messages is description, and there’s something extra cool about it - passing the message returns a result. Not all messages return something, but the description message always returns an NSString that represents the contents of the object that you passed the message to.

If you send description to an NSString object, you’ll get the characters in that string, but if you send it to an NSArray you’ll get a string containing all of the values in that array.

NSArray *foods = @[@"tacos", @"burgers"];

NSLog(@"%@", foods);

#输出:
#challenge[3]: (
#    tacos,
#    burgers
#)

3 Storing the result of a message

 

Objective-C level-2

标签:

原文地址:http://www.cnblogs.com/for-you/p/4928877.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!