3 ms·
.color(.gray)) What object is .gray acting on?
by azhenley 7y ago
.color(.gray))
What object is .gray acting on?
- didgeoridoo 7y agoThat syntax is a shortcut for UIColor.gray, so this is really: .color(UIColor.gray)
- JimDabell 7y agoI would expect it's the grey static member of SwiftUI's Color struct: https://developer.apple.com/documentation/swiftui/color/3049710-gray https://developer.apple.com/documentation/swiftui/color/3049...
- kennywinker 7y agoThat’d be standard swift type inference. The .color function takes a single unnammed parameter of type Color (or similar, idk exactly). Color.gray is a static constant value. So .color(Color.gray) can be simplified to .color(.gray)
- steve_adams_86 7y agoHuh, that's actually a great way to do type inference. Swift seems like an excellent language.
- deleted 7y ago[deleted]
- auggierose 7y agothat's shortcut syntax for an enumeration case where the type of the enumeration can be inferred
- favorited 7y agoIt's not just for enums. It works for any static variable on a given type. So you can say .gray and have it map to NSColor.gray, etc.
- kruuuder 7y agoI guess .color() is a method, and .gray is an enum case.
- deleted 7y ago[deleted]