Skip to content

[Swift] 서브스크립트 #48

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

Closed
seungchan2 opened this issue May 17, 2022 · 0 comments
Closed

[Swift] 서브스크립트 #48

seungchan2 opened this issue May 17, 2022 · 0 comments
Assignees
Labels

Comments

@seungchan2
Copy link
Owner

Subscripts

인스턴스의 서브스크립트

  • 함수의 구현이 특별한 키워드인 subscript로 명명됨

  • 메서드이기 때문에 인스턴스에 메모리 공간이 할당되어 있지 않음

  • ⭐️ 메서드 접근 시, 인스턴스 이름으로 접근 해야함 ➡ instance[파라미터] (특별한 형태)

  • 메서드 실행시, 스택프레임을 만들고 필요한 데이터를 사용 ➡ 메서드 종료시 스택프레임 사라짐

  • 파라미터 2개이상도 구현가능하긴 함(아규먼트 레이블을 따로 사용 안함)

    
 

    (계산 속성과 형태는 유사 - getter/setter)

  • get블록만 선언하면 읽기전용(read-only) 계산 속성이 됨 (필수 구현)

  • set블록은 선택적으로 구현할 수 있음

  • set블록에서 기본 파라미터 newValue가 제공됨(직접 파라미터 이름 설정도 가능)

스크린샷 2022-05-17 오후 5 12 27

@seungchan2 seungchan2 self-assigned this May 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant