swiftxcode10.2

Argument labels '(stringInterpolationSegment:)' do not match any available overloads


After updating the latest Xcode Version 10.2 (10E125), I am getting this error :

Argument labels '(stringInterpolationSegment:)' do not match any available overloads

Could not find any solution yet, any idea please ?

let interpolation1 = String(stringInterpolationSegment:self.addSpotAnnotation!.coordinate.latitude)
let interpolation2 = String(stringInterpolationSegment:self.addSpotAnnotation!.coordinate.longitude)
let coordinate:String = interpolation1 + "," + interpolation2

Solution

  • The error is due to changes to how string interpolation works in Swift 5.

    The solution is not to replace String(stringInterpolationSegment:) with String(stringInterpolation:):

    We do not propose preserving existing init(stringInterpolation:) or init(stringInterpolationSegment:) initializers, since they have always been documented as calls that should not be used directly. [emphasis added]

    The example you gave:

    coordinate:String = 
          String(stringInterpolationSegment: self.addSpotAnnotation!.coordinate.latitude) 
        + "," 
        + String(stringInterpolationSegment: self.addSpotAnnotation!.coordinate.longitude)
    

    can much more easily be written as:

    let coordinate = "\(self.addSpotAnnotation!.coordinate.latitude),\(self.addSpotAnnotation!.coordinate.longitude)"