2์ผ์ฐจ: 100DaysOfSwift๐Ÿš€

2458 ๋‹จ์–ด swiftios100daysofcodebeginners
2์ผ์ฐจ :

๋ฐฐ์—ด, ์ง‘ํ•ฉ, ํŠœํ”Œ, ์‚ฌ์ „ ๋ฐ ์—ด๊ฑฐํ˜•



1.Swift์˜ ๋ฌธ์ž์—ด, ์ •์ˆ˜, ๋ถ€์šธ ๋ฐ Doubles๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋‹จ์ผ ๊ฐ’์„ ์ž„์‹œ๋กœ ์ €์žฅํ•  ์ˆ˜ ์žˆ์ง€๋งŒ ๋งŽ์€ ๊ฐ’์„ ์ €์žฅํ•˜๋ ค๋Š” ๊ฒฝ์šฐ ๋Œ€์‹  ๋ฐฐ์—ด์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ๋งŽ์Šต๋‹ˆ๋‹ค.

๋ฐฐ์—ด์€ ์ •๋ ฌ๋œ ๋ชฉ๋ก์— ๋™์ผํ•œ ์œ ํ˜•์˜ ๊ฐ’์„ ์ €์žฅํ•ฉ๋‹ˆ๋‹ค.

var Names: [String] = ["Saurabh","Sachin"]


๋ฐฐ์—ด ์œ„์น˜๋Š” 0๋ถ€ํ„ฐ ์‹œ์ž‘ํ•˜๋ฏ€๋กœ sachin์„ ์ฝ์œผ๋ ค๋ฉด

Name[1]


  • ์ง‘ํ•ฉ์€ ๊ณ ์œ ํ•œ ๊ฐ’์˜ ์ •๋ ฌ๋˜์ง€ ์•Š์€ ๋ชจ์Œ์ž…๋‹ˆ๋‹ค.

  • var favoriteGenres: Set<String> = ["Rock", "Classical", "Hip hop"]
    
    or 
    
    var favoriteGenres: Set = ["Rock", "Classical", "Hip hop"]
    
    
    


    ์„ธํŠธ์— ์ค‘๋ณต ํ•ญ๋ชฉ์„ ์‚ฝ์ž…ํ•˜๋ ค๊ณ  ํ•˜๋ฉด ์ค‘๋ณต ํ•ญ๋ชฉ์ด ๋ฌด์‹œ๋ฉ๋‹ˆ๋‹ค.

    var favoriteGenres: Set = ["Rock", "Classical", "Hip hop","Rock","Classical"]
    


    ์–ด๋ ˆ์ด์—์„œ ์„ธํŠธ๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

    var Names= set(["Saurabh","Sachin"])
    


    3. ํŠœํ”Œ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์—ฌ๋Ÿฌ ํ•ญ๋ชฉ์„ ๊ด„ํ˜ธ ์•ˆ์— ๋„ฃ์–ด ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค.

    var name = (first: "Taylor", last: "Swift")
    
    


    ํŠœํ”Œ์—์„œ ํ•ญ๋ชฉ์— ์•ก์„ธ์Šค

    name.0
    or
    name.first
    


    ํŠœํ”Œ์„ ๋งŒ๋“  ํ›„์—๋Š” ํŠœํ”Œ ๋‚ด๋ถ€์˜ ๊ฐ’์„ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ์ง€๋งŒ ๊ฐ’์˜ ์œ ํ˜•์€ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ์ด๋ฆ„์„ (์ฒซ ๋ฒˆ์งธ: "Justin", ๋‚˜์ด: 25)๋กœ ๋ณ€๊ฒฝํ•˜๋ ค๊ณ  ํ•˜๋ฉด ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค.

    4. ์‚ฌ์ „์€ ๋™์ผํ•œ ์œ ํ˜•์˜ ํ‚ค์™€ ๋™์ผํ•œ ์œ ํ˜•์˜ ๊ฐ’ ๊ฐ„์˜ ์—ฐ๊ฒฐ์„ ์ •์˜๋œ ์ˆœ์„œ ์—†์ด ์ปฌ๋ ‰์…˜์— ์ €์žฅํ•ฉ๋‹ˆ๋‹ค.

    var someDict:[Int:String] = [1:"One", 2:"Two", 3:"Three"]
    


    5.Swift ์„ค๋ช…์„œ์— ๋”ฐ๋ฅด๋ฉด ์—ด๊ฑฐํ˜•์€ "๊ด€๋ จ ๊ฐ’ ๊ทธ๋ฃน์— ๋Œ€ํ•œ ๊ณตํ†ต ์œ ํ˜•์ด๋ฉฐ ์ฝ”๋“œ ๋‚ด์—์„œ ์œ ํ˜•์ด ์•ˆ์ „ํ•œ ๋ฐฉ์‹์œผ๋กœ ํ•ด๋‹น ๊ฐ’์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•ฉ๋‹ˆ๋‹ค."๋กœ ์ •์˜๋ฉ๋‹ˆ๋‹ค.
    enumClick Here..์— ๋Œ€ํ•œ ์ž์„ธํ•œ ๋‚ด์šฉ์€

    6. ๋นˆ ์ปฌ๋ ‰์…˜ ๋งŒ๋“ค๊ธฐ
    ๋ฐฐ์—ด, ์ง‘ํ•ฉ ๋ฐ ์‚ฌ์ „์€ ๊ฐ’์„ ํ•œ ๊ณณ์— ๋ชจ์œผ๊ธฐ ๋•Œ๋ฌธ์— ์ปฌ๋ ‰์…˜์ด๋ผ๊ณ  ํ•ฉ๋‹ˆ๋‹ค.
    ๋นˆ ์‚ฌ์ „

    var teams = [String: String]()
    


    ์šฐ๋ฆฌ๋Š” ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค

    teams["Paul"] = "Red"
    


    ๋นˆ ๋ฐฐ์—ด

    var results = [Int]()
    


    ๋นˆ ์„ธํŠธ

    var words = Set<String>()
    var numbers = Set<Int>()
    

    ์ข‹์€ ์›นํŽ˜์ด์ง€ ์ฆ๊ฒจ์ฐพ๊ธฐ