From 62d4b1483b850da0a99c2aa6c2da8b013e308f50 Mon Sep 17 00:00:00 2001 From: Damian Rzeszot Date: Mon, 9 Oct 2017 11:56:50 +0200 Subject: swift | fix style guidelines --- swift.html.markdown | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'swift.html.markdown') diff --git a/swift.html.markdown b/swift.html.markdown index 60915d72..46388ca5 100644 --- a/swift.html.markdown +++ b/swift.html.markdown @@ -361,14 +361,14 @@ print("Name is \(name)") // Name is Them // The `Error` protocol is used when throwing errors to catch enum MyError: Error { - case BadValue(msg: String) - case ReallyBadValue(msg: String) + case badValue(msg: String) + case reallyBadValue(msg: String) } // functions marked with `throws` must be called using `try` func fakeFetch(value: Int) throws -> String { guard 7 == value else { - throw MyError.ReallyBadValue(msg: "Some really bad value") + throw MyError.reallyBadValue(msg: "Some really bad value") } return "test" @@ -385,7 +385,7 @@ func testTryStuff() { do { // normal try operation that provides error handling via `catch` block try fakeFetch(value: 1) - } catch MyError.BadValue(let msg) { + } catch MyError.badValue(let msg) { print("Error message: \(msg)") } catch { // must be exhaustive -- cgit v1.2.3 From d01e5242e16c522becc1b04f9692d2556f94c4f1 Mon Sep 17 00:00:00 2001 From: Damian Rzeszot Date: Mon, 9 Oct 2017 12:01:15 +0200 Subject: swift | fix style guidelines --- swift.html.markdown | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'swift.html.markdown') diff --git a/swift.html.markdown b/swift.html.markdown index 46388ca5..577fa559 100644 --- a/swift.html.markdown +++ b/swift.html.markdown @@ -518,20 +518,20 @@ if let circle = myEmptyCircle { // They can contain methods like classes. enum Suit { - case Spades, Hearts, Diamonds, Clubs + case spades, hearts, diamonds, clubs func getIcon() -> String { switch self { - case .Spades: return "♤" - case .Hearts: return "♡" - case .Diamonds: return "♢" - case .Clubs: return "♧" + case .spades: return "♤" + case .hearts: return "♡" + case .diamonds: return "♢" + case .clubs: return "♧" } } } // Enum values allow short hand syntax, no need to type the enum type // when the variable is explicitly declared -var suitValue: Suit = .Hearts +var suitValue: Suit = .hearts // String enums can have direct raw value assignments // or their raw values will be derived from the Enum field -- cgit v1.2.3 From 9a9e52b54bf9bc6ebeefc996452f5944a234557f Mon Sep 17 00:00:00 2001 From: Damian Rzeszot Date: Mon, 9 Oct 2017 12:02:29 +0200 Subject: swift | fix style guidelines --- 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 577fa559..a3b33e25 100644 --- a/swift.html.markdown +++ b/swift.html.markdown @@ -536,10 +536,10 @@ var suitValue: Suit = .hearts // String enums can have direct raw value assignments // or their raw values will be derived from the Enum field enum BookName: String { - case John - case Luke = "Luke" + case john + case luke = "Luke" } -print("Name: \(BookName.John.rawValue)") +print("Name: \(BookName.john.rawValue)") // Enum with associated Values enum Furniture { -- cgit v1.2.3 From e8ee66c854b8833fcb0fd76b5e9ace6ae8379397 Mon Sep 17 00:00:00 2001 From: Damian Rzeszot Date: Mon, 9 Oct 2017 12:03:27 +0200 Subject: swift | fix style guidelines --- swift.html.markdown | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'swift.html.markdown') diff --git a/swift.html.markdown b/swift.html.markdown index a3b33e25..516debed 100644 --- a/swift.html.markdown +++ b/swift.html.markdown @@ -544,23 +544,23 @@ print("Name: \(BookName.john.rawValue)") // Enum with associated Values enum Furniture { // Associate with Int - case Desk(height: Int) + case desk(height: Int) // Associate with String and Int - case Chair(String, Int) + case chair(String, Int) func description() -> String { switch self { - case .Desk(let height): + case .desk(let height): return "Desk with \(height) cm" - case .Chair(let brand, let height): + case .chair(let brand, let height): return "Chair of \(brand) with \(height) cm" } } } -var desk: Furniture = .Desk(height: 80) +var desk: Furniture = .desk(height: 80) print(desk.description()) // "Desk with 80 cm" -var chair = Furniture.Chair("Foo", 40) +var chair = Furniture.chair("Foo", 40) print(chair.description()) // "Chair of Foo with 40 cm" -- cgit v1.2.3