-
Notifications
You must be signed in to change notification settings - Fork 6
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
[Refactor] #625 - FeedViewModel로 FeedVC 리팩토링 #630
Conversation
이슈발생.. 했응께 좀만 다시 수정하고 다시 태그해드리겠습니다.. 그때 봐주세요..😇 @hyun99999 @L-j-h-c |
수정했습니다 확인부탁드립니다 🤓 @hyun99999 @L-j-h-c |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
워후 확실히 전보다 훨씬 보기 좋아졌네요!! 수고 많으셨습니다~~! 한 가지 궁금한 점은 뷰모델에 타입 프로퍼티를 두고 접근하신 부분이에요!! 보통은 뷰컨트롤러 안에 뷰모델을 두고 쓰는데, 그렇게 하면 뷰컨트롤러가 메모리에서 해제될 때 뷰모델도 해제될 수 있기 때문에... 그렇게 쓰지 않나 싶은데 이렇게 shared로 접근하는 건 처음봐서요!!
public lazy var firstList: [Record] = [] | ||
public lazy var secondList: [Record] = [] | ||
public lazy var thirdList: [Record] = [] | ||
public lazy var fourthList: [Record] = [] | ||
public lazy var fifthList: [Record] = [] | ||
public lazy var sixthList: [Record] = [] | ||
public lazy var seventhList: [Record] = [] | ||
public lazy var eighthList: [Record] = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
배열 안에 배열을 넣는 방법은 어떨까요? 그러면 removeAllData나 setDataList 같은 메서드들도 길이가 많이 줄어들 것 같은데.. 가독성을 위해서 뭐가 더 좋은지는 잘 모르겟서여...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
왐맘마 해보겠슴니다
|
||
switch indexPath.section { | ||
case 0: | ||
print("✈️ firstList - \(firstList[indexPath.item])") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
난 여행을 떠나.
switch indexPath.section { | ||
case 0: | ||
targetList = firstList | ||
case 1: | ||
targetList = secondList | ||
case 2: | ||
targetList = thirdList | ||
case 3: | ||
targetList = fourthList | ||
case 4: | ||
targetList = fifthList | ||
case 5: | ||
targetList = sixthList | ||
case 6: | ||
targetList = seventhList | ||
default: | ||
targetList = eighthList | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
배열 안에 배열을 넣어주면 targetList = list[indexPath.section]
처럼 할 수 있을 것 같아서여...
일단 shared로 접근한건 제가 저 친구를 싱글톤 패턴의 Manager 파일을 참조해서 만들다가 그런 것 같아여..! 여기서 갖고 있는 데이터가 다른 뷰컨에서 쓰일 일이 지금은 없긴 하지만,, 만일 나중에라도 다른 곳에서 수정될 일이 생긴다면 메모리 관리하는 면에서도 최초 한번 하나의 인스턴스로 만들어두고 같은 데이터를 수정한다는 점에서 두는 것도 나뿌지 않을랑가 싶어요 .. |
@L-j-h-c @hyun99999 깔꼼하고 뿌듯한 기분은 제가 오랜만에 개발을 해서일까여 .. 🥹 |
오오오 코드가 확실히 줄었네요...이걸 이렇게 뚝딱 해버리시다니 멋져요!! 앱을 점점 Develop 시키면서 규모도 커지고 하면 유지보수를 해야할 일이 많아질 것 같은데 큰맘먹고 ViewModel로 리팩하신 부분...멋있습니다..난 언제 보관함 리팩하냐고 아 ㅋㅋ |
view model 에 대해서 싱글톤 패턴 사용 요 글도 참고해 보면 좋을거 같아요!
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
view model 로 분리해서 확실히 비지니스 로직을 확인하기 너무 좋고 유지보수도 좋을 것 같습니다!
멋진 코드 보구 가네용
클린코드 책... 조심스럽게 추천드리고 아니면 swift 에 적용해서 요약해서 블로그에 정리해둔 글도 많으니 보셔도 좋을 듯합니다! 이게 좀 더 좋지 않을까? 라는 애매했던 생각에 근거를 가질 수 있었어요!
func removeAllData() { | ||
dateList.removeAll() | ||
dayList.removeAll() | ||
for i in 0...7 { | ||
contentList[i].removeAll() | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
7이라는 값도 상수 이기 때문에 유지보수에 힘들다구 생각해요!
contentList 의 갯수를 활용하면 좋을 것 같습니당!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오우 앗차차 생각 못했던 부분을 정확하게 찝어주시네욜 ..
func setFeedsList(isScroll: Bool) { | ||
if isScroll { | ||
self.feeds.append(contentsOf: self.newFeeds) | ||
} else { | ||
self.feeds = self.newFeeds | ||
} | ||
|
||
if feeds.count >= feedCountSize { | ||
isFirstScroll = false | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
요즘 클린코드 책을 읽구 있는데 이렇게 bool 값을 넘기는 flag 역할을 하는 인수는 좋지 못하다구 하더라구요! 함수는 무조건 하나의 역할만을 해야하는데 결국 참일경우에는 a경우를 거짓일 경우는 b일 경우를 하는 거니까 그렇지 못하다는 것이죵!
그래서 isScroll 파라미터가 참과 거짓인 경우를 나누는 함수가 더 좋다는 것으로 적용이 가능할 것 같아요!
bool 자료형을 가진 파라미터에 대해서는 위의 내용을 고려하셔 보는 것도 좋을 것 같습니당
위의 언급한대로 작성하게 되면 장점은 이 함수가 true 일때 무엇을 하는지 false 일때 무엇을 하는지 함수명에서 알 수 있다는 것이 될거 같습니당
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오 .. 그럼 bool 자료형의 파라미터를 받기보다는
애초에 true인 경우의 함수와 false인 경우의 함수를 분리해서, 함수 내에서는 조건에 따라 나누지 않고 딱 한가지 경우일때의 코드를 실행하게 되는 ,,
이런거 말씀하신게 맞을까여?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
넹 정확해요! 뷰에서 isScroll 이 참,거짓인 경우에 활용하게 되면 참,거짓인 경우에 어떤 일을 하는지 알 수 있다는 것을 말하고 싶었어요
그렇게 되면 어떻게 함수명을 지어야하는 지에 머리가 아파오는데 저라면 더해주는 함수와 대입해주는 함수명으로 설정해줄 것 같네용
func getDataList(indexPath: IndexPath) -> Record { | ||
var dataList: Record | ||
dataList = contentList[indexPath.section][indexPath.item] | ||
return dataList | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return contentList[indexPath.section][indexPath.item]
도 좋은 코드가 될 것 같은데 혹시 어떤 점을 우려해서 작성하셨을까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아고 .. 지금 보니까 불필요해보이는데,, 리팩하면서 코드를 옮기는 과정에서 놓쳤나 .. 싶습니다..
바로 리턴하도록 수정하겠습니다!
Merge branch 'develop' of https://github.com/TeamSparker/Spark-iOS into refactor/TeamSparker#625
@L-j-h-c @hyun99999 코드리뷰 반영해서 전부 수정했슴니다 머지할게여 ! |
🔥Pull requests
⛳️ 작업한 브랜치
👷 작업한 내용
데이터를 담는 리스트와 리스트를 수정하는 부분은 최대한 다 FeedViewModel 로 옮겨서 그 안에서만 수정하도록 했습니다...
🚨참고 사항
생각보다 많이 엉망이었던 것 같아요..
일단 목표는 리스트를 수정하는 부분은 전부 viewModel에서만 처리하도록 하는 것이었고 아마.. 전부 수정한 것 같습니다..
근데 이게 맞는지도 확실히 모르겠고 , 보다보니 너어무 리스트가 많은 것 같아서 이것도 바꾸긴 해야할 것 같은데 ..
일단 더 좋은 방법이 있다면 .. 듣고자 먼저 풀리퀘 올려봅니다 .. 질문.. 태클.. 조언 .. 전부 다 받습니다 ..!
📟 관련 이슈