ios - 无法使用类型 'Range<_>' 的参数列表调用类型 '(Range<String.Index>)' 的初始值设定项

标签 ios swift

我已经引用了通过以下链接提供的许多解决方案,但没有得到这个想法。仍然面临这个问题。请引用图片并帮助我。谢谢!

   subscript (r: Range<Int>) -> String {
        let start = index(startIndex, offsetBy: r.lowerBound)
//        let end = <#T##String.CharacterView corresponding to `start`##String.CharacterView#>.index(start, offsetBy: r.upperBound - r.lowerBound)
        let end = index(start, offsetBy: r.upperBound - r.lowerBound)

        let range: Range<Index> = start..<end

        return String(self[range])
    }

Cannot invoke initializer for type 'Range<String.Index>' with an argument list of type '(Range<String.Index>)'

enter image description here

最佳答案

这就是它的修复方式:

String.swift 是一个带有上面代码补丁的 pod 库。这就是我所做的。

Xcode -> 文件 -> 工作区 -> 构建系统 -> 选择旧版构建系统

编译成功。

enter image description here

谢谢!

关于ios - 无法使用类型 'Range<_>' 的参数列表调用类型 '(Range<String.Index>)' 的初始值设定项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54899417/

相关文章:

ios - NSString 的 Objective-C ARC 和 __weak

ios - 事件指示器未在 TableView 中居中

swift - 将 Swift Set 转换为 NSMutableSet

ios - 使用 iOS 8 自定义键盘发送图像?

ios - NSFetchedResultsController 与更改记录数冲突

ios - iOS 中的 QuickBlox 联机/脱机问题

ios - 有谁知道 Apple iTunes 是否会接受浏览器加载网站的单页应用程序

ios - 无法从钥匙串(keychain)导出身份

ios - 如何防止在暂停场景(取消暂停后)上运行 SKAction,节点纹理在暂停/取消暂停场景后不会改变

ios - 将图像设置为导航栏标题