Boilertalk / Web3.swift

A pure swift Ethereum Web3 library
MIT License
639 stars 188 forks source link

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

Closed blau2 closed 1 year ago

blau2 commented 6 years ago

/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 commented 6 years ago

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.

koraykoska commented 5 years ago

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?

pixelmatrix commented 5 years ago

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 commented 5 years ago

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

koraykoska commented 5 years ago

@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?

darwinharianto commented 5 years ago

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

pixelmatrix commented 5 years ago

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 notifications@github.com 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 commented 5 years ago

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.

darwinharianto commented 5 years ago

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
pixelmatrix commented 5 years ago
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!

darwinharianto commented 5 years ago

it works, thanks

blau2 commented 5 years ago

@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