titletextattributes color bar ios swift swift3

ios - color - Manejo de intentos y lanzamientos en Swift 3



uinavigationitem title color (1)

Antes de Swift 3 estaba usando:

guard let data = Data(contentsOf: url) else { print("There was an error!) return }

Sin embargo, ahora tengo que usar do , try y catch . No estoy familiarizado con esta sintaxis. ¿Cómo replicaría este comportamiento?


La diferencia aquí es que Data(contentsOf: url) ya no devuelve un Opcional, arroja.

Entonces puedes usarlo en Do-Catch pero sin guard :

do { let data = try Data(contentsOf: url) // do something with data // if the call fails, the catch block is executed } catch { print(error.localizedDescription) }

Tenga en cuenta que todavía puede usar guard con try? en lugar de try pero luego se ignora el mensaje de error posible. En este caso, no necesita un bloque Do-Catch:

guard let data = try? Data(contentsOf: url) else { print("There was an error!") // return or break } // do something with data