ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [Stanford Lecture] Method & Property
    Stanford iOS Lecture 2020. 4. 14. 12:58


    # Parameters names
    All parameters to all functions have an internal name and an external name
    The internal name is the name of the local variable you use inside the method
    The external name is what callers use when they call the method
    외부이름을 사용하지 않으려면 언더바(_)를 넣어줄 수도 있음.
    You can put _ if you don’t want callers to use an external name at all for a given parameter
    This is the default for the first parameter (except in initializers!)
    외부이름을 지정하지 않으면 내부이름이 기본값
    For other (not the first) parameters, the internal name is, by default, the external name



    메소드는 오버라이드 가능
    Obviously you can override methods/properties in yours superclass
    Precede your func or var with the keyword override

    Final 키워드를 사용하면 서브클래싱 X
    A method can be marked final which will prevent subclasses from being able to override classes can also be marked final
    
Both types and instances can have methods/properties


    # Properties
    Property Observers
    You can observe changes to any property with willSet and didSet
    willSet : 설정되기 전
    didSet : 설정된 후
    저장 프로퍼티나 상속된 프로퍼티에서 사용 가능


    # Lazy Initialization
    A lazy property does not get initialized until someone accesses it
    You can allocate an object, execute a closure, or call a method if you want
    lazy는 변수간 의존성에서 생기는 문제를 극복하는 데에도 쓰일 수 있음.
    (다른 변수에 의존하고 있는 변수 하나가 있다고 하고, 둘 중 하나를 lazy로 만들어도 괜찮을 거라는 얘기)

Designed by Tistory.