Date post: | 07-Aug-2015 |
Category: |
Technology |
Upload: | jose-manuel-navarro |
View: | 33 times |
Download: | 0 times |
Introducción a Swift
Presentado en Junio 2014 como una de las grandes revoluciones de iOS 8
Intenta facilitar la curva de aprendizaje de Objective-C (difícil) a la vez que introduce características modernas al lenguaje
Introducción a Swift
El runtime es compartido con Objective-
C, lo que permite que sean 100%
interoperables
Un app puede estar escrita en cualquier
combinación de Objective-C y Swift
Introducción a Swift
Swift es un lenguaje orientado a objetos, pero no es estricto.
También incluye características de lenguajes funcionales: funciones de primer orden, inmutabilidad, pattern matching, etc.
Introducción a Swift
Soporta inferencia de tipos, para evitar definir los mismos tipos una y otra vez
Utiliza ARC internamente para la gestión de memoria, aunque la mayoría de las veces es transparente al programador
It was the invention of the null reference in 1965. At that time, I was designing the first comprehensive type system for references in an object oriented language (ALGOL W). My goal was to ensure that all use of references should be absolutely safe, with checking performed automatically by the compiler. But I couldn't resist the temptation to put in a null reference, simply because it was so easy to implement.
The billion dollar mistake
Swift 2
Cambios importantes en el lenguaje
Sin compatibilidad hacia atrás
Cambios enfocados a mayor seguridad
del código
Guard Swift 1.x
let name: String? = computeName()
if name == nil {
return nil
}
let nick: String? = computeNick()
if nick == nil {
return nil
}
processUser(name!, nick!)
Guard Swift 2
guard let name: String? = computeName()
else {
return nil
}
guard let nick: String? = computeNick()
else {
return nil
}
processUser(name, nick)
Throws Swift 1.x
func process(a: Int, inout error: NSErrorPointer) -> Int { ... error = NSError(...)
} var error: NSError? = nil process(1, &error)
Throws Swift 2
func process(a: Int) throws -> Int
... throw NSError(...) }
do {
try process(1)
} catch { } try! process(1)
Defer Swift 1.x
let name: String? = computeName()
if name == nil { makeSomething() return nil
}
let nick: String? = computeNick()
if nick == nil {
makeSomething() return nil
}
processUser(name!, nick!)