Skip to content

Conversation

@Limwin94
Copy link
Member

item50에 대한 초안을 작성해보았습니다.

기술적인 부분 보다는 방어적 복사본을 언제 만들고 왜 만들어야 하는지에 대한 내용이 중점인것 같았습니다.

  • inout도 다루는게 맞을까요?

Copy link
Member

@ehgud0670 ehgud0670 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수고하셨습니다!!! 💯💪
글 덕분에 struct 의 장점을 또 한번 알게 되네요 👍👍
그럼 제가 피드백 드린거 확인해주시고 반영해주세요~ (코드 위주로 살짝 수정해보았습니다)

Comment on lines +52 to +59
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class Person {
var isHungry: Bool = true
}
let lin = Person()
let anotherPerson = lin
print(anotherPerson.isHungry) //true
class Person {
var isHungry: Bool = true
}
let lin = Person()
let anotherPerson = lin
lin.isHungry = false
print(lin.isHungry) //false
print(anotherPerson.isHungry) //false

=> 이렇게 내용 추가하면 참조타입의 얕은 복사에 대해 더 설명될 것 같습니다. 👍 아래 코드 보고 추가해봤어요.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저도 이렇게 변경이 되어야 할 것 같아요 ㅎㅎ

Comment on lines +11 to +12
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private var start: Date
private var end: Date
private let start: Date
private let end: Date

=> 사소한건데 자바(final)처럼 let 으로 변경 부탁드립니다.

Comment on lines +43 to +46
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

와우 역시 Swift가 대단하네요. Struct라는 다른 수단이 있으니 말이죠 😎

Comment on lines +69 to +83
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class Person: NSCopying {
func copy(with zone: NSZone? = nil) -> Any {
let copy = Person()
copy.isHungry = self.isHungry
return copy
}
}
let lin = Person()
let anotherPerson = lin.copy()
lin.isHungry = false
print(lin.isHungry) // false
print(anotherPerson.isHungry) // true
class Person: NSCopying {
var isHungry: Bool = true
func copy(with zone: NSZone? = nil) -> Any {
let copy = Person()
copy.isHungry = self.isHungry
return copy
}
}
let lin = Person()
let anotherPerson: Person = lin.copy() as! Person
lin.isHungry = false
print(lin.isHungry) // false
print(anotherPerson.isHungry) // true

해당 코드 컴파일 에러나서 (because of isHungry, Any) 에러안나도록 코드 수정하였습니다.

@ehgud0670 ehgud0670 removed the Jason label May 19, 2021
@ehgud0670
Copy link
Member

pr 내용을 보고 추가로 코멘트 드리면 inout은 안 다뤄도 될 것 같습니다!
자바 코드를 보면 객체의 내부로 입력인수로서 인수를 넘기기만 하지 출력인수, 즉 inout은 사용하지 않네요.

Copy link
Member

@delmaSong delmaSong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

덕분에 NSCopying에 대해 알아갑니다 ㅎㅎ Jason이 제안해주신대로 수정부탁드립니다!
그리고 REAMDE도 수정해주셔요

Comment on lines +52 to +59
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저도 이렇게 변경이 되어야 할 것 같아요 ㅎㅎ

@delmaSong delmaSong removed the Delma label May 30, 2021
Copy link
Member

@dev-Lena dev-Lena left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

방어적 복사에 대한 글 잘 읽었습니다. 델마와 제이슨이 피드백 준 부분을 수정하면 더 좋을 것 같네요! 고생하셨습니다 👏🏻 🤓

@dev-Lena dev-Lena removed the Lena label May 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants