Using Swift’s ‘some’ keyword beyond SwiftUI 0 ▲ Swift by Sundell 2 hours ago · 6 min read1132 words · Tech · hide · 0 comments Developers who have worked with Apple’s SwiftUI framework have likely encountered the some keyword in the context of defining custom views, where it’s typically used to enable the generic View protocol to be referenced as a type when declaring a view’s body:struct ContentView: View { var body: some View { Text("Hello, world!") .padding() .foregroundStyle(.blue) .font(.headline) } }When using the some keyword, the compiler will infer the underlying concrete type that’s actually being returned, which is especially helpful when working with APIs that heavily utilize generics — such as SwiftUI. Without some, we’d have to always manually specify the concrete type of our entire view hierarchy, which even in the case of the above (very simple) ContentView is as complex as this:ModifiedContent<ModifiedContent<ModifiedContent<Text, _PaddingLayout>, _ForegroundStyleModifier<Color>>, _EnvironmentKeyWritingModifier<Optional<Font>>>But the some keyword isn’t just useful when working with SwiftUI.… No comments yet. Log in to reply on the Fediverse. Comments will appear here.