1
0
mirror of https://github.com/adambard/learnxinyminutes-docs.git synced 2025-08-20 21:42:14 +02:00

Merge pull request #942 from geoffliu/master

[swift/pt-br] Remove an extra comma
This commit is contained in:
ven
2015-01-28 23:40:44 +01:00

View File

@@ -1,7 +1,7 @@
--- ---
language: swift language: swift
contributors: contributors:
- ["Grant Timmerman", "http://github.com/grant"], - ["Grant Timmerman", "http://github.com/grant"]
- ["Christopher Bess", "http://github.com/cbess"] - ["Christopher Bess", "http://github.com/cbess"]
translators: translators:
- ["Mariane Siqueira Machado", "https://twitter.com/mariane_sm"] - ["Mariane Siqueira Machado", "https://twitter.com/mariane_sm"]
@@ -9,7 +9,7 @@ lang: pt-br
filename: learnswift.swift filename: learnswift.swift
--- ---
Swift é uma linguagem de programação para desenvolvimento de aplicações no iOS e OS X criada pela Apple. Criada para Swift é uma linguagem de programação para desenvolvimento de aplicações no iOS e OS X criada pela Apple. Criada para
coexistir com Objective-C e para ser mais resiliente a código com erros, Swift foi apresentada em 2014 na Apple's coexistir com Objective-C e para ser mais resiliente a código com erros, Swift foi apresentada em 2014 na Apple's
developer conference WWDC. Foi construída com o compilador LLVM já incluído no Xcode 6 beta. developer conference WWDC. Foi construída com o compilador LLVM já incluído no Xcode 6 beta.
@@ -59,9 +59,9 @@ let piText = "Pi = \(π), Pi 2 = \(π * 2)" // Interpolação de strings
println("Build value: \(buildValue)") // Build value: 7 println("Build value: \(buildValue)") // Build value: 7
/* /*
Optionals fazem parte da linguagem e permitem que você armazene um Optionals fazem parte da linguagem e permitem que você armazene um
valor `Some` (algo) ou `None` (nada). valor `Some` (algo) ou `None` (nada).
Como Swift requer que todas as propriedades tenham valores, até mesmo nil deve Como Swift requer que todas as propriedades tenham valores, até mesmo nil deve
ser explicitamente armazenado como um valor Optional. ser explicitamente armazenado como um valor Optional.
@@ -76,7 +76,7 @@ if someOptionalString != nil {
if someOptionalString!.hasPrefix("opt") { if someOptionalString!.hasPrefix("opt") {
println("has the prefix") println("has the prefix")
} }
let empty = someOptionalString?.isEmpty let empty = someOptionalString?.isEmpty
} }
someOptionalString = nil someOptionalString = nil
@@ -289,7 +289,7 @@ print(numbers) // [3, 6, 18]
// Estruturas e classes tem funcionalidades muito similares // Estruturas e classes tem funcionalidades muito similares
struct NamesTable { struct NamesTable {
let names: [String] let names: [String]
// Custom subscript // Custom subscript
subscript(index: Int) -> String { subscript(index: Int) -> String {
return names[index] return names[index]
@@ -319,7 +319,7 @@ public class Shape {
internal class Rect: Shape { internal class Rect: Shape {
var sideLength: Int = 1 var sideLength: Int = 1
// Getter e setter personalizado // Getter e setter personalizado
private var perimeter: Int { private var perimeter: Int {
get { get {
@@ -330,13 +330,13 @@ internal class Rect: Shape {
sideLength = newValue / 4 sideLength = newValue / 4
} }
} }
// Carregue uma propriedade sob demanda (lazy) // Carregue uma propriedade sob demanda (lazy)
// subShape permanece nil (não inicializado) até seu getter ser chamado // subShape permanece nil (não inicializado) até seu getter ser chamado
lazy var subShape = Rect(sideLength: 4) lazy var subShape = Rect(sideLength: 4)
// Se você não precisa de um getter e setter personalizado, // Se você não precisa de um getter e setter personalizado,
// mas ainda quer roda código antes e depois de configurar // mas ainda quer roda código antes e depois de configurar
// uma propriedade, você pode usar `willSet` e `didSet` // uma propriedade, você pode usar `willSet` e `didSet`
var identifier: String = "defaultID" { var identifier: String = "defaultID" {
// o argumento `willSet` será o nome da variável para o novo valor // o argumento `willSet` será o nome da variável para o novo valor
@@ -344,25 +344,25 @@ internal class Rect: Shape {
print(someIdentifier) print(someIdentifier)
} }
} }
init(sideLength: Int) { init(sideLength: Int) {
self.sideLength = sideLength self.sideLength = sideLength
// sempre chame super.init por último quand inicializar propriedades personalizadas (custom) // sempre chame super.init por último quand inicializar propriedades personalizadas (custom)
super.init() super.init()
} }
func shrink() { func shrink() {
if sideLength > 0 { if sideLength > 0 {
--sideLength --sideLength
} }
} }
override func getArea() -> Int { override func getArea() -> Int {
return sideLength * sideLength return sideLength * sideLength
} }
} }
// Uma classe básica `Square` que estende `Rect` // Uma classe básica `Square` que estende `Rect`
class Square: Rect { class Square: Rect {
convenience init() { convenience init() {
self.init(sideLength: 5) self.init(sideLength: 5)
@@ -420,10 +420,10 @@ protocol ShapeGenerator {
class MyShape: Rect { class MyShape: Rect {
var delegate: TransformShape? var delegate: TransformShape?
func grow() { func grow() {
sideLength += 2 sideLength += 2
if let allow = self.delegate?.canReshape?() { if let allow = self.delegate?.canReshape?() {
// test for delegate then for method // test for delegate then for method
// testa por delegação e então por método // testa por delegação e então por método
@@ -439,7 +439,7 @@ class MyShape: Rect {
// `extension`s: Adicionam uma funcionalidade extra para um tipo já existente. // `extension`s: Adicionam uma funcionalidade extra para um tipo já existente.
// Square agora "segue" o protocolo `Printable` // Square agora "segue" o protocolo `Printable`
extension Square: Printable { extension Square: Printable {
var description: String { var description: String {
return "Area: \(self.getArea()) - ID: \(self.identifier)" return "Area: \(self.getArea()) - ID: \(self.identifier)"
@@ -453,7 +453,7 @@ extension Int {
var customProperty: String { var customProperty: String {
return "This is \(self)" return "This is \(self)"
} }
func multiplyBy(num: Int) -> Int { func multiplyBy(num: Int) -> Int {
return num * self return num * self
} }