indices(where:) Swift Playgrounds Issue: "Cannot call value of non-function type Range<Int>"

Hey there-

I'm having a quite interesting bug on Swift Playgrounds.

I am trying to run my app with this following code snippet which does not compile on Swift Playgrounds, yet compiles on XCode (note: this is a Swift Playground app)


if #available(iOS 18.0, *) {
//simple function to get the indices of other items that have the same date as the "date" variable
            let indices = data!.indices(where: { item in
                let sameMonth = Calendar.current.component(.month, from: item.time) == Calendar.current.component(.month, from: date)
                let sameYear = Calendar.current.component(.year, from: item.time) == Calendar.current.component(.year, from: date)
                let sameDay = Calendar.current.component(.day, from: item.time) == Calendar.current.component(.year, from: date)
                return sameDay && sameMonth && sameYear
            })

However, the indices(where:) codeblock seems to stop the app from compiling (ONLY on Swift Playgrounds - it works perfectly fine on XCode).

I am getting the following error: Cannot call value of non-function type 'Range<Array<Int>.Index>' (aka 'Range<Int>')

Please let me know if you have any insight regarding this issue.

-ColoredOwl

I already reported a similar bug to apple on Jan 9, 2021 – FB8965796. There was never any reaction or fix:

The function Swift.Collection.remove(atOffsets:) is not available in playgrounds

The indices(where:) method was introduced in iOS 18. The current version of Swift Playgrounds, version 4.5.1, includes the iOS 17.5 SDK. That SDK doesn’t include a declaration for that method, and hence this failure.


I already reported a similar bug to apple on Jan 9, 2021 – FB8965796. There was never any reaction or fix:

That’s definitely a different issue. AFAICT your bug was resolved a while back, it’s just that we didn’t communicate the resolution to you. I don’t have a good explanation as to why not )-:

Anyway, the follow code compiles in both Xcode playgrounds (Xcode 16.2) and Swift Playgrounds (4.5.1):

func test() {
    var a = [1]
    a.remove(atOffsets: .init(integer: 0))
}

IMPORTANT The remove(atOffsets:) method is an extension added by SwiftUI, so you have to important that for the code to compile.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

indices(where:) Swift Playgrounds Issue: "Cannot call value of non-function type Range&lt;Int&gt;"
 
 
Q