SwiftCBOR icon indicating copy to clipboard operation
SwiftCBOR copied to clipboard

iOS 16.1 UnsafeRawPointer is depreciated and decodeItem returns nil value

Open sayler8182 opened this issue 3 years ago • 2 comments

UnsafeRawPointer is depreciated:

note: use the 'withUnsafeBytes' method on Array in order to explicitly convert argument to buffer pointer valid for a defined scope

and on iOS 16.1 devices readUInt returns incorrect value

private func readUInt<T: UnsignedInteger>(_ n: Int) throws -> T {
        return UnsafeRawPointer(Array(try istream.popBytes(n).reversed())).load(as: T.self)
}

Solution: It could be potentially refactored by:

private func readUInt<T: UnsignedInteger>(_ n: Int) throws -> T {
        let array = Array(try istream.popBytes(n).reversed())
        return array.withUnsafeBytes { $0.load(as: T.self) }
}

Notice: Probably all UnsafeRawPointer( occurrence should be replaced by .withUnsafeBytes method call

sayler8182 avatar Oct 25 '22 09:10 sayler8182

Hm.. is it possible that https://cocoapods.org/pods/CBOR is not up to date ?

sayler8182 avatar Oct 25 '22 10:10 sayler8182

Issue probably can be rejected. https://cocoapods.org/pods/CBOR and https://cocoapods.org/pods/SwiftCBOR have the same link to GitHub repository, but I don't see any information that CBOR pods is depreciated and renamed into SwiftCBOR

sayler8182 avatar Oct 25 '22 10:10 sayler8182

I'm not sure about the renaming but I don't see any current usage of UnsafeRawPointer in the current codebase, so I'm going to close the issue 👍

hamchapman avatar Nov 02 '22 16:11 hamchapman