ios - 将未包装的引用传递给 Objective C 初始值设定项的问题

标签 ios objective-c swift

PhotoCollectionViewDelegate 有初始化器 -

-(instancetype)initWithController:(MyViewController *)controller {
    self = [super init];
    if(self) {
        self.myViewController = controller;
    }
    return self;
}

MyViewController.swift 文件中调用它,

let photoCollectionViewDelegate = PhotoCollectionViewDelegate(controller : self)

gives 'Can not convert value of type MyViewController to expected argument type 'MyViewController!'

PhotoCollectionViewDelegate(controller : MyViewController!) 但调用它的 selfMyViewController

最佳答案

这可能很愚蠢,但你试过吗:

let photoCollectionViewDelegate = PhotoCollectionViewDelegate(controller : self as MyViewController!)

关于ios - 将未包装的引用传递给 Objective C 初始值设定项的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43366252/

相关文章:

ios - 使导航栏标题成为按钮(Swift)

ios - Monotouch - UITableView 中具有可变高度的多个自定义表格单元格

objective-c - Foo 类在 MyApp 和 MyAppTestCase 中都实现了。将使用两者之一。哪个是未定义的

swift - SceneKit Swift 2.0 碰撞检测(SCNPhysicsContactDelegate)

objective-c - 分配 initWithString 与保留

ios - 如何防止用户不删除 UITextField 中的特定字符?

ios - dynamodb,MobileHub 不工作

ios - showAlert 方法中未声明的标识符

ios - 如何通过 SecureEnclave 持久存储加密数据

ios - 我将数组添加到字典中,然后从数组中删除所有对象