Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c Swift无法将CBPeripal类型的值转换为预期的参数类型_Objective C_Swift_Cbperipheral - Fatal编程技术网

Objective c Swift无法将CBPeripal类型的值转换为预期的参数类型

Objective c Swift无法将CBPeripal类型的值转换为预期的参数类型,objective-c,swift,cbperipheral,Objective C,Swift,Cbperipheral,我的守则如下: func didDiscoverBLE(_ peripheral: CBPeripheral!, address: String!, rssi: Int32) { DispatchQueue.main.async(execute: {() -> Void in // Handle Discovery self.arrayPeripehral.contains(where:periphera

我的守则如下:

func didDiscoverBLE(_ peripheral: CBPeripheral!, address: String!, rssi: Int32) {


DispatchQueue.main.async(execute: {() -> Void in

                    // Handle Discovery
                    self.arrayPeripehral.contains(where:peripheral)
                        return
                    })
            self.arrayPeripehral.append(peripheral)
            let title: String = "\(peripheral.name) \(address) (RSSI:\(rssi))"
            self.arrayPeripheralName.append(title)

在这方面,我有一个问题:

self.arrayPeripehral.contains(where:peripheral)
    return
})
有人有主意吗


这是我从ObjectC复制到swift的代码,在这个错误上卡住了

 - (void)didDiscoverBLE:(CBPeripheral *)peripheral address:(NSString *)address rssi:(int)rssi
    {
        dispatch_async(dispatch_get_main_queue(), ^{

            // Handle Discovery
            if([arrayPeripehral containsObject:peripheral])
                return;

            [arrayPeripehral addObject:peripheral];

            NSString * title = [NSString stringWithFormat:@"%@ %@ (RSSI:%d)", peripheral.name, address, rssi];

            [arrayPeripheralName addObject:title];

[Any]
中的
arrayPeripehral
的类型更改为
[cbperipal]
,这将使编译器对其类型有更多的了解,然后像这样使用
contains(其中:)
来检查数组是否包含对象

var arrayPeripehral = [CBPeripheral]()
if self.arrayPeripehral.contains(where: { $0.name == peripheral.name }) {
    return
}
现在用
contains(其中:)
这种方法检查数组是否包含对象

var arrayPeripehral = [CBPeripheral]()
if self.arrayPeripehral.contains(where: { $0.name == peripheral.name }) {
    return
}
同时将
arrayperiperoname
的类型声明从
[Any]
更改为
[String]
,因为您只在其中添加
String
对象

var arrayPeripheralName = [String]()

您能否显示
arrayPeripehral
的声明。var arrayPeripehral=[Any]()var arrayperiperalname=[Any]()我正在使用框架obj c,我有一个briddging文件,我声明了peripheral var peripheral:CBPeripheral?var arrayPeripehral=[Any]()var arrayperipeheralname=[Any]()请编辑您的问题,而不是在评论中添加信息。这是我的代码,但未找到设备。这是我转换为swift的项目3@AlexArshansky您已经要求更正代码,我建议如果您还有任何问题,请在此提出新问题,非常感谢!!!我忘了myApp.myBle.myDiscoverDelegate=self;我看到了设备,但我还没连接上