Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Letswift18 워크숍#1 스위프트 클린코드와 코드리뷰

157 views

Published on

렛츠스위프트 워크숍. 첫번째 - 스위프트 클린코드와 코드리뷰

Published in: Technology
  • Be the first to comment

Letswift18 워크숍#1 스위프트 클린코드와 코드리뷰

  1. 1. https://github.com/godrm/ChessMate
  2. 2. 🤩
  3. 3. ? ? ? ? ?
  4. 4. API SwiftLint CI
  5. 5. API SwiftLint CI
  6. 6. Best Practices & Styles ✱ Tab vs. Space ✱ Braces Styles ✱ Variable, Function, Class - Naming Rules ✱ Computed Properties vs. Methods ✱ Protocol + Extension + Generic ✱ Value Types vs. Reference Types
  7. 7. Software maintenance is not 'keep it working like before'. It is 'keep it being useful in a changing world' - Jessica Kerr
  8. 8. 1. . . 2. / . 3. . 4. . 5. / . 6. . 7. . .
  9. 9. , ,
  10. 10. http://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html
  11. 11. ? + +
  12. 12. Main - , , , Reusability - DRY, components, generics Reliability - Exception handling and cleanup Extensibility Security - , , , Performance - , Lazy Loading, , Scalability - Usability -
  13. 13. https://c4model.com
  14. 14. 🤩
  15. 15. A B C D E F G H 8 7 6 5 4 3 2 1
  16. 16. Person ChessMate System Email System App Store
  17. 17. Person ChessMate System Email System ChessMate System iOS App Android App API ServerDatabase Apple App Store Google Play Store
  18. 18. Person ChessMate System Mobile App AppDelegate ChessView Controller API Server Network Manager APNS Server Background View
  19. 19. 1. SRP (Single-Responsibility Principle) ( , , ) . - . 2. OCP (Open-Close Principle) , . . 3. LSP (Liskov Substitution Principle) ( ) . ( ) . 4. DIP (Dependency-Inversion Principle) . ( ) , . 5. ISP (Interface-Segregation Principle) .
  20. 20. struct InputView { func readInput() { print(" .") let userInput = readLine() guard let input = userInput else { return } print(seperateCoordinates(userInput: input)) } //… } struct InputView { func readLine(prompt: String) -> String { print(prompt) let line = readLine() guard let input = line else { return "" } return input } //… }
  21. 21. class BackgroundView: UIView { private let Steps = 8 // convenience init() { self.init(frame: ChessBackgroundView.centralRect()) } private static func centralRect() -> CGRect { let screenRect = UIScreen.main.bounds let verticalMargin = (screenRect.height - screenRect.width) / 2 return CGRect(x: 0, y: verticalMargin, width: screenRect.width, height: screenRect.width) } override func draw(_ rect: CGRect) { let width = frame.width / CGFloat(Steps) let height = frame.height / CGFloat(Steps) var binaryFlag = false for y in 0..<Steps { for x in 0..<Steps { let boxFrame = CGRect(x: CGFloat(x) * width, y: CGFloat(y) * height, width: width, height: height) (binaryFlag ? UIColor.white : UIColor.black).setFill() UIBezierPath.init(rect: boxFrame).fill() binaryFlag.toggle() } binaryFlag.toggle() } } }
  22. 22. UIScreen GUI Engine ChessMate System BackgroundView draw(rect:) init() centralRect()
  23. 23. UIScreen GUI Engine ChessMate System BackgroundView draw(rect:) init(frame:) centralRect() BackgroundPresenter
  24. 24. Person ChessMate System Mobile App AppDelegate ChessView Controller Background Presenter Background View
  25. 25. Person ChessMate System Mobile App AppDelegate ChessView Controller Background Presenter Background View Pawn View King View Queen View …
  26. 26. View DataSource
  27. 27. View DataSource DataSource <Protocol> Protocol-Oriented Programming
  28. 28. Piece enum PieceType .pawn .king .queen .rook .bishop .knight type
  29. 29. Piece Pawn type PieceType <Protocol> King Queen Rook Bishop Knight
  30. 30. Person ChessMate System Mobile App AppDelegate ChessView Controller Background Presenter Background View Piece <Protocol> Piece
  31. 31. Constructor Injection Setter Injection Interface Injection class BackgroundView: UIView { private var presenter : BackgroundPresenter! convenience init(presenter: BackgroundPresenter) { self.init(frame: presenter.centralRect()) self.presenter = presenter } } protocol GameManagerAction { func positionMap() -> Array<Array<Piece?>> func defaultFrame(path:(x : Int, y: Int)) -> CGRect } class ViewController: UIViewController { private var manager : GameManagerAction! func setManager(_ manager : GameManagerAction) { self.positionManager = manager } } protocol PieceImageSetter { func setImageBy(piece: Piece) } class PieceImageView: UIImageView, PieceImageSetter { func setImageBy(piece: Piece) { self.image = piece.type.image(color: piece.color.rawValue) } }
  32. 32. protocol GameManagerAction { func positionMap() -> Array<Array<Piece?>> } protocol GameManagerGeometric { func defaultFrame(for: (x : Int, y: Int)) -> CGRect } class ViewController: UIViewController { private var positionManager : (GameManagerAction & GameManagerGeometric)! func setManager(_ manager : GameManagerAction & GameManagerGeometric) { self.positionManager = manager } protocol GameManagerAction { func positionMap() -> Array<Array<Piece?>> func defaultFrame(path:(x : Int, y: Int)) -> CGRect }
  33. 33. Person ChessMate System Mobile App AppDelegate ChessView Controller Background Presenter Background View Game Manager <Action> Game Manager Geometric
  34. 34. . Don’t get it, Just ask them.
  35. 35. struct GamePositionManager { var positionMap = Array<Array<Piece?>>()
  36. 36. struct GamePositionManager { var positionMap = Array<Array<Piece?>>()
  37. 37. (Driver)(Navigator) http://cameracourage.com/2012/11/what-does-a-rally-co-driver-do/
  38. 38. • . • . • , . • . • . • , , ! • . • . • . • ( 10 ~20 ) . • TDD . ( …)
  39. 39. • . • . • . • . • . , . • . • . • . • : .
  40. 40. • . • ' ' . • . • * * . • . • . • . • . • . • .
  41. 41. • review . • • , • 😱 • • • . . https://github.com/godrm/ChessMate

×