This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let numbers = [10, 83, 95, 100, 92] | |
// numbers์ ์์ ์ค ์ง์๋ฅผ ๊ฑธ๋ฌ๋ด์ด ์๋ก์ด ๋ฐฐ์ด๋ก ๋ฐํ | |
let evenNumbers: [Int] = numbers.filter { (number: Int) -> Bool in | |
return number % 2 == 0 | |
} | |
print(evenNumbers) | |
// [10, 100, 92] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let someNumbers = [10, 8, 7, 1, 9] | |
// ์ด๊น๊ฐ์ด 0์ด๊ณ someNumbers ๋ด๋ถ์ ๋ชจ๋ ๊ฐ์ ๋ํฉ๋๋ค. | |
let sum: Int = someNumbers.reduce(0, { (first: Int, second: Int) -> Int in | |
//print("\(first) + \(second)") //์ด๋ป๊ฒ ๋์ํ๋์ง ํ์ธํด๋ณด์ธ์ | |
return first + second | |
}) | |
// 35 | |
// ์ด๊น๊ฐ์ด 5์ด๊ณ someNumbers ๋ด๋ถ์ ๋ชจ๋ ๊ฐ์ ๋บ๋๋ค. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct TV { | |
var channel: Int = 1 | |
} | |
var tv = TV() | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct TV { | |
var channel: Int = 1 | |
} | |
var tv = TV(channel: 15) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct TV { | |
var channel: Int = 1 | |
init(channel: Int) { | |
self.channel = channel | |
} | |
} | |
var tv = TV(channel: 15) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct TV { | |
var channel: Int = 1 | |
var brand: String | |
init(channel: Int) { | |
self.channel = channel | |
self.brand = "LG" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Animal { | |
let species: String | |
init?(species: String) { | |
if species.isEmpty { return nil } | |
self.species = species | |
} | |
} | |
var animal = Animal(species: "") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct TV { | |
var channel: Int = 1 | |
var brand: String | |
init(channel: Int) { | |
self.channel = channel | |
self.brand = "LG" | |
} | |
init() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Radio { | |
var channel: Double | |
init(channel: Double) { | |
self.channel = channel | |
} | |
} | |
let radio = Radio(channel: 89.1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Radio { | |
var channel: Double | |
init(channel: Double) { | |
self.channel = channel | |
} | |
convenience init(){ | |
self.init(channel: 103.5) | |
} | |
} |