将ObjC代码转换为iOS Swift

时间:2015-05-28 16:00:30

标签: ios objective-c swift

 if (self.advertisingSwitch.on) {
        // All we advertise is our service's UUID
        [self.peripheralManager startAdvertising:@{ CBAdvertisementDataServiceUUIDsKey : @[[CBUUID UUIDWithString:TRANSFER_SERVICE_UUID]] }];
    }

    else {
        [self.peripheralManager stopAdvertising];
    }

我把它翻译成Swift:

if self.advertisingSwitch.on {

        self.peripheralManager.startAdvertising([CBUUID(string: TRANSFERSERVICEUUID)])

    } else {

        self.peripheralManager.stopAdvertising()
    }

它给了我错误:"无法使用类型的参数列表([CBUUID])"

调用StartAdvertising

1 个答案:

答案 0 :(得分:1)

试试这个

if self.advertisingSwitch.on {
    self.peripheralManager.startAdvertising([CBAdvertisementDataServiceUUIDsKey:[TRANSFER_SERVICE_UUID]])
} else {
    self.peripheralManager.stopAdvertising()
}