Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Library compile error on Data.swift #295

Closed
macellari-mac opened this issue Apr 17, 2019 · 2 comments
Closed

Library compile error on Data.swift #295

macellari-mac opened this issue Apr 17, 2019 · 2 comments
Assignees
Labels
Milestone

Comments

@macellari-mac
Copy link

I'm trying to test the library but I'm facing a compile error on file Data.swift

Line 36:
$0.baseAddress!.bindMemory(to: R.self, capacity: 1).pointee
Error: /Users/luciomacellari/Projects/dfuDemo/Pods/iOSDFULibrary/iOSDFULibrary/Classes/Utilities/Data.swift:36:13: Value of type 'UnsafePointer<_>' has no member 'baseAddress'

Line 50:
array.append(contentsOf: $0)
Error:
/Users/luciomacellari/Projects/dfuDemo/Pods/iOSDFULibrary/iOSDFULibrary/Classes/Utilities/Data.swift:50:25: Extraneous argument label 'contentsOf:' in call

I'm compiling with Xcode 10.1

@KeerthiChinivar
Copy link

KeerthiChinivar commented Apr 18, 2019

For First issue replace

return subdata(in: offset ..< offset + length).withUnsafeBytes {
    $0.baseAddress!.bindMemory(to: R.self, capacity: 1).pointee
 }

with

 #if swift(>=5.0)
    return subdata(in: offset ..< offset + length).withUnsafeBytes { $0.load(as: T.self) }
 #else
    return subdata(in: offset ..< offset + length).withUnsafeBytes { $0.pointee }
 #endif

For Second issue solution is:

var hexString: String {
    var array: [UInt8] = []
    self.withUnsafeBytes {
        array.append(contentsOf: getByteArray(pointer: $0))
    }
        
    return array.reduce("") { (result, byte) -> String in
        result + String(format: "%02x", byte)
    }
}
    
private func getByteArray(pointer: UnsafePointer<UInt8>) -> [UInt8] {
    let buffer = UnsafeBufferPointer<UInt8>(start: pointer, count: count)
        
    return [UInt8](buffer)
}

@philips77
Copy link
Member

I will fix it in 4.4.2. @KeerthiChinivar thanks for your reply!

@philips77 philips77 added this to the 4.4.2 milestone Apr 23, 2019
@philips77 philips77 added the bug label Apr 23, 2019
@philips77 philips77 self-assigned this Apr 23, 2019
philips77 added a commit that referenced this issue Apr 23, 2019
philips77 added a commit that referenced this issue Apr 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants