1

I've just updated to Xcode 10.2 and my formerly compiling extension can't compile anymore:

extension Array where Element == StringProtocol? {
    func joined(by separator: String = " ") -> String {
        return compactMap { $0?.description }.joined(separator: separator)
    }
}

The famous Protocol 'StringProtocol' can only be used as a generic constraint because it has Self or associated type requirements error now shows up...

Someone can tell me what happened? I have not migrated to Swift 5, just opened my project.

I have changed to:

extension Array where Element == CustomStringConvertible?

But I would like to understand why this changed... Any idea?

Zaphod
  • 6,758
  • 3
  • 40
  • 60
  • 2
    `CustomStringConvertible` is completely different than `StringProtocol`, so that change would modify the scope of your conditional extension significantly. Btw you should use `:` when checking protocol conformance, don't use `==`, since `==` should only be used when checking if the type is the same as another type. I cannot test using `Xcode 10.2`, but that change should resolve the issue. – Dávid Pásztor Apr 01 '19 at 15:22
  • I am aware that `CustomStringConvertible` is not the same as `StringProtocol` but for my usage, it works. The remaining problem is that using `:` does not work because I need `Element` to be optional... If I do so I get the `Type 'Element' constrained to non-protocol, non-class type 'StringProtocol?'` (the same with `CustomStringConvertible?`...) – Zaphod Apr 02 '19 at 06:47

0 Answers0