Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기

Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기

Suyeol Jeon

July 15, 2016
Tweet

More Decks by Suyeol Jeon

Other Decks in Programming

Transcript

  1. // ߸ࣻח ч ߸҃ оמ NVUBCMF name = "੹ࣻৌ" //

    ࢚ࣻחч߸҃ࠛоמ JNNVUBCMF birthyear = 2000 ! Cannot assign to value: 'birthyear' is a 'let' constant ۠ఋ੐੉ইצஹ౵ੌఋ੐ী୓௼ؽ ߸ࣻ৬࢚ࣻ
  2. var name: String = "Suyeol Jeon" let birthyear: Int =

    1995 var height: Float = 180.1 ੿੸ఋ੉ೝ 4UBUJD5ZQJOH ঱য ߸ࣻ৬࢚ࣻ ↟ ஹ౵ੌఋ੐ী߸ࣻ੄੗ܐഋਸঌইঠೠ׮ ↟ ೠߣࢶ঱ػ੗ܐഋ਷߄Շ૑ঋח׮
  3. var name: String = "Suyeol Jeon" let birthyear: Int =

    1995 var height: Float = 180.1 ↟ "ABC"חString੉׮ ↟ 123਷Int׮ ↟ ஹ౵ੌఋ੐ী߸ࣻ੄੗ܐഋਸ୶ஏ ߸ࣻ৬࢚ࣻ ఋੑ୶ۿ 5ZQF*OGFSFODF ࢤۚ ࢤۚ ࢤۚ
  4. ߸ࣻ৬࢚ࣻ ߓৌ "SSBZ җ٤࣊ցܻ %JDUJPOBSZ [String] [String: String] let languages

    = [ "Swift", "Objective-C", "Python", ] var capitals = [ "ೠҴ": "ࢲ਎", "ੌࠄ": "ب௡", "઺Ҵ": "߬੉૚", ]
  5. ઑѤޙҗ߈ࠂޙ for _ in 0..<10 { print("Hello!") } ױࣽೠ߈ࠂޙ •

    for i in 0..<10ܳࢎਊೞݶ
 iܳࢎਊೞ૑ঋও׮Ҋஹ౵ੌ۞҃Ҋ • @ܳࢎਊೞݶчਸࢎਊೞ૑ঋҊޖद
  6. ઑѤޙҗ߈ࠂޙ switch age { case 8..<14: student = "ୡ١೟ࢤ" case

    14..<17: student = "઺೟ࢤ" case 17..<20: student = "Ҋ١೟ࢤ" default: student = "ӝఋ" } ಁఢݒட
  7. ২࣊օ 0QUJPOBM var name: String = "੹ࣻৌ" name = nil

    ! Nil cannot be assigned to type 'String' ӒրStringীחnilਸ֍ਸࣻহ׮
  8. ২࣊օ 0QUJPOBM var name: String? = "੹ࣻৌ" name = nil

    ?ܳࠢৈࢲStringਸ২࣊օ۽੿੄೧ঠೠ׮ ч੉੓ਸࣻب੓Ҋ ч੉হਸࣻب੓Ҋ
  9. ২࣊օ 0QUJPOBM String?਷String੉ইפ׮ let optional: String? = "Hello" let required:

    String = optional ! Value of optional type 'String?' not unwrapped; did you mean to use '!' or '?'?
  10. ২࣊օ 0QUJPOBM ২࣊օ߄ੋ٬ 0QUJPOBM#JOEJOH let optionalName: String? = "੹ࣻৌ" if

    let name = optionalName { print(name) } ч੉ઓ੤ೞח҃਋
  11. ২࣊օ 0QUJPOBM ২࣊օ߄ੋ٬ 0QUJPOBM#JOEJOH let optionalName: String? = "੹ࣻৌ" if

    let name = optionalName { print(name) } ч੉ઓ੤ೞח҃਋
  12. ২࣊օ 0QUJPOBM ২࣊օ߄ੋ٬ 0QUJPOBM#JOEJOH let optionalName: String? = "੹ࣻৌ" if

    let name = optionalName { print(name) } ч੉ઓ੤ೞח҃਋
  13. ২࣊օ 0QUJPOBM ২࣊օ߄ੋ٬ 0QUJPOBM#JOEJOH let optionalName: String? = "੹ࣻৌ" if

    let name = optionalName { print(name) } ч੉ઓ੤ೞח҃਋ "੹ࣻৌ" पઁч
  14. ২࣊օ 0QUJPOBM ২࣊օ߄ੋ٬ 0QUJPOBM#JOEJOH let optionalName: String? = "੹ࣻৌ" if

    let name = optionalName { print(name) } ч੉ઓ੤ೞח҃਋ let name: String = "੹ࣻৌ" ਃۧѱࢶ঱ೠѪҗэ਷࢚కоؽ
  15. ২࣊օ 0QUJPOBM ২࣊օ߄ੋ٬ 0QUJPOBM#JOEJOH let optionalName: String? = "੹ࣻৌ" if

    let name = optionalName { print(name) // ੹ࣻৌ } ч੉ઓ੤ೞח҃਋
  16. ২࣊օ 0QUJPOBM ২࣊օ߄ੋ٬ 0QUJPOBM#JOEJOH let optionalName: String? = "੹ࣻৌ" if

    let name = optionalName { print(name) // ੹ࣻৌ } ч੉ઓ੤ೞח҃਋
  17. ২࣊օ 0QUJPOBM ২࣊օ߄ੋ٬ 0QUJPOBM#JOEJOH let optionalName: String? if let name

    = optionalName { print(name) } ч੉ઓ੤ೞ૑ঋח҃਋
  18. ২࣊օ 0QUJPOBM ২࣊օ߄ੋ٬ 0QUJPOBM#JOEJOH let optionalName: String? if let name

    = optionalName { print(name) } ч੉ઓ੤ೞ૑ঋח҃਋
  19. ২࣊օ 0QUJPOBM ২࣊օ߄ੋ٬ 0QUJPOBM#JOEJOH let optionalName: String? if let name

    = optionalName { print(name) } ч੉ઓ੤ೞ૑ঋח҃਋ nil
  20. ২࣊օ 0QUJPOBM ২࣊օ߄ੋ٬ 0QUJPOBM#JOEJOH let optionalName: String? if let name

    = optionalName { print(name) } ч੉ઓ੤ೞ૑ঋח҃਋ ઁযޙਸӒրѤցڭ
  21. ২࣊օ 0QUJPOBM ২࣊օ߄ੋ٬ 0QUJPOBM#JOEJOH if let name = optionalName, let

    age = optionalAge { print(name, age) } ৈ۞ѐ੄0QUJPOBM߄ੋ٬بоמ
  22. ২࣊օ 0QUJPOBM ২࣊օ߄ੋ٬ 0QUJPOBM#JOEJOH if let age = optionalAge where

    age >= 20 { print(age) } ↟ whereܳࢎਊೠઑѤ૑੿ ↟ ২࣊օ੉ߩѹ૓чਸࢎਊоמ
  23. ২࣊օ 0QUJPOBM ২࣊օ୓੉׬ 0QUJPOBM$IBJOJOH if let arr = optionalArray {

    print(arr.isEmpty) } else { print(false) } ߓৌীч੉ઓ੤ೞח૑୹۱ೞӝ
  24. ২࣊օ 0QUJPOBM ২࣊օߩӝӝ 6OXSBQ let optionalName: String? = "੹ࣻৌ" print(optionalName)

    // Optional("੹ࣻৌ") print(optionalName!) // ੹ࣻৌ ܳࢎਊ೧ࢲъઁ۽২࣊օ੄чਸԁղৡ׮
  25. ২࣊օ 0QUJPOBM ঐޗ੸ਵ۽ߩѹ૓২࣊օ *NQMJDJUMZ6OXSBQQFE0QUJPOBM var email: String! = "੹ࣻৌ" print(email)

    // ੹ࣻৌ ↟ ч੉੓׮Ҋо੿ೞח২࣊օ ↟ 0QUJPOBM#JOEJOHহ੉чী૒੽੽Ӕоמ ↟ оઉ৳חؘnil੉ۄݶ$SBTI উॳחѱજ׮
  26. ೣࣻ৬௿۽੷ $MPTVSF func hello(name: String, time: Int) -> String {

    var string = "" for _ in 0..<time { string += "\(name)ש উ֞ೞࣁਃ!\n" } return string } ೣࣻ੿੄
  27. ೣࣻ৬௿۽੷ $MPTVSF func hello(name: String, time: Int) -> String {

    var string = "" for _ in 0..<time { string += "\(name)ש উ֞ೞࣁਃ!\n" } return string } hello("੹ࣻৌ", time: 3) ೣࣻ੿੄
  28. ೣࣻ৬௿۽੷ $MPTVSF func hello(name: String, time: Int) -> String {

    var string = "" for _ in 0..<time { string += "\(name)ש উ֞ೞࣁਃ!\n" } return string } hello("੹ࣻৌ", time: 3) ୐ߣ૩חࢤۚ 4XJGUীࢲח೙ਃ Oߣ૩ח౵ۄ޷ఠ੉ܴ੘ࢿ ୐ߣ૩ੋ੗ Oߣ૩ੋ੗ O ೣࣻ੿੄
  29. ೣࣻ৬௿۽੷ $MPTVSF func hello(name: String, numberOfTimes time: Int) -> Void

    { print(time) } hello("੹ࣻৌ", numberOfTimes: 3) ౵ۄ޷ఠ੉ܴ૑੿ೞӝ
  30. ೣࣻ৬௿۽੷ $MPTVSF func hello(name: String, numberOfTimes time: Int) -> Void

    { print(time) } hello("੹ࣻৌ", numberOfTimes: 3) ೣࣻഐ୹दࢎਊೞח੉ܴ ղࠗীࢲࢎਊೞח੉ܴ ౵ۄ޷ఠ੉ܴ૑੿ೞӝ
  31. ೣࣻ৬௿۽੷ $MPTVSF func hello(withName name: String, numberOfTimes time: Int) ->

    Void { print(time) } hello(withName: "੹ࣻৌ", numberOfTimes: 3) ୐ߣ૩౵ۄ޷ఠ੉ܴ૑੿ೞӝ
  32. ೣࣻ৬௿۽੷ $MPTVSF func hello(withName name: String, numberOfTimes time: Int) ->

    Void { print(time) } hello(withName: "੹ࣻৌ", numberOfTimes: 3) ୐ߣ૩౵ۄ޷ఠ੉ܴ૑੿ೞӝ
  33. ೣࣻ৬௿۽੷ $MPTVSF func hello(name: String, _ time: Int) -> Void

    { print(time) } hello("੹ࣻৌ", 3) ౵ۄ޷ఠ੉ܴࢤۚೞӝ
  34. ೣࣻ৬௿۽੷ $MPTVSF func hello(name: String, time: Int = 1) ->

    Void { print(time) } hello("੹ࣻৌ") ౵ۄ޷ఠӝࠄч૑੿ೞӝ
  35. ೣࣻ৬௿۽੷ $MPTVSF func sum(numbers: Int...) -> Int { var sum

    = 0 for number in numbers { sum += number } return sum } sum(1, 2) sum(3, 4, 5) о߸ഋੋ੗
  36. ೣࣻ৬௿۽੷ $MPTVSF func hello(name: String, time: Int) { func message(name:

    String) { return "\(name)ש উ֞ೞࣁਃ!" } for _ in 0..<time { print message(name) } } ೣࣻউীೣࣻ੿੄ೞӝ ઺୏ೣࣻ
  37. ೣࣻ৬௿۽੷ $MPTVSF func helloGenerator(message: String) -> String -> String {

    func hello(name: String) -> String { return name + message } return hello } let hello = helloGenerator("ש উ֞ೞࣁਃ!") hello("੹ࣻৌ") ೣࣻীࢲೣࣻ߈ജೞӝ 4USJOHਸ߉ইࢲ4USJOHਸ߈ജೞחޖ঱о ܳ߈ജೞѷ׮
  38. ೣࣻ৬௿۽੷ $MPTVSF func helloGenerator(message: String) -> String -> String {

    func hello(name: String) -> String { return name + message } return hello } let hello = helloGenerator("ש উ֞ೞࣁਃ!") hello("੹ࣻৌ") ೣࣻীࢲೣࣻ߈ജೞӝ
  39. ೣࣻ৬௿۽੷ $MPTVSF func helloGenerator(message: String) -> (String, String) -> String

    { func hello(firstName: String, lastName: String) -> String { return lastName + firstName + message } return hello } let hello = helloGenerator("ש উ֞ೞࣁਃ!") hello("ࣻৌ", "੹") ೣࣻীࢲೣࣻ߈ജೞӝ 4USJOHفѐܳ߉ইࢲ4USJOHਸ߈ജೞחޖ঱о ܳ߈ജೞѷ׮
  40. ೣࣻ৬௿۽੷ $MPTVSF func helloGenerator(message: String) -> (String, String) -> String

    { func hello(firstName: String, lastName: String) -> String { return lastName + firstName + message } return hello } let hello = helloGenerator("ש উ֞ೞࣁਃ!") hello("ࣻৌ", "੹") ೣࣻীࢲೣࣻ߈ജೞӝ
  41. ೣࣻ৬௿۽੷ $MPTVSF func helloGenerator(message: String) -> (String, String) -> String

    { return { (firstName: String, lastName: String) -> String in return lastName + firstName + message } } ೣࣻীࢲ௿۽੷߈ജೞӝ func helloGenerator(message: String) -> (String, String) -> String { func hello(firstName: String, lastName: String) -> String { return lastName + firstName + message } return hello } ೣࣻח੉ܴ੉੓ח௿۽੷ 
  42. ೣࣻ৬௿۽੷ $MPTVSF func helloGenerator(message: String) -> (String, String) -> String

    { return { (firstName: String, lastName: String) -> String in return lastName + firstName + message } } ௿۽੷рѾೞѱٜ݅ӝ
  43. ೣࣻ৬௿۽੷ $MPTVSF func helloGenerator(message: String) -> (String, String) -> String

    { return { (firstName: String, lastName: String) -> String in return lastName + firstName + message } } ௿۽੷рѾೞѱٜ݅ӝ  ೣࣻ੿੄ীࢲ௿۽੷੄੗ܐഋਸঌҊ੓֎
  44. ೣࣻ৬௿۽੷ $MPTVSF func helloGenerator(message: String) -> (String, String) -> String

    { return { firstName , lastName in return lastName + firstName + message } } ௿۽੷рѾೞѱٜ݅ӝ  ೣࣻ੿੄ীࢲ௿۽੷੄੗ܐഋਸঌҊ੓֎ ࢤۚ
  45. ೣࣻ৬௿۽੷ $MPTVSF func helloGenerator(message: String) -> (String, String) -> String

    { return { firstName, lastName in return lastName + firstName + message } } ௿۽੷рѾೞѱٜ݅ӝ  ೣࣻ੿੄ীࢲ௿۽੷੄੗ܐഋਸঌҊ੓֎ ࢤۚ
  46. ೣࣻ৬௿۽੷ $MPTVSF func helloGenerator(message: String) -> (String, String) -> String

    { return { firstName, lastName in return lastName + firstName + message } } ௿۽੷рѾೞѱٜ݅ӝ  ௿۽੷౵ۄ޷ఠࣽࢲܳঌҊ੓֎
  47. ೣࣻ৬௿۽੷ $MPTVSF func helloGenerator(message: String) -> (String, String) -> String

    { return { return $1 + $0 + message } } ௿۽੷рѾೞѱٜ݅ӝ  ௿۽੷౵ۄ޷ఠࣽࢲܳঌҊ੓֎ ࢤۚ ߣ౵ۄ޷ఠ ߣ౵ۄ޷ఠ
  48. ೣࣻ৬௿۽੷ $MPTVSF func helloGenerator(message: String) -> (String, String) -> String

    { return { return $1 + $0 + message } } ௿۽੷рѾೞѱٜ݅ӝ  ௿۽੷౵ۄ޷ఠࣽࢲܳঌҊ੓֎ ࢤۚ
  49. ೣࣻ৬௿۽੷ $MPTVSF func helloGenerator(message: String) -> (String, String) -> String

    { return { $1 + $0 + message } } ௿۽੷рѾೞѱٜ݅ӝ  ब૑য҃਋ীٮۄSFUVSOبࢤۚೡࣻ੓਺ func helloGenerator(message: String) -> (String, String) -> String { return { return $1 + $0 + message } }
  50. ೣࣻ৬௿۽੷ $MPTVSF let hello: ((String, String) -> String)? = nil

    hello?("ࣻৌ", "੹") ২࣊օ۽੿੄೧ࢲ২࣊օ୓੉׬ೞӝ
  51. ೣࣻ৬௿۽੷ $MPTVSF func manipulateNumber(number: Int, usingBlock block: Int -> Int)

    -> Int { return block(number) } manipulateNumber(10, usingBlock: { (number: Int) -> Int in return number * 2 }) ௿۽੷ܳೣࣻ౵ۄ޷ఠ۽߉ӝ
  52. ೣࣻ৬௿۽੷ $MPTVSF manipulateNumber(10, usingBlock: { $0 * 2 }) ௿۽੷ܳೣࣻ౵ۄ޷ఠ۽߉ӝ

    ݃ଲо૑۽ࢤۚоמ manipulateNumber(10, usingBlock: { (number: Int) -> Int in return number * 2 }) manipulateNumber(10) { $0 * 2 } ೣࣻ੄݃૑݄౵ۄ޷ఠо ௿۽੷ੋ҃਋੉ܴҗҚഐࢤۚоמ
  53. ೣࣻ৬௿۽੷ $MPTVSF ௿۽੷ܳೣࣻ౵ۄ޷ఠ۽߉ӝ let numbers = [1, 3, 2, 6,

    7, 5, 8, 4] let sortedNumbers = numbers.sort { $0 < $1 } print(sortedNumbers) // [1, 2, 3, 4, 5, 6, 7, 8] let evens = numbers.filter { $0 % 2 == 0 } print(evens) // [2, 6, 8, 4] ৘दTPSU ৬GJMUFS
  54. ೣࣻ৬௿۽੷ $MPTVSF ௿۽੷ഝਊೞӝNBQ let arr1 = [1, 3, 6, 2,

    7, 9] let arr2 = arr1.map { $0 * 2 } // [2, 6, 12, 4, 14, 18]
  55. ೣࣻ৬௿۽੷ $MPTVSF ௿۽੷ഝਊೞӝNBQ let arr1 = [1, 3, 6, 2,

    7, 9] let arr2 = arr1.map { $0 * 2 } // [2, 6, 12, 4, 14, 18]
  56. ೣࣻ৬௿۽੷ $MPTVSF ௿۽੷ഝਊೞӝNBQ let arr1 = [1, 3, 6, 2,

    7, 9] let arr2 = arr1.map { $0 * 2 } // [2, 6, 12, 4, 14, 18]
  57. ೣࣻ৬௿۽੷ $MPTVSF ௿۽੷ഝਊೞӝNBQ let arr1 = [1, 3, 6, 2,

    7, 9] let arr2 = arr1.map { $0 * 2 } // [2, 6, 12, 4, 14, 18]
  58. ೣࣻ৬௿۽੷ $MPTVSF ௿۽੷ഝਊೞӝNBQ let arr1 = [1, 3, 6, 2,

    7, 9] let arr2 = arr1.map { $0 * 2 } // [2, 6, 12, 4, 14, 18]
  59. ೣࣻ৬௿۽੷ $MPTVSF ௿۽੷ഝਊೞӝNBQ let arr1 = [1, 3, 6, 2,

    7, 9] let arr2 = arr1.map { $0 * 2 } // [2, 6, 12, 4, 14, 18]
  60. ೣࣻ৬௿۽੷ $MPTVSF ௿۽੷ഝਊೞӝNBQ let arr1 = [1, 3, 6, 2,

    7, 9] let arr2 = arr1.map { $0 * 2 } // [2, 6, 12, 4, 14, 18]
  61. ೣࣻ৬௿۽੷ $MPTVSF ௿۽੷ഝਊೞӝNBQ let arr1 = [1, 3, 6, 2,

    7, 9] let arr2 = arr1.map { $0 * 2 } // [2, 6, 12, 4, 14, 18]
  62. ೣࣻ৬௿۽੷ $MPTVSF ௿۽੷ഝਊೞӝSFEVDF let arr1 = [1, 3, 6, 2,

    7, 9] arr1.reduce(0, combine: { $0 + $1 }) // 28 0 1 +
  63. ೣࣻ৬௿۽੷ $MPTVSF ௿۽੷ഝਊೞӝSFEVDF let arr1 = [1, 3, 6, 2,

    7, 9] arr1.reduce(0, combine: { $0 + $1 }) // 28 0 1 + = 1
  64. ೣࣻ৬௿۽੷ $MPTVSF ௿۽੷ഝਊೞӝSFEVDF let arr1 = [1, 3, 6, 2,

    7, 9] arr1.reduce(0, combine: { $0 + $1 }) // 28 1 3 0 1 + = 1 +
  65. ೣࣻ৬௿۽੷ $MPTVSF ௿۽੷ഝਊೞӝSFEVDF let arr1 = [1, 3, 6, 2,

    7, 9] arr1.reduce(0, combine: { $0 + $1 }) // 28 1 3 0 1 + = 1 + = 4
  66. ೣࣻ৬௿۽੷ $MPTVSF ௿۽੷ഝਊೞӝSFEVDF let arr1 = [1, 3, 6, 2,

    7, 9] arr1.reduce(0, combine: { $0 + $1 }) // 28 1 3 0 1 + = 1 + = 4 4 6 +
  67. ೣࣻ৬௿۽੷ $MPTVSF ௿۽੷ഝਊೞӝSFEVDF let arr1 = [1, 3, 6, 2,

    7, 9] arr1.reduce(0, combine: { $0 + $1 }) // 28 1 3 0 1 + = 1 + = 4 4 6 + = 10
  68. ೣࣻ৬௿۽੷ $MPTVSF ௿۽੷ഝਊೞӝSFEVDF let arr1 = [1, 3, 6, 2,

    7, 9] arr1.reduce(0, combine: { $0 + $1 }) // 28 1 3 0 1 + = 1 + = 4 4 6 + = 10 ߈ࠂ
  69. ೣࣻ৬௿۽੷ $MPTVSF ௿۽੷ഝਊೞӝSFEVDF let arr1 = [1, 3, 6, 2,

    7, 9] arr1.reduce(0, combine: +) // 28 ౲ো࢑੗بೣࣻ׮
  70. ௿ېझ৬ҳઑ୓ ௿ېझ ҳઑ୓ class Dog { var name: String? var

    age: Int? func simpleDescription() -> String { return "" \(self.name)" } } struct Coffee { var name: String? var size: String? func simpleDescription() -> String { return "☕ \(self.name)" } }
  71. ௿ېझ৬ҳઑ୓ ࢤࢿ੗ class Dog { var name: String? var age:

    Int? init() { self.age = 0 // ࣘࢿ ୡӝച } }
  72. ௿ېझ৬ҳઑ୓ ࢤࢿ੗ class Dog { var name: String // ч੉

    ޖઑѤ ೙ਃ var age: Int? init() { self.age = 0 } } ч੉೙ਃೠࣘࢿ੉ୡӝചغ૑ঋ਷҃਋ஹ౵ੌী۞ ! Return from initializer without initializing all stored properties
  73. ௿ېझ৬ҳઑ୓ ࢤࢿ੗ class Dog { var name: String = "੹ࣻৌ"

    var age: Int? init() { self.age = 0 } }  ࣘࢿਸ੿੄ೡٸୡӝച೧઱Ѣա
  74. ௿ېझ৬ҳઑ୓ ௿ېझ࢚ࣘ class Dog: Animal { var name: String? var

    age: Int override init() { self.age = 0 // ୡӥч ࢸ੿ super.init() // ࢚ਤ ௿ېझ ࢤࢿ੗ ഐ୹ // ৈӝࢲࠗఠ `self` ੽Ӕ оמ print(self.simpleDescription()) } func simpleDescription() -> String { return "" \(self.name)" } }
  75. ௿ېझ৬ҳઑ୓ $PNQVUFE1SPQFSUZ struct Hex { var hexString: String? { get

    { if let decimal = self.decimal { return String(decimal, radix: 16) } else { return nil } } set { if let newValue = newValue { self.decimal = Int(newValue, radix: 16) } else { self.decimal = nil } } } } HFUҗTFU
  76. ௿ېझ৬ҳઑ୓ ੍ӝ੹ਊࣘࢿ struct Hex { var hexCode: String? { if

    let hex = self.hexString { return "0x" + hex } return nil } } HFUఃਕ٘ࢤۚоמ
  77. ௿ېझ৬ҳઑ୓ 4UPSFE1SPQFSUZ੄ࣘࢿҙ଴ೞӝ EJE4FUҗXJMM4FU struct Hex { var decimal: Int? {

    willSet { print("\(self.decimal)ীࢲ \(newValue)۽ ч੉ ߄Չ ৘੿ੑפ׮.") } didSet { print("\(oldValue)ীࢲ \(self.decimal)۽ ч੉ ߄Շ঻णפ׮.") } } }
  78. ౚ೒ 5VQMF ↟ যځೠчٜ੄ޘ਺ ↟ Ҋ੿ػӡ੉ ୶оઁѢೡࣻহ਺  ↟ ஹ౵ੌఋ੐ী੗ܐഋ੉੿೧૗

    var coffeeInfo = ("ইݫܻ஠֢", 5100) coffeeInfo // (String, Int) coffeeInfo.0 // ইݫܻ஠֢ coffeeInfo.1 // 5100 coffeeInfo.1 = 5100
  79. ౚ೒ 5VQMF var namedCoffeeInfo = (coffee: "ইݫܻ஠֢", price: 5100) namedCoffeeInfo.coffee

    // ইݫܻ஠֢ namedCoffeeInfo.price // 5100 namedCoffeeInfo.price = 5100 ౚ೒ী੉ܴࠢ੉ӝ   ؀न౵ۄ޷ఠ੉ܴਵ۽੽Ӕоמ
  80. ౚ೒ 5VQMF let (coffee, price) = ("ইݫܻ஠֢", 5100) coffee //

    ইݫܻ஠֢ price // 5100 ౚ೒۽ৈ۞߸ࣻীч؀ੑೞӝ let (_, latteSize, lattePrice) = ("ۄڍ", "Venti", 5600) latteSize // Venti lattePrice // 5600
  81. ౚ೒ 5VQMF func coffeeInfoForName(name: String) -> (name: String, price: Int)?

    { let coffeeInfoList: [(name: String, price: Int)] = [ ("ইݫܻ஠֢", 5100), ("ۄڍ", 5600), ] for coffeeInfo in coffeeInfoList { if coffeeInfo.name == name { return coffeeInfo } } return nil } coffeeInfoForName("ইݫܻ஠֢")?.price // 5100 coffeeInfoForName("ীझ೐ۨࣗ")?.price // nil ౚ೒ਸ߈ജೞחೣࣻ
  82. ৌѢഋ &OVN &OVN੿੄ೞӝ enum Month: Int { case January =

    1 case February case March case April case May case June case July case August case September case October case November case December } ↟ ਗदч 3BX7BMVF ਸо ૑ח&OVN ↟ пп੄DBTFоࠗఠө ૑ܳо૗ 3BX5ZQF
  83. ৌѢഋ &OVN &OVNীೣࣻ੿੄ೞӝ enum Month: Int { case ... func

    simpleDescription() -> String { switch self { case .January: return "1ਘ" case .February: return "2ਘ" case ... return "..." case .December: return "12ਘ" } } }
  84. ৌѢഋ &OVN 3BX7BMVF۽&OVNࢤࢿೞӝ let october = Month(rawValue: 10) print(october) //

    Optional(Month.October) &OVNীࢲ੿੄غ૑ঋ਷ਗदчਸо૑Ҋࢤ ࢿೡ҃਋OJMਸ߈ജೞӝਤ೧0QUJPOBM
  85. ৌѢഋ &OVN 4USJOHਸਗदчਵ۽о૑ח&OVN enum IssueState: String { case Open =

    "open" case Closed = "closed" } let state = IssueState(rawValue: "open") print(state) // Optional(IssueState.Open)
  86. ৌѢഋ &OVN ਗदчਸо૑૑ঋח&OVN enum Spoon { case Dirt case Bronze

    case Silver case Gold } Ҷ੉೙ਃহח҃਋ࢎਊೞ૑ঋחѱ؊જणפ׮
  87. ৌѢഋ &OVN &OVNఋੑ୶ۿ enum Spoon { case Dirt case Bronze

    case Silver case Gold } let spoon: Spoon = .Gold func doSomething(spoon: Spoon) { // ... } doSomething(.Silver)
  88. ৌѢഋ &OVN ੋ੗ܳо૑ח&OVN enum Error { case InvalidParameter(String, String) case

    Timeout } let error = Error.InvalidParameter( "email", "੉ݫੌ ഋध੉ ৢ߄ܰ૑ ঋणפ׮." )
  89. ৌѢഋ &OVN ੋ੗ܳо૑ח&OVN ੋ੗ԁղয়ӝ JGDBTF if case .InvalidParameter(let field, let

    message) = error { print(field) // email print(message) // ੉ݫੌ ഋध੉ ৢ߄ܰ૑ ঋणפ׮. }
  90. ৌѢഋ &OVN ੋ੗ܳо૑ח&OVN ੋ੗ԁղয়ӝ TXJUDIDBTF switch error { case .InvalidParameter(let

    field, let message): print(field) // email print(message) // ੉ݫੌ ഋध੉ ৢ߄ܰ૑ ঋणפ׮. default: break }
  91. ৌѢഋ &OVN ୽Ѻ੸ࢎप 0QUJPOBM਷ࢎप&OVN੉׮ public enum Optional<Wrapped> { case None

    case Some(Wrapped) } OJM੉Ѣա чਸо૑ח҃਋оઓ੤ೞח&OVN
  92. ৌѢഋ &OVN ୽Ѻ੸ࢎप let age: Int? = 20 switch age

    { case .None: // `nil`ੋ ҃਋ print("ա੉ ੿ࠁо হणפ׮.") case .Some(let x) where x < 20: print("୒ࣗ֙") case .Some(let x) where x < 65: print("ࢿੋ") default: print("যܰन") }
  93. ೐۽ష௒ 1SPUPDPM struct Mail: Sendable { var from: String? var

    to: String func send() { print("Send a mail from \(self.from) to \(self.to)") } } ೐۽ష௒੸ਊೞӝ ௿ېझ৬ҳઑ୓ী੸ਊоמ
  94. ೐۽ష௒ 1SPUPDPM ೐۽ష௒࢚ࣘ protocol Messagable { var message: String? {

    get } } protocol Sendable: Messagable { // ... } 4FOEBCMFਸ੸ਊೞݶ.FTTBHBCMF਷੗ز੸ਊ
  95. ੊झబ࣌ &YUFOTJPO ੉޷੿੄ػఋੑী࢜۽਍ࣘࢿ੉աݫࢲ٘ܳ ୶оೡࣻ੓ب۾ೞחӝמ extension String { var length: Int

    { return self.characters.count } func reverse() -> String { return self.characters.reverse() .map { String($0) } .joinWithSeparator("") } }
  96. ੊झబ࣌ &YUFOTJPO &YUFOTJPOਵ۽1SPUPDPMӝࠄҳഅೞӝ protocol Sendable { var from: String? {

    get } var to: String { get } func send() } extension Sendable { func debug() { print("\(self.from) -> \(self.to)") } }