Objective c 无法转换类型为';NSArray.Element';预期论点
我有一个用Objective C编写的静态库,其中我有一个协议来获取监控结果的回调Objective c 无法转换类型为';NSArray.Element';预期论点,objective-c,swift,delegates,nsmutablearray,protocols,Objective C,Swift,Delegates,Nsmutablearray,Protocols,我有一个用Objective C编写的静态库,其中我有一个协议来获取监控结果的回调 @protocol ScanBeaconsDelegate <NSObject> @required - (void) onBeaconDetected: (NSMutableArray <Beacon*> *) detectedBeacons @end 我不知道如何将detectedBeacons数组强制转换为Beacon对象,我得到一个“无法将序列元素类型'NSArray.eleme
@protocol ScanBeaconsDelegate <NSObject>
@required
- (void) onBeaconDetected: (NSMutableArray <Beacon*> *) detectedBeacons
@end
我不知道如何将detectedBeacons数组强制转换为Beacon对象,我得到一个“无法将序列元素类型'NSArray.element'(也称为'Any')转换为预期类型'Beacon'”
我很迷路,因为这是我第一次接触斯威夫特。有什么办法解决这个问题吗?你可以试试
func onBeaconDetected(_ detectedBeacons: NSMutableArray!) {
for beacon in (detectedBeacons as! [Beacon]) {
//do staff
}
}
这里Beacon是您的模型类??是的,是一个自定义类,但在执行“func onBeaconDetected(uuDetectedBeacons:[Beacon])”时,我得到的不符合协议“ScanBeaconsDelegate”,并且我无法更改静态库代码。如果是这样,请尝试编辑..完美!非常感谢你的帮助
func onBeaconDetected(_ detectedBeacons: NSMutableArray!) {
for beacon: Beacon in detectedBeacons
{
//do staff
}
}
func onBeaconDetected(_ detectedBeacons: NSMutableArray!) {
for beacon in (detectedBeacons as! [Beacon]) {
//do staff
}
}