在目标C语法中使用* [英] Use of * in Objective C Syntax
问题描述
我在用一些客观的c语法苦苦挣扎.有人可以在下面的实例方法中详细说明*的用法.
I'm struggling a bit with some objective c syntax. Can someone please elaborate on the usage of * in the following instance method.
- (IBAction)sliderChanged:(id)sender{
UISlider *slider = (UISlider *)sender;
}
我意识到我们正在创建一个类型为UISlider的变量,然后在将其转换为UISlider后将其设置为sender.但是,我不知道*的含义和原因
I realize that we are creating a variable typed as UISlider and then setting it to sender once it is cast as a UISlider. However, I don't understand what the * are for and why
UISlider slider = (UISlider)sender;
不起作用.
推荐答案
*,像在C中一样,在类型中使用时表示指针(例如您的情况)并取消引用指针.
*, like in C, when used in a type denotes a pointer (such as your case) and to dereference a pointer.
指针只是一个变量,它包含其他内容(在您的示例中为UISlider对象)在内存中的地址.
A pointer is just a variable that contains the address in memory of something else, in your example a UISlider object.
在您的示例中,
UISlider *slider = (UISlider *)sender;
slider类型为UISlider *
,或者是指向UISlider对象的指针.
slider is of type UISlider *
, or a pointer to a UISlider object.
以下有关C语言中指针的教程也适用于Objective-C: 您需要了解的有关C语言中的指针的所有信息
The following tutorial about pointers in C also applies to Objective-C: Everything you need to know about pointers in C
这篇关于在目标C语法中使用*的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!