在Objective-C中声明实例变量并在Swift中设置

时间:2018-06-07 23:01:23

标签: objective-c swift

我希望能够在我的Swift类中设置Objective-C类的实例变量的值。在我的Swift课程中,我希望能够说出类似cameraViewController.ingestViewController = self的内容,并在我的Objective-C类中设置ingestViewController的值。以下是一些演示代码:

PhotoViewController.swift:

class PhotoViewController : UIViewController {
    let cameraViewController = // reference to the CameraViewController
    cameraViewController.ingestViewController = self
}

CameraViewController.h:

@interface CameraViewController : GSKCameraViewController

@end

CameraViewController.m:

@interface CameraViewController ()

@property (nonatomic, strong) UIView *toolbar;
@property (nonatomic, strong) UIButton *cameraButton;
@property (class, nonatomic, strong) UIViewController *ingestViewController;

@end

@implementation CameraViewController

UIViewController *ingestViewController

// rest of implementation

@end

我继续收到错误Value of type 'CameraViewController?' has no member 'ingestViewController'

2 个答案:

答案 0 :(得分:0)

@property (class, nonatomic, strong) UIViewController *ingestViewController;

这是一个类属性,而不是实例变量属性。 所以只需删除class属性。

答案 1 :(得分:-1)

您已将ingestViewController属性声明为类属性,而不是实例属性。

删除class。{/ p>的@property属性

@property (nonatomic, strong) UIViewController *ingestViewController;

修复后,您需要公开该属性。将其移至.h文件:

@interface CameraViewController : GSKCameraViewController

@property (nonatomic, strong) UIViewController *ingestViewController;

@end

.m中的所有属性都是私有的。

最后,删除不必要的行:

UIViewController *ingestViewController
<。>来自.m文件。这实际上是声明一个全局变量,并且与同名属性没有任何关联。

相关问题