结构体指针的使用非常频繁,因此有一个特殊的运算符:->。下面的表达式是等价的:
(*x).y
x->y
Run Code Online (Sandbox Code Playgroud)
将此运算符简单地视为如下定义的预处理器宏是否公平:
#define (x)-> (*(x).)
为什么或者为什么不?或者它从一开始就被编码为运算符 - 这有何不同/优势?
只是好奇。
我有一个简单的基于文档的Cocoa应用程序调用"RaiseMan".当我去保存文件时,控制台中会显示以下消息:
-[NSDocumentController fileExtensionsFromType:] is deprecated, and does not work when passed a uniform type identifier (UTI). If the application didn't invoke it directly then the problem is probably that some other NSDocument or NSDocumentController method is getting confused by a UTI that's not actually declared anywhere. Maybe it should be declared in the UTExportedTypeDeclarations section of this app's Info.plist but is not. The alleged UTI in question is "com.bignerdranch.raiseman-doc".
如果我将当前文件保存为"测试",则会显示一个以.plist打开的文件,并且不会使用Raiseman应用程序打开.如果我将其保存为"Test.rsmn"(明确键入扩展名),则将其保存为Raiseman类型文件,但是当我重新打开文件时,我无法访问任何用户首选项或首选项面板(.xib) .
背景:我目前正在通过Aaron Hillegass的Mac OS X编程,第13章......
在 Objective-C 中命名参数时,如果我对类似的方法使用相同的名称,这是否重要 - 也就是说,对于文档/易读性是可取的?例如:
@interface Zookeeper : Employee
-(void) washAnimal:(Animal *)someAnimal;
-(void) feedAnimal:(Animal *)someAnimal;
-(void) trainAnimal:(Animal *)someAnimal;
...
Run Code Online (Sandbox Code Playgroud)
或者,应该是这样的:
@interface Zookeeper : Employee
-(void) washAnimal:(Animal *)animalToBeWashed;
-(void) feedAnimal:(Animal *)animalToBeFed;
-(void) trainAnimal:(Animal *)animalToBeTrained;
...
Run Code Online (Sandbox Code Playgroud)
谢谢!
我总是不得不在break开关声明中; 简单地用分号;退出是不安全的?
switch ( (rand() % 2) ) {
case 0:
// Do foo;
break;
case 1:
// Do nothing
;
default:
;
}
Run Code Online (Sandbox Code Playgroud)