我正在尝试将Objective-C中的这些行转换为快速行
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*)sender
{
...
NSAppleEventDescriptor* appleEventDesc = [[NSAppleEventManager sharedAppleEventManager] currentAppleEvent];
NSAppleEventDescriptor* whyDesc = [appleEventDesc attributeDescriptorForKeyword:kEventParamReason];
OSType why = [whyDesc typeCodeValue];
if (why==kAEShutDown || why==kAERestart || why==kAEReallyLogOut)
它们将检测应用是否由于系统关闭而终止。
我无法转换此行
if (why==kAEShutDown || why==kAERestart || why==kAEReallyLogOut)
我猜是这样的
let codeValue = whyDescription?.typeCodeValue
if ((codeValue == AEKeyword(kAEShutDown)) ||
(codeValue == AEKeyword(kAERestart)) ||
(codeValue == AEKeyword(kAEReallyLogOut))) {
这是正确的吗?
或者应该是
if ((codeValue == OSType(kAEShutDown)) ||
(codeValue == OSType(kAERestart)) ||
(codeValue == OSType(kAEReallyLogOut))) {
Xcode可以很好地进行编译,但是我不确定kAEShutDown
,kAERestart
和kAEReallyLogOut
是否是可在此处使用的AEKeywords。
按预期,我找不到任何文档。
AEKeyword
和OSType
均为typealias
至FourCharCode
。从技术上讲,它们是相同的类型,因此使用哪个都无所谓。
但是,由于将typeCodeValue
声明为OSType
,因此OSType
是逻辑选择。
而且,似乎常量已经声明为OSType
,因此应该没有任何理由要强制转换它们。