๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป iOSun
article thumbnail

๊ตฌ์กฐ์ฒด์™€ ํด๋ž˜์Šค (Structures and Classes)

๊ณตํ†ต์ 

  • ๊ฐ’์„ ์ €์žฅํ•  ํ”„๋กœํผํ‹ฐ๋ฅผ ์„ ์–ธํ•  ์ˆ˜ ์žˆ๋‹ค.
  • ํ•จ์ˆ˜์  ๊ธฐ๋Šฅ์„ ํ•˜๋Š” ๋ฉ”์„œ๋“œ๋ฅผ ์„ ์–ธ ํ•  ์ˆ˜ ์žˆ๋‹ค.
  • ๋‚ด๋ถ€ ๊ฐ’์—. ์„ ์‚ฌ์šฉํ•˜์—ฌ ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋‹ค.
  • ์ƒ์„ฑ์ž๋ฅผ ์‚ฌ์šฉํ•ด ์ดˆ๊ธฐ ์ƒํƒœ๋ฅผ ์„ค์ •ํ•  ์ˆ˜ ์žˆ๋‹ค.
  • extension์„ ์‚ฌ์šฉํ•˜์—ฌ ๊ธฐ๋Šฅ์„ ํ™•์žฅํ•  ์ˆ˜ ์žˆ๋‹ค.
  • Protocol์„ ์ฑ„ํƒํ•˜์—ฌ ๊ธฐ๋Šฅ์„ ์„ค์ •ํ•  ์ˆ˜ ์žˆ๋‹ค.

Class (ํด๋ž˜์Šค)

class VideoMode {
    var resolution = Resolution()
    var interlaced = false
    var frameRate = 0.0
    var name: String?
}

let tenEighty = VideoMode()
let alsoTenEighty = tenEighty

if tenEighty === alsoTenEighty {
    print("tenEighty and alsoTenEighty refer to the same VideoMode instance.")
}
  • ์ฐธ์กฐ ํƒ€์ž…
  • ARC๋กœ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ๊ด€๋ฆฌ
  • ์ƒ์†์ด ๊ฐ€๋Šฅ
  • deinit์„ ์‚ฌ์šฉํ•˜์—ฌ ํด๋ž˜์Šค ์ธ์Šคํ„ด์Šค์˜ ๋ฉ”๋ชจ๋ฆฌ ํ• ๋‹น์„ ํ•ด์ œํ•  ์ˆ˜ ์žˆ๋‹ค.
  • ๋™์ผ ์ธ์Šคํ„ด์Šค (Identical to) (===) & ๋™์ผํ•˜์ง€ ์•Š์€ ์ธ์Šคํ„ด์Šค (Not identical to) (!==)

 

Struct (๊ตฌ์กฐ์ฒด)

struct Resolution {
    var width = 0
    var height = 0
}
let a = Resolution(width: 640, height: 480)
let b = a
  • ๊ฐ’ ํƒ€์ž…
  • ๊ฐ™์€ ๊ตฌ์กฐ์ฒด๋ฅผ ์—ฌ๋Ÿฌ ๊ฐœ์˜ ๋ณ€์ˆ˜์— ํ• ๋‹นํ•œ ๋’ค ๊ฐ’์„ ๋ณ€๊ฒฝ์‹œํ‚ค๋”๋ผ๋„ ๋‹ค๋ฅธ ๋ณ€์ˆ˜์— ์˜ํ–ฅ์„ ์ฃผ์ง€ ์•Š๋Š”๋‹ค. (๊ฐ’ ์ž์ฒด๋ฅผ ๋ณต์‚ฌ)
  • ์ž๋™์ ์œผ๋กœ ์ƒ์„ฑ๋œ memberwise intializer ๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค.
profile

๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป iOSun

@iosun

ํฌ์ŠคํŒ…์ด ์ข‹์•˜๋‹ค๋ฉด "์ข‹์•„์š”โค๏ธ" ๋˜๋Š” "๊ตฌ๋…๐Ÿ‘๐Ÿป" ํ•ด์ฃผ์„ธ์š”!

profile on loading

Loading...