繁体   English   中英

#import “Project-Swift.h” 出现了一些奇怪的问题

[英]#import “Project-Swift.h” comes some strange issue

项目与ocswift混合。

#import "myProjectName-Swift.h"AppDelegate.m ,:

项目是我创建的Objective-c语言,几乎用swift语言编写。 Appdelegate.m我想使用swift的类,所以

但不幸的是,我的项目在myProjectName-Swift.h出现了一些error

代码如下:

SWIFT_CLASS_PROPERTY(@property (nonatomic, class, readonly, copy) 
NSString * _Nonnull ;)

+ (NSString * _Nonnull);
SWIFT_CLASS_PROPERTY(@property (nonatomic, class, readonly, copy) 
NSString * _Nonnull ;)

+ (NSString * _Nonnull);

SWIFT_CLASS_PROPERTY(@property (nonatomic, class, readonly, strong) UIColor * _Nonnull APP_COLOR;)

+ (UIColor * _Nonnull)APP_COLOR;

错误是:

Expected ';' at end of declaration list.

cannot declare variable inside @interface or @protocal

Expected member name or ';' after declaration specifiers

Expected ']'

Property requires fields to be named

Missing '[' at start of message send expression

等等...


注意力
在全局swift ,我设置了汉字变量,如下所示:

class Global: NSObject {

}

编辑 - 1

因为我认为一个错误指出了static let " ,so I annotation this line, project will not show this错误. Or I delete the ,`,也不会显示错误。

Objective-C 在标识符(变量名、类名、方法名等)中不支持 Unicode,仅在字符串字面量(“🏋”)中支持。 只允许使用 ASCII 的一个子集(以 _[a-zA-Z] 开头,然后是 +[0-9])。

示例:

class MyClass : NSObject {
  func 😞() { }
}

当您在混合项目中编译它时,这将中断。 相反,您需要给它一个有效的 Objective-C 名称,如下所示:

class MyClass : NSObject {
  @objc(unhappyFace)
  func 😞() { }
}

它将编译(并且您需要在 ObjC 端以unhappyFace的形式访问它)。

或者在您的示例中,您需要修改 Global 对象:

class Global: NSObject {
  @objc(emptyNumberNotAllowed)
  static let 手机号码不能为空 = "手机号码不能为空"
  ... etc ...
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM