gpt4 book ai didi

swift - 参数标签错误

转载 作者:行者123 更新时间:2023-11-30 12:32:09 27 4
gpt4 key购买 nike

转换为 Swift 后获取参数标签错误:
参数标签“(bytes:, length:)”与任何可用的重载都不匹配

关于有效负载分配:
让有效负载=数据(字节:字节,长度:长度)

        if characteristic.uuid.isEqual(CBUUID(string: TRANSFER_CHARACTERISTIC_UUID)) {
print("Writing to characteristic \(characteristic)")
let zpl: String = "^XA^FO50,50^ADN,36,20^FDHELLO WORLD^FS^XZ"
let bytes = zpl.utf8
let length: size_t = (zpl.characters.count ?? 0)

let payload = Data(bytes: bytes, length: length)
print("Writing payload: \(payload) length of \(length)")
//peripheral.writeValue(payload, forCharacteristic: characteristic, type: CBCharacteristicWriteWithResponse)
peripheral.writeValue(payload, for: characteristic, type: CBCharacteristicWriteType)
}

以及以下内容:

textview.text = String(数据, 编码: String.Encoding.utf8)

    if (stringFromData == "EOM") {
// We have, so show the data,
textview.text = String(data, encoding: String.Encoding.utf8)
// Cancel our subscription to the characteristic
peripheral.setNotifyValue(false, for: characteristic)
// and disconnect from the peripehral
centralManager?.cancelPeripheralConnection(peripheral)
}

建议?

最佳答案

如果您查看文档或在 Xcode 中使用自动完成功能,您将找到该方法的 bytes:count: 版本。也许你想要这样的东西:

let zpl: String = "^XA^FO50,50^ADN,36,20^FDHELLO WORLD^FS^XZ"
var bytes = zpl.utf8

let payload = Data(bytes: &bytes, count: zpl.characters.count)

关于swift - 参数标签错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43393623/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com