objective -c委托语法查询(objective -c delegates syntax query)
我是objective-c的新手,并且与代理的使用方式相当混淆。 我遇到了这个代码,我想用它来澄清一些疑问。
#import <Foundation/Foundation.h> @protocol ProcessDataDelegate <NSObject> @required - (void) processSuccessful: (BOOL)success; @end @interface ClassWithProtocol : NSObject { id <ProcessDataDelegate> delegate; } @property (retain) id delegate; -(void)startSomeProcess; @end
在这里,有两个对“委托”一词的引用,任何人都可以解释在上下文中用“id angled bracket delegate angled-bracket-closed”时的意思吗?
同样,有一个名称委托的属性。 它不应该引起任何形式的冲突?
提前致谢,
I am new to objective-c and pretty much confused with the way delegates are used. I came across this code and i would like to use it to clarify some of the doubts.
#import <Foundation/Foundation.h> @protocol ProcessDataDelegate <NSObject> @required - (void) processSuccessful: (BOOL)success; @end @interface ClassWithProtocol : NSObject { id <ProcessDataDelegate> delegate; } @property (retain) id delegate; -(void)startSomeProcess; @end
Here, there are 2 references to the word "delegate" can anyone explain what it means when used in context with "id angled bracket delegate angled-bracket-closed" ??
Again, there is a property with name delegate. Should it not cause any kind of conflict ??
Thanks in advance,
原文:https://stackoverflow.com/questions/11750486
最满意答案
您不应该分配appDelegate的另一个实例。 如果要访问它,可以使用
[[[UIApplication sharedApplication] delegate] composeBar:YES];
You should not alloc another instance of your appDelegate. If you want to access it you can use
[[[UIApplication sharedApplication] delegate] composeBar:YES];
相关问答
更多-
为什么一个类需要一个空的方法被调用来注册它?(Why would a class need an empty method to be called to register it?)[2022-12-22]
Delphi编译器很聪明,在编译/链接代码时会试图消除未使用的代码,所以从编译器的角度来看,示例中的实现类(例如TCSVDataService )不会在程序中的任何地方使用,并且会被淘汰,所以这些空方法的调用是为了防止这种情况发生。 The Delphi compiler is smart and will try to eliminate unused code when compiling/linking the code, so from the compiler's point of view, t ... -
在MissionAgreement.php ,您需要使用$ argc和$ argv来获取系统调用传递给它的命令行参数,然后将这些值分配给$var1 , $var2等。 或者,你可以使用getopt() Inside your MissionAgreement.php, you need to use $argc and $argv to get the command line arguments that your system call is passing to it, and then assign ...
-
你可以实现这样的东西,但它不是很漂亮。 正如gnibbler指出的那样,使用插值更容易。 关于我看到做这样的事情的唯一好处是格式字符串是否多次格式化相同的值。 即便如此,使用自定义哈希(而不是将变量转储到格式化程序中)或将其抽象为方法可能更容易。 #!/usr/bin/env ruby module Kernel def vars(b) Hash[ (b.eval('local_variables')-[:_]). map{|v| [v,b.eval(v.to_s)]} ...
-
$offset = 1; $backtrace = debug_backtrace(); $caller = array(); if(isset($backtrace[$offset])) { $backtrace = $backtrace[$offset]; if(isset($backtrace['class'])) { $caller['class'] = $backtrace['class']; } if(isset($backtrace['funct ...
-
您可以在其他函数内调用该函数: $ret = false; // return true or false if (!$ret) $this->ifFalse(); return $ret; 如果你想要它更“神奇”,你可以这样做: public function __call($name, $arguments) { switch($name) { case 'funcA': case 'funcB': $value = $this->$na ...
-
如何调用这个方法?(How this method is called?)[2023-12-09]
FProcess的类型为T ,其中T被限制为可IStoppable的接口或从IStoppable派生的IStoppable 。 所引用的方法调用因此调用IStoppable的Stop方法。 想象一下, FProcess被声明为IStoppable类型。 FProcess: IStoppable; 如果那样的话,我认为你会理解代码。 每当你发现自己在努力理解泛型代码时,这是一种有用的技巧。 将泛型替换为具体类型并再次读取代码。 理解具体代码通常会容易得多,而理解将帮助您推广到通用代码。 就实现方法而言,这里 ... -
这里有一些大问题。 GameObject *go = new GameObject(); go = this->data; 您正在创建一个新对象,然后忘记了指向该对象的指针。 每次您调用渲染时都会发生这种情况,所以您有大量内存不会随着时间而增长。 你可以说: GameObject *go = NULL; 在不分配数据的情况下创建一个指针。 你也可以在任何地方省略this-> foo。 它隐含在所有类中。 因此,虽然我看不到这个代码中的错误,但它可能是其他地方的,因为你正在用上面的指针来犯错误。 你可能有 ...
-
您不应该分配appDelegate的另一个实例。 如果要访问它,可以使用[[[UIApplication sharedApplication] delegate] composeBar:YES]; You should not alloc another instance of your appDelegate. If you want to access it you can use [[[UIApplication sharedApplication] delegate] composeBar:YES] ...
-
您缺少Image import语句。 导入Image类,你应该没问题。 You lack the Image import statement. Import the Image class and you should be fine.
-
首先,免责声明:以var = something之外的任何方式将变量“拉”到本地范围内真的不是 真的不推荐。 对于那些不熟悉你正在做的事情的人(即不是你的人,或将来6个月的人,等等),你的代码往往会让你的代码感到困惑。 话虽如此,仅出于教育目的,有一种方法。 你的pull_args函数可以像这样实现: def pull_args(request, *args): pulled = {} try: for a in args: pulled[a] = r ...