Swifterswift: Cannot subscript a value of type 'String' with an index of type '(safe: Range<Int>)'

Created on 11 Jun 2019  路  9Comments  路  Source: SwifterSwift/SwifterSwift

swift 5.0

SwifterSwift (5.0.0)

        let str = "hello world";
        let str1 = str[safe: 0..<3]

The above code will prompt an error. I will rewrite an extension and write these functions. It is not. Why?

Most helpful comment

Sorry if this is an obvious question, but have you called import SwifterSwift?

All 9 comments

Hello @ningkexin
This code works for me in Xcode 10.2.1 and I also use SwifterSwift 5.0.0. What Xcode version are you using?

Hey @ningkexin @RomanPodymov :))
@ningkexin Can you elaborate more on what error it is giving you, so we can check?

@RomanPodymov I also use Version 10.2.1 (10E1001)

@LucianoPAlmeida I don't know why this is causing the problem, but I can probably provide my usage environment. I am using it under the old project (Objective-C). In addition, I used swift4.2 before. I didn't use this POD at first. I just tried the extension of String, which didn't cause any problems during the use. Then I tried the swift5.0 version yesterday, and this problem has appeared!

image

Xcode also indexes two definitions, but I commented out that my extension is not compiled.

This duplication is probably because Xcode didn鈥檛 reindexed after you comment. But my question is more about the error message. What the error log the compiler is outputting?

Sent with GitHawk

@LucianoPAlmeida

  • Please see the error message below. I have already "Clean Build Folder" before this.
    image

Sorry if this is an obvious question, but have you called import SwifterSwift?

Oh, it鈥檚 stupid, I solved my problem!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fanglinwei picture fanglinwei  路  3Comments

AYastrebov picture AYastrebov  路  3Comments

SD10 picture SD10  路  3Comments

fanglinwei picture fanglinwei  路  5Comments

omaralbeik picture omaralbeik  路  3Comments