flo*_*ger 6 constants objective-c nsstring ios swift
在Objective-C中,我们都习惯于创建NSString常量来存储和访问NSDictionaries中的信息,或者用于NSNotifications的唯一名称.
// in MYClass.h
FOUNDATION_EXTERN NSString * const kMYNotificationName;
// in MYClass.m
NSString * const kMYNotificationName = @"my.app.notification";
[[NSNotificationCenter defaultCenter] postNotificationName:kMYNotificationName object:self userInfo:nil];
Run Code Online (Sandbox Code Playgroud)
现在,使用Xcode 6的混合和匹配我想在Swift类中注册这个特定的NSNotification:
NSNotificationCenter.defaultCenter()
.addObserver(self,
selector:"notificationReceived:",
name:kMYNotificationName,
object:nil)
Run Code Online (Sandbox Code Playgroud)
编译错误是"使用未解析的标识符'kMYNotificationName'",我无能为力.
我已经检查过的低调水果是:
有什么可以指点我的吗?除了"直接使用字符串"之外的任何变通方法?
非常感谢,弗洛
| 归档时间: |
|
| 查看次数: |
755 次 |
| 最近记录: |