๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐ŸŽ iOS/Swift

[Swift] 1. ๋ช…๋ช…๋ฒ•, ์ฝ˜์†” ๋กœ๊ทธ, ๋ฌธ์ž์—ด ๋ณด๊ฐ„๋ฒ•

1. ๋ช…๋ช…๋ฒ•

Swift์—์„œ๋Š” ์ด๋ฆ„์„ ์ง€์„ ๋•Œ ์นด๋ฉœ์ผ€์ด์Šค๋ฅผ ์‚ฌ์šฉํ•˜๊ณ , ๋ชจ๋“  ๋Œ€์†Œ๋ฌธ์ž๋ฅผ ๊ตฌ๋ถ„ํ•œ๋‹ค.

 

Lower Camel Case(์†Œ๋ฌธ์ž๋กœ ์‹œ์ž‘)

: fuction, method, variable, constant

ex) viewDidLoad, userTable ๋“ฑ

 

Upper Camel Case(๋Œ€๋ฌธ์ž๋กœ ์‹œ์ž‘)

: type(class, struct, enum, extension…)

ex) Person, Point, Week ๋“ฑ

2. ์ฝ˜์†”๋กœ๊ทธ

print ํ•จ์ˆ˜ : ๋‹จ์ˆœ ๋ฌธ์ž์—ด ์ถœ๋ ฅ

dump ํ•จ์ˆ˜ : ์ธ์Šคํ„ด์Šค์˜ ์ž์„ธํ•œ ์„ค๋ช…(description ํ”„๋กœํผํ‹ฐ)๊นŒ์ง€ ์ถœ๋ ฅ

class Person {
    var name: String = "TechYeon"
    var age: Int = 10
}
let techYeon: Person = Person()

print(techYeon)
dump(techYeon)
---------------- ์ถœ๋ ฅ -----------------
__lldb_expr_3.Person
โ–ฟ __lldb_expr_3.Person #0
  - name: "techYeon"
  - age: 10

3. ๋ฌธ์ž์—ด ๋ณด๊ฐ„๋ฒ• (String Interpolation)

ํ”„๋กœ๊ทธ๋žจ ์‹คํ–‰ ์ค‘ ๋ฌธ์ž์—ด ๋‚ด์— ๋ณ€์ˆ˜ ๋˜๋Š” ์ƒ์ˆ˜์˜ ์‹ค์งˆ์ ์ธ ๊ฐ’์„ ํ‘œํ˜„ํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉ.

 

\(๋ณ€์ˆ˜๋‚˜ ์ƒ์ˆ˜)

let name: String = “techYeon”

print(“my name is \(name)”)
---------------- ์ถœ๋ ฅ -----------------
my name is techYeon

 

 

728x90
๋ฐ˜์‘ํ˜•