1

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
Sachin Vas
  • 1,757
  • 12
  • 16
Arafin Russell
  • 1,487
  • 1
  • 18
  • 37
  • Can you provide the line of code, or lines, where this error is occurring? – Mike Taverne Mar 27 '19 at 04:38
  • Its an existing app and there are lots of place where its been used. One of them is like this: `let coordinate:String = String(stringInterpolationSegment: self.addSpotAnnotation!.coordinate.latitude) + "," + String(stringInterpolationSegment: self.addSpotAnnotation!.coordinate.longitude)` – Arafin Russell Mar 27 '19 at 04:50
  • 1
    Replace `stringInterpolationSegment` with `stringInterpolation`. – Sachin Vas Mar 27 '19 at 05:17

3 Answers3

2

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)"
Mike Taverne
  • 9,156
  • 2
  • 42
  • 58
1

String Interpolation Updates

Swift 4.2 implements string interpolation by interpolating segments:

let language = "Swift"
let languageSegment = String(stringInterpolationSegment: language)
let space = " "
let spaceSegment = String(stringInterpolationSegment: space)
let version = 4.2
let versionSegment = String(stringInterpolationSegment: version)
let string = String(stringInterpolation: languageSegment, spaceSegment, versionSegment)

In this code, the compiler first wraps each literal segment and then interpolates one with init(stringInterpolationSegment:) . Then, it wraps all segments together with init(stringInterpolation:)

Swift 5 takes a completely different approach

// 1
var interpolation = DefaultStringInterpolation(
literalCapacity: 7,
interpolationCount: 1)
// 2
let language = "Swift"
interpolation.appendLiteral(language)
let space = " "
interpolation.appendLiteral(space)
let version = 5
interpolation.appendInterpolation(version)
// 3
let string = String(stringInterpolation: interpolation)

Here’s what this code does:

Define a DefaultStringInterpolation instance with a certain capacity and interpolation count. Call appendLiteral(:) or appendInterpolation(:) to add literals and interpolated values to interpolation. Produce the final interpolated string by calling init(stringInterpolation:)

credit: raywenderlich

Arafin Russell
  • 1,487
  • 1
  • 18
  • 37
1
public func == <T>(lhs: ResultTest<T>, rhs: ResultTest<T>) -> Bool {
    return  "\(lhs)" == "\(rhs)"
}
Giang
  • 3,553
  • 30
  • 28