Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Swift] 타입 메서드 #47

Closed
seungchan2 opened this issue May 17, 2022 · 1 comment
Closed

[Swift] 타입 메서드 #47

seungchan2 opened this issue May 17, 2022 · 1 comment

Comments

@seungchan2
Copy link
Owner

seungchan2 commented May 17, 2022

타입 메서드

  • 메서드이기 때문에 타입에 메모리 공간이 할당되어 있지 않음 -> 인스턴스 메서드에서 설명한 부분

  • 인스턴스에 속한 속성이 아니고, 타입자체에 속한 속성이기에 내/외부에서 Type.method( )로 접근해야함

  • 메서드 실행시, 스택프레임을 만들고 타입 데이터를 사용 ➡ 메서드 종료시 스택프레임 사라짐 -> 인스턴스 메서드에서 설명한 부분

  • 타입에 해당하는 보편적인 동작의 경우

스크린샷 2022-05-17 오후 5 13 54

Int.random(in: 1...100)

static

상속시 재정의 불가
스크린샷 2022-05-17 오후 4 31 01

class

상속시 재정의 가능
스크린샷 2022-05-17 오후 4 27 51

가장 큰 장점으로는 타입의 메서드에 직접 접근하기 때문에 ARC 걱정이 없을 것 같음

@seungchan2
Copy link
Owner Author

class, static 둘 다 상속이 가능함

차이점은 상속 후, 재정의 차이임

헷갈리지 말기

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant