hello swift 1/5 - basic1

20
Welcome to Swift 1/5

Upload: cody-yun

Post on 10-May-2015

1.578 views

Category:

Technology


3 download

DESCRIPTION

Hello Swift 2/5 http://www.slideshare.net/ssusere2153e/hello-swift-02

TRANSCRIPT

Page 1: Hello Swift 1/5 - Basic1

Welcome to Swift 1/5

Page 2: Hello Swift 1/5 - Basic1

constant

let name = "Cody" let isMan = true let height = 171.0 let weight : Int = 69.0 let familyName : String = "Yun" let age = 32 !age = 33

Page 3: Hello Swift 1/5 - Basic1

constant

let name = "Cody" let isMan = true let height = 171.0 let weight : Int = 69.0 let familyName : String = "Yun" let age = 32 !age = 33Cannot assign to ‘let’ value ‘age’

Page 4: Hello Swift 1/5 - Basic1

variable

var company = "KAKAO" company = "Daum Kakao" !var product : String = "KakaoTalk" product = 10 !!!var doubleValue : Double = 30.0 doubleValue = 40 !var intValue : Int = 50 intValue = 30.0 !

Page 5: Hello Swift 1/5 - Basic1

variable

var company = "KAKAO" company = "Daum Kakao" !var product : String = "KakaoTalk" product = 10 !!!var doubleValue : Double = 30.0 doubleValue = 40 !var intValue : Int = 50 intValue = 30.0 !

Cannot covert the expression’s type ‘()’ to ‘String’

Cannot covert the expression’s type ‘()’ to ‘Int’

Page 6: Hello Swift 1/5 - Basic1

merge variable

let korea = 2 let algeria = 4 !let scoreLabel = String(korea)+":"+String(algeria) let resultLabel = "한국vs알제리 결과는 \(korea):\(algeria) 입니다."

Page 7: Hello Swift 1/5 - Basic1

array

var shoppingList = ["milk","soda","tomato"] shoppingList[0] = "apple" shoppingList += "pasta" !let brandList = ["nike","abidas","newbalance"] brandList[1] = "adidas" brandList.removeAtIndex(0) !!!!var emptyArray = String[]()

Page 8: Hello Swift 1/5 - Basic1

array

var shoppingList = ["milk","soda","tomato"] shoppingList[0] = "apple" shoppingList += "pasta" !let brandList = ["nike","abidas","newbalance"] brandList[1] = "adidas" brandList.removeAtIndex(0) !!!!var emptyArray = String[]()

Immutable value of type 'Array<String>' only has mutating members named 'removeAtIndex'

Page 9: Hello Swift 1/5 - Basic1

dictionary

var names = [ "yun":"cody", "lee":"kimin", ] names["yun"] names["yun"] = "경옥" names["won"] = "bin" !let programmingAndChannel = [ "무한도전":"MBC", "1박2일":"KBS", "런닝맨":"SBS", ] !programmingAndChannel["무한도전"] = "SBS" !!!!var emptyDictionary = Dictionary<String,Int>()

Page 10: Hello Swift 1/5 - Basic1

dictionary

var names = [ "yun":"cody", "lee":"kimin", ] names["yun"] names["yun"] = "경옥" names["won"] = "bin" !let programmingAndChannel = [ "무한도전":"MBC", "1박2일":"KBS", "런닝맨":"SBS", ] !programmingAndChannel["무한도전"] = "SBS" !!!!var emptyDictionary = Dictionary<String,Int>()

Could not find an overload for 'subscript' that accepts the supplied arguments

Page 11: Hello Swift 1/5 - Basic1

for

var shoppingList = ["milk","soda","tomato"] !var count = 0 for item in shoppingList { ++count } count

Page 12: Hello Swift 1/5 - Basic1

for

var shoppingList = ["milk","soda","tomato"] !var count = 0 for item in shoppingList { ++count } count

Page 13: Hello Swift 1/5 - Basic1

for

var shoppingList = ["milk","soda","tomato"] !var count = 0 for item in shoppingList { ++count } count !// Array Counting은 loop없이도 가능합니다 shoppingList.count

Page 14: Hello Swift 1/5 - Basic1

switch

var shoppingList = ["milk","soda","tomato","apple"] !for item in shoppingList { switch item { case "milk": "유재품" case "soda": "음료" case "tomato","apple": "과일/야채" } }Switch must be exhaustive, consider adding a default clause

Page 15: Hello Swift 1/5 - Basic1

switch

var shoppingList = ["milk","soda","tomato","apple"] !for item in shoppingList { switch item { case "milk": "유재품" case "soda": "음료" case "tomato","apple": "과일/야채" default: "Can not find." } }

Page 16: Hello Swift 1/5 - Basic1

if

var isMan = false if isMan==true { "남성입니다" } !var myName: String if myName==nil { "myName에 아무런 값도 입력되지 않았습니다." } !== is unavailable: Cannot compare a String to nil

Page 17: Hello Swift 1/5 - Basic1

if

var isMan = false if isMan==true { "남성입니다" } !var myName: String? if myName==nil { "myName에 아무런 값도 입력되지 않았습니다." }

Page 18: Hello Swift 1/5 - Basic1

참고 : 개발가이드 문서

https://developer.apple.com/library/prerelease/ios/documentation/ swift/conceptual/swift_programming_language/TheBasics.html

Page 19: Hello Swift 1/5 - Basic1

1. 확실히 쉬운 문법 2. 플레이 그라운드의 잦은 크래쉬 3. 서버사이드에서 Swift? 4. 세미콜론;과 if/for/switch문에서의 괄호() 5. 아직은 Beta 하지만, 앞으로는?

참고 : 생각해 볼 내용

Page 20: Hello Swift 1/5 - Basic1

감사합니다.