swift - 参数标签 '(stringInterpolationSegment:)' 不匹配任何可用的重载

标签 swift xcode10.2

更新最新的 Xcode 版本 10.2 (10E125) 后,出现此错误:

参数标签“(stringInterpolationSegment:)”不匹配任何可用的重载

还没有找到任何解决方案,有什么想法吗?

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

最佳答案

错误是由于changes了解字符串插值在 Swift 5 中的工作原理。

解决方案是String(stringInterpolationSegment:)替换为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]

你举的例子:

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

可以更容易地写成:

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

关于swift - 参数标签 '(stringInterpolationSegment:)' 不匹配任何可用的重载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55369435/

相关文章:

ios - IOS 13.2.3版本TextField文本不显示如何解决?

php - 如何管理团队在其他表的字段 id_team 中更新 ID、用户名

iOS - 禁用答案但保留 Crashlytics

ios - 如何使用 swift 在应用程序中调用一次计时器?

swift - AKMIDI监听器 : ReceivedNoteOn unable to change UI Components

ios - 无法从 Objective-C 通用框架引用 Swift 通用框架的类和方法

xcode - 如何修复 Xcode 10.2 中的 "SWIFT_VERSION ' 3. 0' is unsupported, supported versions are: 4.0, 4.2, 5.0"错误?

ios - build设置的搜索路径中缺少框架搜索路径

xcode - 找不到选项的目录 - 升级 Swift 2.0

ios - UITableViewController : Update cell from DOWNLOADING to DONE