\.self key path

So I'm basically struggling with understanding of why this not working. As I understood from this thread this code

let users = [User]()
users.map(\.name)

Translates right too

users.map { $0[keyPath: \.name] }

But this code not working

users.map(\.self)

While this code is perfectly fine

users.map { $0[keyPath: \.self] }

That seems like a bug: the proposal itself shows [1, nil, 3, nil, 5].compactMap(\.self) as an example of a supported self key path.

1 Like

Yep, for me it's also looks like a bug :upside_down_face:

I reported both of these bugs awhile back if you want to follow them:

https://bugs.swift.org/browse/SR-12387
https://bugs.swift.org/browse/SR-13999

2 Likes

Duplicate?

https://bugs.swift.org/browse/SR-12897

Oh, didn't see that, thanks!

Looks like that

Terms of Service

Privacy Policy

Cookie Policy