Web3.swift icon indicating copy to clipboard operation
Web3.swift copied to clipboard

Compiler error with Xcode 10 GM: Type 'Data' does not conform to protocol 'BytesInitializable'

Open blau2 opened this issue 6 years ago • 12 comments

/Pods/Web3/Web3/Classes/Core/Toolbox/Data+BytesConvertible.swift:10:1: Unavailable initializer 'init(bytes:)' was used to satisfy a requirement of protocol 'BytesInitializable'

blau2 avatar Sep 13 '18 18:09 blau2

I believe that Data no longer conforms to BytesInitializable because BytesInitializable requires a throwable initializer init(bytes: Bytes) throws, however the Data initializer init<S>(bytes elements: S) where S : Sequence, S.Element == UInt8 does not throw.

blau2 avatar Sep 13 '18 19:09 blau2

Really? Is this required in the new version of Swift? Actually omitting the throws declaration was always possible in Swift as the "postcondition" is only strengthened if done so. E.g. trying a non throwing function is not an issue, but not trying a throwing function would be.

If they really changed this behaviour, we would have to add our own throwing functions to all types conforming to BytesInitializable as most of them don't throw right now.

@blau2 Do you have resources about this change so we can be certain before moving on?

@pixelmatrix Did you know of this change?

koraykoska avatar Sep 16 '18 15:09 koraykoska

Hmm, it sounds like maybe they made this change because now they have better guarantees with conditional conformance. Maybe BytesInitializable should do the same?

pixelmatrix avatar Sep 17 '18 02:09 pixelmatrix

https://github.com/apple/swift/pull/18443

pixelmatrix avatar Sep 17 '18 02:09 pixelmatrix

@pixelmatrix Oh I missed that. It seems like the generic version of the initializer isn't compatible with our signature. You are right, we should definitely change that for Swift 4.2. Maybe together with a general refactoring to make use of the newly added conditional conformance features?

koraykoska avatar Sep 18 '18 10:09 koraykoska

I am still having the same issue. How to deal with this issue?

darwinharianto avatar Nov 02 '18 08:11 darwinharianto

Hmm, you should be able to build this SDK against Swift 4.0 and it should be fine. Might need to set this in the Podspec. I can look into this, but for the meantime maybe just try changing the swift version for just this framework to 4.0 or 4.1.

On Nov 2, 2018, at 1:26 AM, darwinharianto [email protected] wrote:

I am still having the same issue. How to deal with this issue?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

pixelmatrix avatar Nov 02 '18 14:11 pixelmatrix

Confirmed locally that changing the swift version under Build Settings on the Web3 framework to Swift 4 allows it to be built for an app running Swift 4.2. That should allow you to at least use this library for now, but we should also add swift_version to the Podspec.

pixelmatrix avatar Nov 02 '18 17:11 pixelmatrix

I'm sorry, I'm new to swift. I tried to change the version to 4, but it still says error. I installed it using cocoa pods screen shot 2018-11-05 at 9 43 55

darwinharianto avatar Nov 05 '18 00:11 darwinharianto

image

Hey @darwinharianto I submitted a PR to fix the issue, but this is the setting you need to change. It looks like you've changed the swift version for the Pods project, or for your app's project, but you actually have to select the Web3 framework within the Pods project and change the build setting in there. Hope that helps!

pixelmatrix avatar Nov 05 '18 00:11 pixelmatrix

it works, thanks

darwinharianto avatar Nov 05 '18 01:11 darwinharianto

@darwinharianto Alternatively, you can add a post_install script to your Podfile as follows (otherwise performing a pod install will reset the Swift version back to 4.2):

post_install do |installer|
  # Downgrade Swift language version to 4.0 for Pods that don't support Swift 4.2
  installer.pods_project.targets.each do |target|
    if ['RxSwift', 'Web3'].include? target.name
      target.build_configurations.each do |config|
        config.build_settings['SWIFT_VERSION'] = '4.0'
      end
    end
  end
end

blau2 avatar Nov 16 '18 00:11 blau2