GithubHelp home page GithubHelp logo

Step5 Feedback about swift-cardgameapp HOT 6 OPEN

jinios avatar jinios commented on August 25, 2024
Step5 Feedback

from swift-cardgameapp.

Comments (6)

jinios avatar jinios commented on August 25, 2024

Stackable 프로토콜 추상화

func stackUp(newCard: Card?, newCards: [Card]?, column: Int) {
        guard let card = newCard else {return}
        foundations[column].push(newCard: card)
    }
  • newCards 변수가 필요한건가요? 인터페이스가 적절하지 않으면 추상화가 잘못된건 아닐까여?
  • 차라리 메소드를 분리해서 만드는게 어땠을까요?
    • Stackable프로토콜을 카드 doubleTap과 panGesture인 경우 동시에 사용하려다보니 파라미터에 타입 [Card]을 추가했어야했다. 하지만 이보다는 다른 프로토콜을 만들고 수행하는 제스쳐에 따라서 뷰가 다른 프로토콜 타입으로 추상화되어야 한다.

from swift-cardgameapp.

jinios avatar jinios commented on August 25, 2024

FrameCalculator

 func cardIndexInStack(originY: CGFloat) -> Int {
        return Int(originY / 15.0)
 }
  • 이 클래스 함수들은 인스턴스 변수가 없어서 static 한 유틸리티 함수들인 것 같아요.
  • 이런 경우는 혹시 첫번째 매개변수로 넘어오는 타입과 관련이 있거나 그 타입을 확장하는 걸로 해결할 수 있는지 고민해보세요.
    • 예시 코드는 매개변수 타입을 확장하는 것으로 해결할 수 있는 것으로 보인다. 다른 경우에도 확장을 통해서 변경 할 수 있는지 알아보기

from swift-cardgameapp.

jinios avatar jinios commented on August 25, 2024

Animation에 easing 적용

참고링크- A look at UIView Animation Curves

from swift-cardgameapp.

jinios avatar jinios commented on August 25, 2024

프로토콜 선언

Question:

  • 해당 프로토콜을 채택한 객체에 의존하는 대표적인 클래스 윗 부분에 선언하는 경우도 많이 있습니다.
    이렇게 프로토콜을 모아놓는 것과 관련있는 객체에 프로토콜을 선언하는 방법 차이를 정리해보세요.

Answer:

  • 결과적으로 프로토콜을 클래스 바로 윗부분에 선언하는 방법, 프로토콜을 모아놓는 방법 모두 사용합니다. 제가 둘 중 어떤 방법을 선택하는지는 가독성이랑 접근성이 가장 큰 이유인데, 어떤 방법을 선택하는게 더 좋은지는 상황마다 다릅니다.
  • 프로토콜을 클래스와 같은 파일 내에 선언했을때,
    • 관련된 클래스 내용을 볼때 프로토콜도 함께 검토할 수 있다는 장점이 있습니다. 따라서 저는 보통 클래스를 구현하고 설계하는 초반에 이 방법을 사용합니다.
    • 클래스 설계나 프로토콜을 선언하면서 서로 바뀌는 부분들이 많을때는 한 파일내에서 작업하는게 더 편합니다.
    • 다만 해당 프로토콜이 꼭 그 클래스에만 쓰이지 않고 다른 클래스에도 쓰이거나 한 프로젝트 내에 프로토콜이 여기저기 선언되어있으면 오히려 나중에 찾아보기 힘든 경우가 발생합니다.
  • 프로토콜을 CustomProtocols.swift와 같은 파일로 모아놓았을때,
    • 위에서 말한 것과 반대로, 한 프로토콜을 여러 클래스가 구현하는 경우나 프로젝트에 프로토콜이 많이 선언 된 경우는 한 파일에 모아보는게 오히려 접근성이 더 좋습니다.
    • 다만 수정해야 할게 많을땐 관련있는 클래스파일과 분리되어 선언되어있으면 접근성이 떨어집니다.
    • 그래서 저는 주로 수정할게 많은 초반엔 관련있는 클래스 파일 내에 프로토콜을 선언하여 같이 바로 구현&수정할 수 있게하고,
    • 어느정도 자리가 잡히고 다른 프로토콜이 많아졌을땐 CustomProtocols.swift파일을 만들어서 분리합니다.

from swift-cardgameapp.

jinios avatar jinios commented on August 25, 2024

PanGesture state - .cancelled

 @objc func dragAction(notification: Notification) {
         ...
        switch recognizer.state {
        case .began:
            // do something
        case .changed:
            // do something
        case .ended:
            // do something
        case .cancelled: return
        default: return
        }
    }

  • 드래그가 cancelled 되는 경우는 어떤 경우일까요?
    취소되버리면 카드가 중간에 멈추면 될까요? 아니면 이전 상태로 돌아가야 할까요?
    • 드래그가 취소된다면 원래 위치로 돌아가야함. 애니메이션도 적용.

from swift-cardgameapp.

jinios avatar jinios commented on August 25, 2024

옵셔널 처리

func cardImages(at: Int?) -> [CardImageView]? {
        var result = [CardImageView]()
        guard self.subviews.count == self.stackManager.countOfCard() else { return result }
        guard let index = at else { return result }
        guard index != self.subviews.count else { return [lastCardView!] }
        for i in index..<self.stackManager.countOfCard() {
            result.append(self.subviews[i] as! CardImageView)
        }
        return result
    }

  • 이렇게 구현되어 있으면 nil 리턴하는 경우가 없는데 optional 필요한걸까요?

from swift-cardgameapp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.