Hi there, I'm Marcos!


RoundedRectangle in SwiftUI

If a function you need to execute might throw but you don’t care about it you can execute it with try?:

func getValue() throws -> String {
    throw Error("Something went wrong")

// ...

try? getValue()

In this case the returned value will be nil which can also be replaced with the nil-coalescing operator:

let value = (try? getValue()) ?? "default value"

Note the parenthesis around the try? statement, otherwise it won’t work.