Conversation
Co-authored-by: Bambu <byrr113@gmail.com>
devBambu
reviewed
Jan 9, 2026
Comment on lines
+140
to
+154
| for i in introducibleArray { | ||
| switch i { | ||
| case is Cat: | ||
| let cat = i as! Cat | ||
| print(cat.meow()) | ||
| case is Dog: | ||
| let dog = i as! Dog | ||
| print(dog.bark()) | ||
| case is Robot: | ||
| let robot = i as! Robot | ||
| print(robot.charge()) | ||
| default: | ||
| print("해당없음") | ||
| } | ||
| } |
Collaborator
There was a problem hiding this comment.
저는 if문으로 처리했었는데 switch문이 훨씬 직관적으로 이해하기 쉬운 것 같네요! 참고하고 갑니당ㅎㅎ
Comment on lines
+10
to
+13
| protocol Introducible { | ||
| var name: String { get set } | ||
| func introduce() -> String | ||
| } |
Collaborator
There was a problem hiding this comment.
name 프로퍼티를 { get set }으로 선언하신 이유가 있으실지 궁금합니다..!
프로토콜을 채택한 객체 내에서 name을 따로 연산 프로퍼티로 사용하거나 하시진 않은 것 같아 여쭈어봅니당..ㅎㅎ
프로퍼티 선언 시 { get set }으로 선언을 하면 프로토콜을 채택한 객체에서 해당 프로퍼티는 var로만 선언 가능하여 구현의 자유도가 떨어진다고 하더라고요.(let으로 선언 불가능) 좀더 자유로운 구현을 위해 제한 사항을 덜어주는 게 어떨까 말씀드려봅니다..!
Collaborator
There was a problem hiding this comment.
앗 예슬님도 프로토콜 채택 객체들 class로 선언해주신 걸로 확인했습니당...!! 저도 예슬님 코드처럼 수정했어요...😂😂
클래스에 채택하면 프로토콜 타입으로 인스턴스 생성 시 name 값 변경이 불가능하네요.. 하핳 위의 제 의견은 무시해주십셔..👉👈
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.