Ios 将未包装的引用传递给目标C初始值设定项时出现问题
Ios 将未包装的引用传递给目标C初始值设定项时出现问题,ios,objective-c,swift,Ios,Objective C,Swift,PhotoCollectionViewDelegate具有初始化器- -(instancetype)initWithController:(MyViewController *)controller { self = [super init]; if(self) { self.myViewController = controller; } return self; } 从MyViewController.swift文件调用此函数 let pho
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!'
i、 e
PhotoCollectionViewDelegate(控制器:MyViewController!)
但是调用它的self
是MyViewController
这可能很愚蠢,但您是否尝试过:
let photoCollectionViewDelegate=photoCollectionViewDelegate(controller:self as MyViewController!)
这可能很愚蠢,但您是否尝试过:
让photoCollectionViewDelegate=photoCollectionViewDelegate(controller:self as MyViewController!)
试试看:
let optionalSelf = self as MyViewController!
let wrappedSelf = optionalSelf ?? nil
let photoCollectionViewDelegate = PhotoCollectionViewDelegate(controller : wrappedSelf)
试一试:
let optionalSelf = self as MyViewController!
let wrappedSelf = optionalSelf ?? nil
let photoCollectionViewDelegate = PhotoCollectionViewDelegate(controller : wrappedSelf)
是的,但不确定如何获取MyViewController!(可选值)使用self,因为self会给出MyViewController(展开值)yes,但不确定如何获取MyViewController!(可选值)使用self,因为self不会给MyViewController(未包装的值)带来好运,会给-无法将类型为“(NSObject)->()->MyViewController”的值转换为类型“MyViewController!”在强制中,如果没有运气,gives-无法将类型为“(NSObject)->()->MyViewController”的值转换为类型为“MyViewController!”胁迫