我是学习swift的新手,我尝试在objC源中定义属性,但后来我不知道从我的swift代码中访问它:(
foo.h中
#import "RCTView.h"
@interface Foo : RCTView
@property (nonatomic, assign) NSString *config;
@end
foo.m
#import "foo.h"
#import "RCTViewManager.h"
#import "RCTBridgeModule.h"
@interface RCT_EXTERN_MODULE(Foo, RCTViewManager)
RCT_EXPORT_VIEW_PROPERTY(config, NSString);
@end
foo.swift
import Foundation
@objc(Foo)
class Foo : {
struct Foo
{
static var bar = ""
}
func setConfig(config: String!) {
Foo.bar = config
}
}
现在我只是通过struct获取属性config
值,我怎么能直接从swift代码中获取它?
答案 0 :(得分:0)
如果您想在同一个项目中使用 swift 和 objective-c ,那么您必须使用连接swift的桥接标题目标c。以下是官方文档:https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html