From 3fa59915d0e30b5b0f08bea5e1a62b73f4250ebb Mon Sep 17 00:00:00 2001 From: yelite Date: Sun, 18 Jan 2015 16:06:48 +0800 Subject: Update swift.html.markdown --- swift.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'swift.html.markdown') diff --git a/swift.html.markdown b/swift.html.markdown index 0d1d2df4..2fbbe544 100644 --- a/swift.html.markdown +++ b/swift.html.markdown @@ -481,7 +481,7 @@ extension Int { } println(7.customProperty) // "This is 7" -println(14.multiplyBy(2)) // 42 +println(14.multiplyBy(3)) // 42 // Generics: Similar to Java and C#. Use the `where` keyword to specify the // requirements of the generics. -- cgit v1.2.3 From 7a55b4a9b1badebd4b9342304c902fde049dd172 Mon Sep 17 00:00:00 2001 From: Keito Uchiyama Date: Tue, 20 Jan 2015 14:52:31 -0800 Subject: Explain Optional Chaining Without going into too much detail, mention optional chaining so it's not confusing that there is a question mark suffix (it's not currently mentioned anywhere on the page). --- swift.html.markdown | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'swift.html.markdown') diff --git a/swift.html.markdown b/swift.html.markdown index 2fbbe544..c6d2a8af 100644 --- a/swift.html.markdown +++ b/swift.html.markdown @@ -445,7 +445,10 @@ class MyShape: Rect { func grow() { sideLength += 2 - + + // Place a question mark after an optional property, method, or + // subscript to gracefully ignore a nil value and return nil + // instead of throwing a runtime error ("optional chaining"). if let allow = self.delegate?.canReshape?() { // test for delegate then for method self.delegate?.reshaped?() -- cgit v1.2.3 From f74fd2657a6233702a46926ec79d87e46b4fa65f Mon Sep 17 00:00:00 2001 From: TheDmitry Date: Wed, 28 Jan 2015 11:24:31 +0300 Subject: [swift/en,cn,ru]Updating the getting started guide weblink. --- swift.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'swift.html.markdown') diff --git a/swift.html.markdown b/swift.html.markdown index c6d2a8af..0977efc4 100644 --- a/swift.html.markdown +++ b/swift.html.markdown @@ -10,7 +10,7 @@ Swift is a programming language for iOS and OS X development created by Apple. D The official [Swift Programming Language](https://itunes.apple.com/us/book/swift-programming-language/id881256329) book from Apple is now available via iBooks. -See also Apple's [getting started guide](https://developer.apple.com/library/prerelease/ios/referencelibrary/GettingStarted/LandingPage/index.html), which has a complete tutorial on Swift. +See also Apple's [getting started guide](https://developer.apple.com/library/prerelease/ios/referencelibrary/GettingStarted/RoadMapiOS/index.html), which has a complete tutorial on Swift. ```swift // import a module -- cgit v1.2.3 From b178ac30776698409f6a5e8f3d9f7baf611091b6 Mon Sep 17 00:00:00 2001 From: Joey Huang Date: Sat, 28 Feb 2015 19:28:34 +0800 Subject: add optional init and enum with associated values --- swift.html.markdown | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'swift.html.markdown') diff --git a/swift.html.markdown b/swift.html.markdown index 0977efc4..ffc57e69 100644 --- a/swift.html.markdown +++ b/swift.html.markdown @@ -3,6 +3,7 @@ language: swift contributors: - ["Grant Timmerman", "http://github.com/grant"] - ["Christopher Bess", "http://github.com/cbess"] + - ["Joey Huang", "http://github.com/kamidox"] filename: learnswift.swift --- @@ -388,6 +389,35 @@ if mySquare === mySquare { println("Yep, it's mySquare") } +// Optional init +class Circle: Shape { + var radius: Int + override func getArea() -> Int { + return 3 * radius * radius + } + + // Place a question mark postfix after `init` is an optional init + // which can return nil + init?(radius: Int) { + self.radius = radius + super.init() + + if radius <= 0 { + return nil + } + } +} + +var myCircle = Circle(radius: 1) +println(myCircle?.getArea()) // Optional(3) +println(myCircle!.getArea()) // 3 +var myEmptyCircle = Circle(radius: -1) +println(myEmptyCircle?.getArea()) // "nil" +if let circle = myEmptyCircle { + // will not execute since myEmptyCircle is nil + println("circle is not nil") +} + // // MARK: Enums @@ -419,6 +449,28 @@ enum BookName: String { } println("Name: \(BookName.John.rawValue)") +// Enum with associated Values +enum Furniture { + // Associate with Int + case Desk(height: Int) + // Associate with String and Int + case Chair(String, Int) + + func description() -> String { + switch self { + case .Desk(let height): + return "Desk with \(height) cm" + case .Chair(let brand, let height): + return "Chair of \(brand) with \(height) cm" + } + } +} + +var desk: Furniture = .Desk(height: 80) +println(desk.description()) // "Desk with 80 cm" +var chair = Furniture.Chair("Foo", 40) +println(chair.description()) // "Chair of Foo with 40 cm" + // // MARK: Protocols -- cgit v1.2.3 From c4558c47eaf08d7a1d22789f1b0a38c23260fd18 Mon Sep 17 00:00:00 2001 From: Anthony Nguyen Date: Mon, 3 Aug 2015 23:05:22 -0400 Subject: Println deprecated in Swift 2 --- swift.html.markdown | 56 +++++++++++++++++++++++++++-------------------------- 1 file changed, 29 insertions(+), 27 deletions(-) (limited to 'swift.html.markdown') diff --git a/swift.html.markdown b/swift.html.markdown index ffc57e69..8e83a0b3 100644 --- a/swift.html.markdown +++ b/swift.html.markdown @@ -26,7 +26,9 @@ import UIKit // TODO: Do something soon // FIXME: Fix this code -println("Hello, world") +// In Swift 2, println and print were combined into one print method. +print("Hello, world") // standard print +print("Hello, world", appendNewLine: true) // appending a new line // variables (var) value can change after being set // constants (let) value can NOT be changed after being set @@ -46,12 +48,12 @@ let piText = "Pi = \(π), Pi 2 = \(π * 2)" // String interpolation // Build Specific values // uses -D build configuration #if false - println("Not printed") + print("Not printed") let buildValue = 3 #else let buildValue = 7 #endif -println("Build value: \(buildValue)") // Build value: 7 +print("Build value: \(buildValue)") // Build value: 7 /* Optionals are a Swift language feature that allows you to store a `Some` or @@ -69,7 +71,7 @@ var someOptionalString2: Optional = "optional" if someOptionalString != nil { // I am not nil if someOptionalString!.hasPrefix("opt") { - println("has the prefix") + print("has the prefix") } let empty = someOptionalString?.isEmpty @@ -138,21 +140,21 @@ var emptyMutableDictionary = [String: Float]() // var == mutable let myArray = [1, 1, 2, 3, 5] for value in myArray { if value == 1 { - println("One!") + print("One!") } else { - println("Not one!") + print("Not one!") } } // for loop (dictionary) var dict = ["one": 1, "two": 2] for (key, value) in dict { - println("\(key): \(value)") + print("\(key): \(value)") } // for loop (range) for i in -1...shoppingList.count { - println(i) + print(i) } shoppingList[1...2] = ["steak", "peacons"] // use ..< to exclude the last number @@ -165,7 +167,7 @@ while i < 1000 { // do-while loop do { - println("hello") + print("hello") } while 1 == 2 // Switch @@ -222,8 +224,8 @@ let pricesTuple = getGasPrices() let price = pricesTuple.2 // 3.79 // Ignore Tuple (or other) values by using _ (underscore) let (_, price1, _) = pricesTuple // price1 == 3.69 -println(price1 == pricesTuple.1) // true -println("Gas price: \(price)") +print(price1 == pricesTuple.1) // true +print("Gas price: \(price)") // Variadic Args func setup(numbers: Int...) { @@ -251,7 +253,7 @@ func swapTwoInts(inout a: Int, inout b: Int) { var someIntA = 7 var someIntB = 3 swapTwoInts(&someIntA, &someIntB) -println(someIntB) // 7 +print(someIntB) // 7 // @@ -305,7 +307,7 @@ struct NamesTable { // Structures have an auto-generated (implicit) designated initializer let namesTable = NamesTable(names: ["Me", "Them"]) let name = namesTable[1] -println("Name is \(name)") // Name is Them +print("Name is \(name)") // Name is Them // // MARK: Classes @@ -386,7 +388,7 @@ let aShape = mySquare as Shape // compare instances, not the same as == which compares objects (equal to) if mySquare === mySquare { - println("Yep, it's mySquare") + print("Yep, it's mySquare") } // Optional init @@ -409,13 +411,13 @@ class Circle: Shape { } var myCircle = Circle(radius: 1) -println(myCircle?.getArea()) // Optional(3) -println(myCircle!.getArea()) // 3 +print(myCircle?.getArea()) // Optional(3) +print(myCircle!.getArea()) // 3 var myEmptyCircle = Circle(radius: -1) -println(myEmptyCircle?.getArea()) // "nil" +print(myEmptyCircle?.getArea()) // "nil" if let circle = myEmptyCircle { // will not execute since myEmptyCircle is nil - println("circle is not nil") + print("circle is not nil") } @@ -447,7 +449,7 @@ enum BookName: String { case John = "John" case Luke = "Luke" } -println("Name: \(BookName.John.rawValue)") +print("Name: \(BookName.John.rawValue)") // Enum with associated Values enum Furniture { @@ -467,9 +469,9 @@ enum Furniture { } var desk: Furniture = .Desk(height: 80) -println(desk.description()) // "Desk with 80 cm" +print(desk.description()) // "Desk with 80 cm" var chair = Furniture.Chair("Foo", 40) -println(chair.description()) // "Chair of Foo with 40 cm" +print(chair.description()) // "Chair of Foo with 40 cm" // @@ -522,7 +524,7 @@ extension Square: Printable { } } -println("Square: \(mySquare)") +print("Square: \(mySquare)") // You can also extend built-in types extension Int { @@ -535,8 +537,8 @@ extension Int { } } -println(7.customProperty) // "This is 7" -println(14.multiplyBy(3)) // 42 +print(7.customProperty) // "This is 7" +print(14.multiplyBy(3)) // 42 // Generics: Similar to Java and C#. Use the `where` keyword to specify the // requirements of the generics. @@ -550,7 +552,7 @@ func findIndex(array: [T], valueToFind: T) -> Int? { return nil } let foundAtIndex = findIndex([1, 2, 3, 4], 3) -println(foundAtIndex == 2) // true +print(foundAtIndex == 2) // true // Operators: // Custom operators can start with the characters: @@ -566,9 +568,9 @@ prefix func !!! (inout shape: Square) -> Square { } // current value -println(mySquare.sideLength) // 4 +print(mySquare.sideLength) // 4 // change side length using custom !!! operator, increases size by 3 !!!mySquare -println(mySquare.sideLength) // 12 +print(mySquare.sideLength) // 12 ``` -- cgit v1.2.3 From 775ac3b8595f80dd3229b7974672cf71d642d94f Mon Sep 17 00:00:00 2001 From: Anthony Nguyen Date: Mon, 3 Aug 2015 23:10:10 -0400 Subject: Updated print description on Swift --- swift.html.markdown | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'swift.html.markdown') diff --git a/swift.html.markdown b/swift.html.markdown index 8e83a0b3..5ea8da6b 100644 --- a/swift.html.markdown +++ b/swift.html.markdown @@ -26,9 +26,9 @@ import UIKit // TODO: Do something soon // FIXME: Fix this code -// In Swift 2, println and print were combined into one print method. -print("Hello, world") // standard print -print("Hello, world", appendNewLine: true) // appending a new line +// In Swift 2, println and print were combined into one print method. Print automatically appends a new line. +print("Hello, world") // println is now print +print("Hello, world", appendNewLine: false) // printing without appending a newline // variables (var) value can change after being set // constants (let) value can NOT be changed after being set -- cgit v1.2.3 From d17d41a02b5eb67b0b28a9708cfa5640e17325ef Mon Sep 17 00:00:00 2001 From: Anthony Nguyen Date: Mon, 3 Aug 2015 23:11:44 -0400 Subject: Println deprecated in Swift 2, added name --- swift.html.markdown | 1 + 1 file changed, 1 insertion(+) (limited to 'swift.html.markdown') diff --git a/swift.html.markdown b/swift.html.markdown index 5ea8da6b..509c9d2f 100644 --- a/swift.html.markdown +++ b/swift.html.markdown @@ -4,6 +4,7 @@ contributors: - ["Grant Timmerman", "http://github.com/grant"] - ["Christopher Bess", "http://github.com/cbess"] - ["Joey Huang", "http://github.com/kamidox"] + - ["Anthony Nguyen", "http://github.com/anthonyn60"] filename: learnswift.swift --- -- cgit v1.2.3 From d540d1c67bb123f8e7dc3233be957e29d8983e4b Mon Sep 17 00:00:00 2001 From: Clayton Walker Date: Tue, 6 Oct 2015 22:25:38 -0400 Subject: Original link directs to page that can't be found. Changed to represent new location of the Apple Developer tutorial on swift. --- swift.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'swift.html.markdown') diff --git a/swift.html.markdown b/swift.html.markdown index 509c9d2f..86a0b89a 100644 --- a/swift.html.markdown +++ b/swift.html.markdown @@ -12,7 +12,7 @@ Swift is a programming language for iOS and OS X development created by Apple. D The official [Swift Programming Language](https://itunes.apple.com/us/book/swift-programming-language/id881256329) book from Apple is now available via iBooks. -See also Apple's [getting started guide](https://developer.apple.com/library/prerelease/ios/referencelibrary/GettingStarted/RoadMapiOS/index.html), which has a complete tutorial on Swift. +See also Apple's [getting started guide](https://developer.apple.com/library/prerelease/ios/referencelibrary/GettingStarted/DevelopiOSAppsSwift/), which has a complete tutorial on Swift. ```swift // import a module -- cgit v1.2.3 From 5dac348b72000dedc2e8a35f1ccaea55a7f408f7 Mon Sep 17 00:00:00 2001 From: Clayton Walker Date: Tue, 6 Oct 2015 23:00:11 -0400 Subject: Forgot to add myself as a contributor from swift-1 pull request. --- swift.html.markdown | 1 + 1 file changed, 1 insertion(+) (limited to 'swift.html.markdown') diff --git a/swift.html.markdown b/swift.html.markdown index 509c9d2f..23ebcfc5 100644 --- a/swift.html.markdown +++ b/swift.html.markdown @@ -5,6 +5,7 @@ contributors: - ["Christopher Bess", "http://github.com/cbess"] - ["Joey Huang", "http://github.com/kamidox"] - ["Anthony Nguyen", "http://github.com/anthonyn60"] + - ["Clayton Walker", "https://github.com/cwalk"] filename: learnswift.swift --- -- cgit v1.2.3 From ad16a31c0751f244a46cadbfb3540943af73349d Mon Sep 17 00:00:00 2001 From: Clayton Walker Date: Tue, 6 Oct 2015 23:36:32 -0400 Subject: Added clearer description of Optionals and Unwrapping. Minor typo changes as well. --- swift.html.markdown | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) (limited to 'swift.html.markdown') diff --git a/swift.html.markdown b/swift.html.markdown index 23ebcfc5..46e5e6d4 100644 --- a/swift.html.markdown +++ b/swift.html.markdown @@ -58,8 +58,9 @@ let piText = "Pi = \(π), Pi 2 = \(π * 2)" // String interpolation print("Build value: \(buildValue)") // Build value: 7 /* - Optionals are a Swift language feature that allows you to store a `Some` or - `None` value. + Optionals are a Swift language feature that either contains a value, + or contains nil (no value) to indicate that a value is missing. + A question mark (?) after the type marks the value as optional. Because Swift requires every property to have a value, even nil must be explicitly stored as an Optional value. @@ -75,11 +76,17 @@ if someOptionalString != nil { if someOptionalString!.hasPrefix("opt") { print("has the prefix") } - + let empty = someOptionalString?.isEmpty } someOptionalString = nil +/* + To get the underlying type from an optional, you unwrap it using the + force unwrap operator (!). Only use the unwrap operator if you're sure + the underlying value isn't nil. +*/ + // implicitly unwrapped optional var unwrappedString: String! = "Value is expected." // same as above, but ! is a postfix operator (more syntax candy) @@ -94,13 +101,13 @@ if let someOptionalStringConstant = someOptionalString { // Swift has support for storing a value of any type. // AnyObject == id -// Unlike Objective-C `id`, AnyObject works with any value (Class, Int, struct, etc) +// Unlike Objective-C `id`, AnyObject works with any value (Class, Int, struct, etc.) var anyObjectVar: AnyObject = 7 anyObjectVar = "Changed value to a string, not good practice, but possible." /* Comment here - + /* Nested comments are also supported */ @@ -296,10 +303,10 @@ print(numbers) // [3, 6, 18] // MARK: Structures // -// Structures and classes have very similar capabilites +// Structures and classes have very similar capabilities struct NamesTable { let names = [String]() - + // Custom subscript subscript(index: Int) -> String { return names[index] @@ -330,7 +337,7 @@ public class Shape { internal class Rect: Shape { var sideLength: Int = 1 - + // Custom getter and setter property private var perimeter: Int { get { @@ -341,11 +348,11 @@ internal class Rect: Shape { sideLength = newValue / 4 } } - + // Lazily load a property // subShape remains nil (uninitialized) until getter called lazy var subShape = Rect(sideLength: 4) - + // If you don't need a custom getter and setter, // but still want to run code before and after getting or setting // a property, you can use `willSet` and `didSet` @@ -355,19 +362,19 @@ internal class Rect: Shape { print(someIdentifier) } } - + init(sideLength: Int) { self.sideLength = sideLength // always super.init last when init custom properties super.init() } - + func shrink() { if sideLength > 0 { --sideLength } } - + override func getArea() -> Int { return sideLength * sideLength } @@ -399,13 +406,13 @@ class Circle: Shape { override func getArea() -> Int { return 3 * radius * radius } - + // Place a question mark postfix after `init` is an optional init // which can return nil init?(radius: Int) { self.radius = radius super.init() - + if radius <= 0 { return nil } @@ -459,7 +466,7 @@ enum Furniture { case Desk(height: Int) // Associate with String and Int case Chair(String, Int) - + func description() -> String { switch self { case .Desk(let height): @@ -498,7 +505,7 @@ protocol ShapeGenerator { class MyShape: Rect { var delegate: TransformShape? - + func grow() { sideLength += 2 @@ -533,7 +540,7 @@ extension Int { var customProperty: String { return "This is \(self)" } - + func multiplyBy(num: Int) -> Int { return num * self } -- cgit v1.2.3 From 960ee4a1856db8eadb96277bb2422edfa8f2a81c Mon Sep 17 00:00:00 2001 From: Gabriel Halley Date: Wed, 7 Oct 2015 23:11:24 -0400 Subject: removing whitespace all over --- swift.html.markdown | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'swift.html.markdown') diff --git a/swift.html.markdown b/swift.html.markdown index 86a0b89a..a40e86c8 100644 --- a/swift.html.markdown +++ b/swift.html.markdown @@ -3,7 +3,7 @@ language: swift contributors: - ["Grant Timmerman", "http://github.com/grant"] - ["Christopher Bess", "http://github.com/cbess"] - - ["Joey Huang", "http://github.com/kamidox"] + - ["Joey Huang", "http://github.com/kamidox"] - ["Anthony Nguyen", "http://github.com/anthonyn60"] filename: learnswift.swift --- @@ -74,7 +74,7 @@ if someOptionalString != nil { if someOptionalString!.hasPrefix("opt") { print("has the prefix") } - + let empty = someOptionalString?.isEmpty } someOptionalString = nil @@ -99,7 +99,7 @@ anyObjectVar = "Changed value to a string, not good practice, but possible." /* Comment here - + /* Nested comments are also supported */ @@ -298,7 +298,7 @@ print(numbers) // [3, 6, 18] // Structures and classes have very similar capabilites struct NamesTable { let names = [String]() - + // Custom subscript subscript(index: Int) -> String { return names[index] @@ -329,7 +329,7 @@ public class Shape { internal class Rect: Shape { var sideLength: Int = 1 - + // Custom getter and setter property private var perimeter: Int { get { @@ -340,11 +340,11 @@ internal class Rect: Shape { sideLength = newValue / 4 } } - + // Lazily load a property // subShape remains nil (uninitialized) until getter called lazy var subShape = Rect(sideLength: 4) - + // If you don't need a custom getter and setter, // but still want to run code before and after getting or setting // a property, you can use `willSet` and `didSet` @@ -354,19 +354,19 @@ internal class Rect: Shape { print(someIdentifier) } } - + init(sideLength: Int) { self.sideLength = sideLength // always super.init last when init custom properties super.init() } - + func shrink() { if sideLength > 0 { --sideLength } } - + override func getArea() -> Int { return sideLength * sideLength } @@ -398,13 +398,13 @@ class Circle: Shape { override func getArea() -> Int { return 3 * radius * radius } - + // Place a question mark postfix after `init` is an optional init // which can return nil init?(radius: Int) { self.radius = radius super.init() - + if radius <= 0 { return nil } @@ -458,7 +458,7 @@ enum Furniture { case Desk(height: Int) // Associate with String and Int case Chair(String, Int) - + func description() -> String { switch self { case .Desk(let height): @@ -497,7 +497,7 @@ protocol ShapeGenerator { class MyShape: Rect { var delegate: TransformShape? - + func grow() { sideLength += 2 @@ -532,7 +532,7 @@ extension Int { var customProperty: String { return "This is \(self)" } - + func multiplyBy(num: Int) -> Int { return num * self } -- cgit v1.2.3 From 707c8db171cb5239682332f14fd2098901741c63 Mon Sep 17 00:00:00 2001 From: Valentine Silvansky Date: Thu, 8 Oct 2015 10:00:13 +0300 Subject: Add generics operator in Swift --- swift.html.markdown | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'swift.html.markdown') diff --git a/swift.html.markdown b/swift.html.markdown index a40e86c8..75535e43 100644 --- a/swift.html.markdown +++ b/swift.html.markdown @@ -574,4 +574,18 @@ print(mySquare.sideLength) // 4 // change side length using custom !!! operator, increases size by 3 !!!mySquare print(mySquare.sideLength) // 12 + +// Operators can also be generics +infix operator <-> {} +func <-> (inout a: T, inout b: T) { + let c = a + a = b + b = c +} + +var foo: Float = 10 +var bar: Float = 20 + +foo <-> bar +print("foo is \(foo), bar is \(bar)") // "foo is 20.0, bar is 10.0" ``` -- cgit v1.2.3 From b4860de42f2bbf0ab97ef28085eb40accb030657 Mon Sep 17 00:00:00 2001 From: Clayton Walker Date: Thu, 8 Oct 2015 23:27:19 -0400 Subject: Suggested changes --- swift.html.markdown | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'swift.html.markdown') diff --git a/swift.html.markdown b/swift.html.markdown index 46e5e6d4..9f0019d8 100644 --- a/swift.html.markdown +++ b/swift.html.markdown @@ -58,8 +58,8 @@ let piText = "Pi = \(π), Pi 2 = \(π * 2)" // String interpolation print("Build value: \(buildValue)") // Build value: 7 /* - Optionals are a Swift language feature that either contains a value, - or contains nil (no value) to indicate that a value is missing. + Optionals are a Swift language feature that either contains a value, + or contains nil (no value) to indicate that a value is missing. A question mark (?) after the type marks the value as optional. Because Swift requires every property to have a value, even nil must be @@ -82,9 +82,9 @@ if someOptionalString != nil { someOptionalString = nil /* - To get the underlying type from an optional, you unwrap it using the - force unwrap operator (!). Only use the unwrap operator if you're sure - the underlying value isn't nil. + Trying to use ! to access a non-existent optional value triggers a runtime + error. Always make sure that an optional contains a non-nil value before + using ! to force-unwrap its value. */ // implicitly unwrapped optional -- cgit v1.2.3 From 9530122a1c956a25adb71bfd9cc1c516ff67d2f3 Mon Sep 17 00:00:00 2001 From: Fernando Valverde Date: Fri, 30 Oct 2015 22:43:44 +0100 Subject: Include MARK style and two collection declarations Added MARK with separator and a couple of mutable explicit declarations of empty Array/Dictionary --- swift.html.markdown | 3 +++ 1 file changed, 3 insertions(+) (limited to 'swift.html.markdown') diff --git a/swift.html.markdown b/swift.html.markdown index f451288d..1ca81bc2 100644 --- a/swift.html.markdown +++ b/swift.html.markdown @@ -25,6 +25,7 @@ import UIKit // Xcode supports landmarks to annotate your code and lists them in the jump bar // MARK: Section mark +// MARK: - Section mark with a separator line // TODO: Do something soon // FIXME: Fix this code @@ -128,6 +129,7 @@ shoppingList[1] = "bottle of water" let emptyArray = [String]() // let == immutable let emptyArray2 = Array() // same as above var emptyMutableArray = [String]() // var == mutable +var explicitEmptyMutableStringArray: [String] = [] // same as above // Dictionary @@ -139,6 +141,7 @@ occupations["Jayne"] = "Public Relations" let emptyDictionary = [String: Float]() // let == immutable let emptyDictionary2 = Dictionary() // same as above var emptyMutableDictionary = [String: Float]() // var == mutable +var explicitEmptyMutableDictionary: [String: Float] = [:] // same as above // -- cgit v1.2.3 From dbe6184519860e526432c4987a6f67d6c0acf38e Mon Sep 17 00:00:00 2001 From: Fernando Valverde Arredondo Date: Sun, 1 Nov 2015 01:48:44 +0100 Subject: Update contributor list --- swift.html.markdown | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'swift.html.markdown') diff --git a/swift.html.markdown b/swift.html.markdown index 1ca81bc2..f3746613 100644 --- a/swift.html.markdown +++ b/swift.html.markdown @@ -6,6 +6,7 @@ contributors: - ["Joey Huang", "http://github.com/kamidox"] - ["Anthony Nguyen", "http://github.com/anthonyn60"] - ["Clayton Walker", "https://github.com/cwalk"] + - ["Fernando Valverde", "http://visualcosita.xyz"] filename: learnswift.swift --- @@ -25,7 +26,7 @@ import UIKit // Xcode supports landmarks to annotate your code and lists them in the jump bar // MARK: Section mark -// MARK: - Section mark with a separator line +// MARK: - Section mark with a separator line // TODO: Do something soon // FIXME: Fix this code @@ -83,7 +84,7 @@ if someOptionalString != nil { someOptionalString = nil /* - Trying to use ! to access a non-existent optional value triggers a runtime + Trying to use ! to access a non-existent optional value triggers a runtime error. Always make sure that an optional contains a non-nil value before using ! to force-unwrap its value. */ -- cgit v1.2.3