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

Swift 4 upgrade #4

Closed
vaggos666 opened this issue Oct 27, 2017 · 4 comments
Closed

Swift 4 upgrade #4

vaggos666 opened this issue Oct 27, 2017 · 4 comments

Comments

@vaggos666
Copy link

Swift 4 reports: Static let 'nativeByteOrder' is internal and cannot be referenced from a default argument value.

Any workaround?

@michaeldorner
Copy link
Owner

Thanks for pointing out! I will have a look today.

@vaggos666
Copy link
Author

Great. My temporary workaround was the following. In case it helps.

Added an extra case .notspecified and then in the functions added and extra control.

public enum ByteOrder {
case bigEndian
case littleEndian
case notSpecified
/// Machine specific byte order
static let nativeByteOrder: ByteOrder = (Int(CFByteOrderGetCurrent()) == Int(CFByteOrderLittleEndian.rawValue)) ? .littleEndian : .bigEndian
}

open class func unpack<T: Any>(_ valueByteArray: [Byte], byte_Order: ByteOrder = .notSpecified) -> T {
//assert(!(type(of: T.self) is AnyObject), referenceTypeErrorString) // does not work in Swift 3

    **let byteOrder: ByteOrder = (byte_Order == .notSpecified) ? .nativeByteOrder : byte_Order**
    
    let bytes = (byteOrder == .littleEndian) ? valueByteArray : valueByteArray.reversed()
    return bytes.withUnsafeBufferPointer {
        return $0.baseAddress!.withMemoryRebound(to: T.self, capacity: 1) {
            $0.pointee
        }
    }
}

@michaeldorner
Copy link
Owner

I think it is a bug in Swift 4.

@michaeldorner
Copy link
Owner

michaeldorner commented Oct 27, 2017

And fixed it with version 1.2. :)
I just made it public.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants