Search code examples
iosswiftswiftdate

SwiftDate 5.0 compilation issues


When I install SwiftDate through Cocoapods and try to build my project, I get three errors from the SwiftDate library:

/Pods/SwiftDate/Sources/SwiftDate/DateInRegion/DateInRegion.swift:11:15: Type 'DateInRegion' does not conform to protocol 'Hashable'

/Pods/SwiftDate/Sources/SwiftDate/DateInRegion/DateInRegion+Create.swift:50:33: Type 'UInt32' has no member 'random'

/Pods/SwiftDate/Sources/SwiftDate/DateInRegion/DateInRegion+Create.swift:65:37: Type 'UInt32' has no member 'random'

Am I using an incorrect version of SwiftDate, Swift, or XCode? When I try to install SwiftDate 4.5.1, I get no errors in the library but none of the SwiftDate functions actually work.


Solution

  • Since versions 5.0.0+ of SwiftDate include code from Swift 4.2, you have to have installed Xcode which supports this version of Swift (Xcode 10+).

    Otherwise you can use the latest version of SwiftDate which doesn't use code from Swift 4.2 such as getting random number easily (SwiftDate 4.5.0) by specifing the version of cocoapod in podfile

    pod 'SwiftDate', '4.5.0'