From 76f4c1b3b6d99d05197224dfec905a46dbd80713 Mon Sep 17 00:00:00 2001 From: Grant Timmerman Date: Wed, 4 Jun 2014 13:22:01 -0700 Subject: Formatted the document according to the guidelines --- swift.html.markdown | 94 ++++++++++++++++++++++++++--------------------------- 1 file changed, 47 insertions(+), 47 deletions(-) diff --git a/swift.html.markdown b/swift.html.markdown index c7615a82..6ab0cc20 100644 --- a/swift.html.markdown +++ b/swift.html.markdown @@ -9,20 +9,11 @@ Swift is a programming language for iOS and OS X development created by Apple. D 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. -# Overview -- [Basics](#basics) -- [Arrays and Dictionaries](#array) -- [Control Flow](#control) -- [Functions](#func) -- [Closures](#closures) -- [Classes](#classes) -- [Enums](#enums) -- [Other](#other) -- [Links](#links) - -## Basics - ```js +// +// Basics +// + println("Hello, world") var myVariable = 42 let myConstant = 3.1415926 @@ -31,11 +22,12 @@ let label = "some text " + String(myVariable) // Casting let piText = "Pi = \(myConstant)" // String interpolation var optionalString: String? = "optional" // Can be nil optionalString = nil -``` -## Arrays and Dictionaries -```js +// +// Arrays and Dictionaries +// + // Array var shoppingList = ["catfish", "water", "lemons"] shoppingList[1] = "bottle of water" @@ -48,11 +40,12 @@ var occupations = [ ] occupations["Jayne"] = "Public Relations" let emptyDictionary = Dictionary() -``` -## Control Flow -```js +// +// Control Flow +// + // for loop (array) let myArray = [1, 1, 2, 3, 5] for value in myArray { @@ -97,13 +90,15 @@ case let x where x.hasSuffix("pepper"): default: // required (in order to cover all possible input) let vegetableComment = "Everything tastes good in soup." } -``` -## Functions -Functions are a first-class type, meaning they can be nested in functions and can be passed around +// +// Functions +// + +// Functions are a first-class type, meaning they can be nested +// in functions and can be passed around -```js // Function func greet(name: String, day: String) -> String { return "Hello \(name), today is \(day)." @@ -127,13 +122,14 @@ func makeIncrementer() -> (Int -> Int) { } var increment = makeIncrementer() increment(7) -``` -## Closures -Functions are special case closures ({}) +// +// Closures +// + +// Functions are special case closures ({}) -```js // Closure example. // `->` separates the arguments and return type // `in` separates the closure header from the closure body @@ -147,14 +143,16 @@ numbers.map({ var numbers = [1, 2, 6] numbers = numbers.map({ number in 3 * number }) print(numbers) // [3, 6, 18] -``` -## Classes -All methods and properties of a class are public. If you just need to store data -in a structured object, you should use a `struct` +// +// Classes +// + +// All methods and properties of a class are public. +// If you just need to store data in a +// structured object, you should use a `struct` -```js // A simple class `Square` extends `Shape class Rect: Shape { var sideLength: Int = 1 @@ -189,15 +187,18 @@ print(mySquare.getArea()) // 25 mySquare.shrink() print(mySquare.sideLength) // 4 -// If you don't need a custom getter and setter, but still want to run code -// before an after getting or setting a property, you can use `willSet` and `didSet` -``` +// If you don't need a custom getter and setter, +// but still want to run code before an after getting or setting +// a property, you can use `willSet` and `didSet` -## Enums -Enums can optionally be of a specific type or on their own. They can contain methods like classes. +// +// Enums +// + +// Enums can optionally be of a specific type or on their own. +// They can contain methods like classes. -```js enum Suit { case Spades, Hearts, Diamonds, Clubs func getIcon() -> String { @@ -209,16 +210,15 @@ enum Suit { } } } -``` -## Other -- **`protocol`**: Similar to Java interfaces. -- **`extension`s**: Add extra functionality to an already created type -- **Generics**: Similar to Java. Use the `where` keyword to specify the requirements of the generics. +// +// Other +// -## Links +// `protocol`: Similar to Java interfaces. +// `extension`s: Add extra functionality to an already created type +// Generics: Similar to Java. Use the `where` keyword to specify the +// requirements of the generics. -- [Homepage](https://developer.apple.com/swift/) -- [Guide](https://developer.apple.com/library/prerelease/ios/referencelibrary/GettingStarted/LandingPage/index.html) -- [Book](https://itunes.apple.com/us/book/the-swift-programming-language/id881256329?mt=11) +``` \ No newline at end of file -- cgit v1.2.3