diff --git a/iOS/baseballApp/baseballApp.xcodeproj/project.pbxproj b/iOS/baseballApp/baseballApp.xcodeproj/project.pbxproj index 5f2644082..4a286c7c4 100644 --- a/iOS/baseballApp/baseballApp.xcodeproj/project.pbxproj +++ b/iOS/baseballApp/baseballApp.xcodeproj/project.pbxproj @@ -28,7 +28,13 @@ 76619ABC2643A355004D31C6 /* GameViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76619ABB2643A355004D31C6 /* GameViewModel.swift */; }; 76619AC22643AE83004D31C6 /* GameCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76619AC12643AE83004D31C6 /* GameCell.swift */; }; 76619B062644EE37004D31C6 /* StadiumView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76619B052644EE37004D31C6 /* StadiumView.swift */; }; + 76855AC7264BE17600068E77 /* BallCountView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76855AC6264BE17600068E77 /* BallCountView.swift */; }; 7691F9A526491ADB00C56E11 /* PlayStoryboard.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7691F9A426491ADB00C56E11 /* PlayStoryboard.storyboard */; }; + 76A7E3A6264CB9010028B08A /* PlayInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76A7E3A5264CB9010028B08A /* PlayInfo.swift */; }; + 76A7E3A8264CBD510028B08A /* PlayDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76A7E3A7264CBD510028B08A /* PlayDTO.swift */; }; + 76A7E3AA264CC4B60028B08A /* PlayViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76A7E3A9264CC4B60028B08A /* PlayViewModel.swift */; }; + 76A7E3AC264CD2F20028B08A /* Constant.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76A7E3AB264CD2F20028B08A /* Constant.swift */; }; + 76A7E3EA264CF9B50028B08A /* BallCount.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76A7E3E9264CF9B50028B08A /* BallCount.swift */; }; 76AA2694264A73F500600D45 /* ScoreStoryboard.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 76AA2693264A73F500600D45 /* ScoreStoryboard.storyboard */; }; 76AF2BC4264B7D9900DC7782 /* GameViewModelType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76AF2BC3264B7D9900DC7782 /* GameViewModelType.swift */; }; 76AF2BC7264BA5F600DC7782 /* BallListCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76AF2BC5264BA5F600DC7782 /* BallListCell.swift */; }; @@ -85,7 +91,13 @@ 76619ABB2643A355004D31C6 /* GameViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameViewModel.swift; sourceTree = ""; }; 76619AC12643AE83004D31C6 /* GameCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameCell.swift; sourceTree = ""; }; 76619B052644EE37004D31C6 /* StadiumView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StadiumView.swift; sourceTree = ""; }; + 76855AC6264BE17600068E77 /* BallCountView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BallCountView.swift; sourceTree = ""; }; 7691F9A426491ADB00C56E11 /* PlayStoryboard.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = PlayStoryboard.storyboard; sourceTree = ""; }; + 76A7E3A5264CB9010028B08A /* PlayInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayInfo.swift; sourceTree = ""; }; + 76A7E3A7264CBD510028B08A /* PlayDTO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayDTO.swift; sourceTree = ""; }; + 76A7E3A9264CC4B60028B08A /* PlayViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayViewModel.swift; sourceTree = ""; }; + 76A7E3AB264CD2F20028B08A /* Constant.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constant.swift; sourceTree = ""; }; + 76A7E3E9264CF9B50028B08A /* BallCount.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BallCount.swift; sourceTree = ""; }; 76AA2693264A73F500600D45 /* ScoreStoryboard.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = ScoreStoryboard.storyboard; sourceTree = ""; }; 76AF2BC3264B7D9900DC7782 /* GameViewModelType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameViewModelType.swift; sourceTree = ""; }; 76AF2BC5264BA5F600DC7782 /* BallListCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BallListCell.swift; sourceTree = ""; }; @@ -156,6 +168,7 @@ 7650A1B02640E3A9006C1E5F /* Assets.xcassets */, 7650A1B22640E3A9006C1E5F /* LaunchScreen.storyboard */, 7650A1B52640E3A9006C1E5F /* Info.plist */, + 76A7E3AB264CD2F20028B08A /* Constant.swift */, ); path = baseballApp; sourceTree = ""; @@ -202,6 +215,7 @@ children = ( 76619ABB2643A355004D31C6 /* GameViewModel.swift */, 76AF2BC3264B7D9900DC7782 /* GameViewModelType.swift */, + 76A7E3A9264CC4B60028B08A /* PlayViewModel.swift */, ); path = ViewModel; sourceTree = ""; @@ -223,6 +237,7 @@ 76619B052644EE37004D31C6 /* StadiumView.swift */, 76AF2BC5264BA5F600DC7782 /* BallListCell.swift */, 76AF2BC6264BA5F600DC7782 /* BallListCell.xib */, + 76855AC6264BE17600068E77 /* BallCountView.swift */, ); path = View; sourceTree = ""; @@ -250,6 +265,8 @@ 7650A1E6264138A0006C1E5F /* Player.swift */, 7650A1E82641418B006C1E5F /* Record.swift */, 76619AA626437476004D31C6 /* Game.swift */, + 76A7E3A5264CB9010028B08A /* PlayInfo.swift */, + 76A7E3E9264CF9B50028B08A /* BallCount.swift */, ); path = Entity; sourceTree = ""; @@ -285,6 +302,7 @@ isa = PBXGroup; children = ( 76619AB326439866004D31C6 /* GameDTO.swift */, + 76A7E3A7264CBD510028B08A /* PlayDTO.swift */, ); path = DataMapping; sourceTree = ""; @@ -559,15 +577,21 @@ 7650A1A82640E3A8006C1E5F /* AppDelegate.swift in Sources */, 76AF2BC4264B7D9900DC7782 /* GameViewModelType.swift in Sources */, 76619AC22643AE83004D31C6 /* GameCell.swift in Sources */, + 76A7E3EA264CF9B50028B08A /* BallCount.swift in Sources */, 7650A1AA2640E3A8006C1E5F /* SceneDelegate.swift in Sources */, 7650A1E126411A51006C1E5F /* HomeViewController.swift in Sources */, 76619ABC2643A355004D31C6 /* GameViewModel.swift in Sources */, 76619AB426439866004D31C6 /* GameDTO.swift in Sources */, 7650A1E92641418B006C1E5F /* Record.swift in Sources */, 76619AB2264385BB004D31C6 /* APIService.swift in Sources */, + 76A7E3AA264CC4B60028B08A /* PlayViewModel.swift in Sources */, + 76A7E3A8264CBD510028B08A /* PlayDTO.swift in Sources */, + 76A7E3AC264CD2F20028B08A /* Constant.swift in Sources */, 7650A1E7264138A0006C1E5F /* Player.swift in Sources */, + 76A7E3A6264CB9010028B08A /* PlayInfo.swift in Sources */, 7650A1E526411A78006C1E5F /* ScoreViewController.swift in Sources */, 76619AA726437476004D31C6 /* Game.swift in Sources */, + 76855AC7264BE17600068E77 /* BallCountView.swift in Sources */, 76619B062644EE37004D31C6 /* StadiumView.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/iOS/baseballApp/baseballApp/Assets.xcassets/baseball_player.imageset/Contents.json b/iOS/baseballApp/baseballApp/Assets.xcassets/baseball_player.imageset/Contents.json index a1f759c6d..75d200444 100644 --- a/iOS/baseballApp/baseballApp/Assets.xcassets/baseball_player.imageset/Contents.json +++ b/iOS/baseballApp/baseballApp/Assets.xcassets/baseball_player.imageset/Contents.json @@ -1,7 +1,7 @@ { "images" : [ { - "filename" : "baseball_player.png", + "filename" : "baseball_player-2.png", "idiom" : "universal", "scale" : "1x" }, diff --git a/iOS/baseballApp/baseballApp/Assets.xcassets/baseball_player.imageset/baseball_player-2.png b/iOS/baseballApp/baseballApp/Assets.xcassets/baseball_player.imageset/baseball_player-2.png new file mode 100644 index 000000000..2eb1af288 Binary files /dev/null and b/iOS/baseballApp/baseballApp/Assets.xcassets/baseball_player.imageset/baseball_player-2.png differ diff --git a/iOS/baseballApp/baseballApp/Assets.xcassets/baseball_player.imageset/baseball_player.png b/iOS/baseballApp/baseballApp/Assets.xcassets/baseball_player.imageset/baseball_player.png deleted file mode 100644 index 0a9ce2fea..000000000 Binary files a/iOS/baseballApp/baseballApp/Assets.xcassets/baseball_player.imageset/baseball_player.png and /dev/null differ diff --git a/iOS/baseballApp/baseballApp/Constant.swift b/iOS/baseballApp/baseballApp/Constant.swift new file mode 100644 index 000000000..fb4babe41 --- /dev/null +++ b/iOS/baseballApp/baseballApp/Constant.swift @@ -0,0 +1,12 @@ +// +// Constant.swift +// baseballApp +// +// Created by 김지선 on 2021/05/13. +// + +import Foundation + +struct Notification { + static let sendGame = "sendGame" +} diff --git a/iOS/baseballApp/baseballApp/Data/Network/APIService.swift b/iOS/baseballApp/baseballApp/Data/Network/APIService.swift index 9dbcbc884..31cc8923a 100644 --- a/iOS/baseballApp/baseballApp/Data/Network/APIService.swift +++ b/iOS/baseballApp/baseballApp/Data/Network/APIService.swift @@ -11,6 +11,13 @@ class APIService { } return getAndDecode(url) } + + func requestPlay(gameID: Int, inningID: Int) throws -> Observable { + guard let url = Endpoint.getGames(path: "baseball/\(gameID)/inning/\(inningID)") else { + throw APIError.urlNotSupport + } + return getAndDecode(url) + } private func getAndDecode(_ url: URL) -> Observable { return Observable.create { observer in diff --git a/iOS/baseballApp/baseballApp/Data/Network/DataMapping/PlayDTO.swift b/iOS/baseballApp/baseballApp/Data/Network/DataMapping/PlayDTO.swift new file mode 100644 index 000000000..ce859c93d --- /dev/null +++ b/iOS/baseballApp/baseballApp/Data/Network/DataMapping/PlayDTO.swift @@ -0,0 +1,29 @@ +import Foundation + +struct PlayDTO: Codable { + let inningID: Int + let inning: Int + let attackTeamID: Int + let ballCount: [String] + let outCount: Int + let pitcher: Player + let batter: Player + let baseStatus: [Int] + let homeTeamScore: Int + let awayTeamScore: Int + + enum CodingKeys: String, CodingKey { + case inningID = "inning_id" + case inning = "inning" + case attackTeamID = "attack_team_id" + case ballCount = "ball_count" + case outCount = "out_count" + case pitcher = "pitcher" + case batter = "batter" + case baseStatus = "base_status" + case homeTeamScore = "home_team_score" + case awayTeamScore = "away_team_score" + } +} + + diff --git a/iOS/baseballApp/baseballApp/Domain/Entity/BallCount.swift b/iOS/baseballApp/baseballApp/Domain/Entity/BallCount.swift new file mode 100644 index 000000000..b94d717ea --- /dev/null +++ b/iOS/baseballApp/baseballApp/Domain/Entity/BallCount.swift @@ -0,0 +1,17 @@ +import Foundation + +class BallCount { + private var strike: Int + private var ball: Int + + init() { + self.strike = 0 + self.ball = 0 + } + + func addBall(_ ballType: String) -> (Int, Int) { + strike += ballType == "S" ? 1 : 0 + ball += ballType == "B" ? 1: 0 + return (strike, ball) + } +} diff --git a/iOS/baseballApp/baseballApp/Domain/Entity/Game.swift b/iOS/baseballApp/baseballApp/Domain/Entity/Game.swift index 19f4a0e20..54bf52d3e 100644 --- a/iOS/baseballApp/baseballApp/Domain/Entity/Game.swift +++ b/iOS/baseballApp/baseballApp/Domain/Entity/Game.swift @@ -8,7 +8,7 @@ struct Game: Codable { let awayID: Int let away: String let awayScore: Int - let inning: Int + let inningID: Int enum CodingKeys: String, CodingKey { case id = "game_id" @@ -18,6 +18,6 @@ struct Game: Codable { case awayID = "away_team_id" case away = "away_team" case awayScore = "away_team_score" - case inning = "now_inning_id" + case inningID = "now_inning_id" } } diff --git a/iOS/baseballApp/baseballApp/Domain/Entity/PlayInfo.swift b/iOS/baseballApp/baseballApp/Domain/Entity/PlayInfo.swift new file mode 100644 index 000000000..fbf287572 --- /dev/null +++ b/iOS/baseballApp/baseballApp/Domain/Entity/PlayInfo.swift @@ -0,0 +1,2 @@ +import Foundation + diff --git a/iOS/baseballApp/baseballApp/Domain/Entity/Player.swift b/iOS/baseballApp/baseballApp/Domain/Entity/Player.swift index 071e297df..bc5d462bd 100644 --- a/iOS/baseballApp/baseballApp/Domain/Entity/Player.swift +++ b/iOS/baseballApp/baseballApp/Domain/Entity/Player.swift @@ -1,7 +1,6 @@ import Foundation -struct Player { +struct Player: Codable { let name: String let backNumber: Int - let record: Record } diff --git a/iOS/baseballApp/baseballApp/Presentation/UI/Storyboard/PlayStoryboard.storyboard b/iOS/baseballApp/baseballApp/Presentation/UI/Storyboard/PlayStoryboard.storyboard index f3e246fce..28868a11d 100644 --- a/iOS/baseballApp/baseballApp/Presentation/UI/Storyboard/PlayStoryboard.storyboard +++ b/iOS/baseballApp/baseballApp/Presentation/UI/Storyboard/PlayStoryboard.storyboard @@ -18,105 +18,281 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -126,7 +302,7 @@ - + @@ -134,11 +310,8 @@ - - - - - + + diff --git a/iOS/baseballApp/baseballApp/Presentation/UI/Storyboard/ScoreStoryboard.storyboard b/iOS/baseballApp/baseballApp/Presentation/UI/Storyboard/ScoreStoryboard.storyboard index 75962e566..c7673c865 100644 --- a/iOS/baseballApp/baseballApp/Presentation/UI/Storyboard/ScoreStoryboard.storyboard +++ b/iOS/baseballApp/baseballApp/Presentation/UI/Storyboard/ScoreStoryboard.storyboard @@ -27,7 +27,7 @@ - + diff --git a/iOS/baseballApp/baseballApp/Presentation/UI/View/BallCountView.swift b/iOS/baseballApp/baseballApp/Presentation/UI/View/BallCountView.swift new file mode 100644 index 000000000..4c11a72ca --- /dev/null +++ b/iOS/baseballApp/baseballApp/Presentation/UI/View/BallCountView.swift @@ -0,0 +1,44 @@ +import UIKit + +class BallCountView: UIView { + private lazy var strikePoint = CGPoint(x: 20, y: 2) + private lazy var ballPoint = CGPoint(x: 20, y: 26) + private lazy var outPoint = CGPoint(x: 20, y: 50) + private let rectSize = CGSize(width: 20, height: 20) + + override func draw(_ rect: CGRect) { + guard let context = UIGraphicsGetCurrentContext() else { return } + context.setStrokeColor(UIColor.gray.cgColor) + drawStrike(context) + drawStrike(context) + drawBall(context) + drawBall(context) + drawBall(context) + drawOut(context) + } + + func drawStrike(_ context: CGContext) { + context.setFillColor(UIColor.yellow.cgColor) + context.addEllipse(in: CGRect(origin: strikePoint, size: rectSize)) + context.closePath() + context.drawPath(using: .fillStroke) + strikePoint.x += 25 + } + + func drawBall(_ context: CGContext) { + context.setFillColor(UIColor.green.cgColor) + context.addEllipse(in: CGRect(origin: ballPoint, size: rectSize)) + context.closePath() + context.drawPath(using: .fillStroke) + ballPoint.x += 25 + } + + func drawOut(_ context: CGContext) { + context.setFillColor(UIColor.red.cgColor) + context.addEllipse(in: CGRect(origin: outPoint, size: rectSize)) + context.closePath() + context.drawPath(using: .fillStroke) + outPoint.x += 25 + } + +} diff --git a/iOS/baseballApp/baseballApp/Presentation/UI/View/BallListCell.swift b/iOS/baseballApp/baseballApp/Presentation/UI/View/BallListCell.swift index b9b06cf76..f89d38221 100644 --- a/iOS/baseballApp/baseballApp/Presentation/UI/View/BallListCell.swift +++ b/iOS/baseballApp/baseballApp/Presentation/UI/View/BallListCell.swift @@ -7,30 +7,38 @@ import UIKit -class ballListCell: UITableViewCell { +class BallListCell: UITableViewCell { + static let identifier = "BallListCell" @IBOutlet weak var ballIDLabel: UILabel! @IBOutlet weak var ballTypeLabel: UILabel! - @IBOutlet weak var ballCountLabel: UILabel! @IBOutlet weak var strikeCountLabel: UILabel! + @IBOutlet weak var ballCountLabel: UILabel! override func awakeFromNib() { super.awakeFromNib() + configureUI() // Initialization code } override func setSelected(_ selected: Bool, animated: Bool) { super.setSelected(selected, animated: animated) - + configureUI() // Configure the view for the selected state } -// func configureCell() { -// -// } + func configure(id: Int, ball: String, with ballCount: BallCount) { + ballIDLabel.text = "\(id)" + ballTypeLabel.text = ball == "S" ? "Strike" : "Ball" + let (strike, ball) = ballCount.addBall(ball) + strikeCountLabel.text = "\(ball)" + ballCountLabel.text = "\(strike)" + } func configureUI() { ballIDLabel.layer.cornerRadius = ballIDLabel.bounds.width / 2 } + + } diff --git a/iOS/baseballApp/baseballApp/Presentation/UI/View/BallListCell.xib b/iOS/baseballApp/baseballApp/Presentation/UI/View/BallListCell.xib index b49254d14..023b2171f 100644 --- a/iOS/baseballApp/baseballApp/Presentation/UI/View/BallListCell.xib +++ b/iOS/baseballApp/baseballApp/Presentation/UI/View/BallListCell.xib @@ -10,7 +10,7 @@ - + @@ -56,6 +56,9 @@ - - + + - + diff --git a/iOS/baseballApp/baseballApp/Presentation/UI/View/StadiumView.swift b/iOS/baseballApp/baseballApp/Presentation/UI/View/StadiumView.swift index 23d04ae1e..8fcbbd457 100644 --- a/iOS/baseballApp/baseballApp/Presentation/UI/View/StadiumView.swift +++ b/iOS/baseballApp/baseballApp/Presentation/UI/View/StadiumView.swift @@ -53,6 +53,8 @@ class StadiumView: UIView { context.drawPath(using: mode) } - + func drawPlayer() { + let layer = CALayer() + } } diff --git a/iOS/baseballApp/baseballApp/Presentation/UI/ViewController/HomeViewController.swift b/iOS/baseballApp/baseballApp/Presentation/UI/ViewController/HomeViewController.swift index 961d14c08..62e1fc867 100644 --- a/iOS/baseballApp/baseballApp/Presentation/UI/ViewController/HomeViewController.swift +++ b/iOS/baseballApp/baseballApp/Presentation/UI/ViewController/HomeViewController.swift @@ -27,12 +27,13 @@ class HomeViewController: UIViewController { } private func setupCollectionViewDelegate() { - mainCollectionView.rx.itemSelected - .subscribe(onNext: { [weak self] indexPath in + mainCollectionView.rx.modelSelected(Game.self) + .subscribe(onNext: { [weak self] game in let tabBarController = self?.storyboard?.instantiateViewController(identifier: "TabBarController") + let playViewController = tabBarController?.children.first as! PlayViewController + playViewController.game = game self?.present(tabBarController!, animated: true, completion: nil) }, onError: { error in - print(error.localizedDescription) }) .disposed(by: disposeBag) diff --git a/iOS/baseballApp/baseballApp/Presentation/UI/ViewController/PlayViewController.swift b/iOS/baseballApp/baseballApp/Presentation/UI/ViewController/PlayViewController.swift index 8ba8d2846..eb9842740 100644 --- a/iOS/baseballApp/baseballApp/Presentation/UI/ViewController/PlayViewController.swift +++ b/iOS/baseballApp/baseballApp/Presentation/UI/ViewController/PlayViewController.swift @@ -1,15 +1,84 @@ import UIKit +import RxSwift class PlayViewController: UIViewController { - + var game: Game? + private lazy var ballListData = [String]() + private lazy var ballCount = BallCount() + @IBOutlet weak var stadiumView: StadiumView! @IBOutlet weak var ballListView: UITableView! + @IBOutlet weak var pitcherNameLabel: UILabel! + @IBOutlet weak var pitcherBackNumberLabel: UILabel! + @IBOutlet weak var batterNameLabel: UILabel! + @IBOutlet weak var batterInfoLabel: UILabel! + @IBOutlet weak var pitcherCheckMark: UIImageView! + @IBOutlet weak var batterCheckMark: UIImageView! + @IBOutlet weak var attackAndDefendLabel: UILabel! + @IBOutlet weak var inningCountLabel: UILabel! + @IBOutlet weak var inningPointLabel: UILabel! + @IBAction func pitcherButtonTouched(_ sender: Any) { + batterCheckMark.isHidden = true + pitcherCheckMark.isHidden = false + attackAndDefendLabel.text = "수비" + } + @IBAction func batterButtonTouched(_ sender: Any) { + batterCheckMark.isHidden = false + pitcherCheckMark.isHidden = true + attackAndDefendLabel.text = "공격" + } + + + + private let viewModel = PlayViewModel() + private var disposeBag = DisposeBag() + override func viewDidLoad() { super.viewDidLoad() - ballListView.register(UINib(nibName: "BallListCell", bundle: nil), forCellReuseIdentifier: "BallListCell") + registerXib() + configureUI() + + + } override func viewDidAppear(_ animated: Bool) { - stadiumView.backgroundColor = .red + + } + + private func registerXib() { + ballListView.register(UINib(nibName: BallListCell.identifier, bundle: nil), forCellReuseIdentifier: BallListCell.identifier) + } + + func configureUI() { + batterCheckMark.isHidden = false + pitcherCheckMark.isHidden = true + attackAndDefendLabel.text = "공격" + viewModel.getPlayInfo(gameID: game!.id, inningID: game!.inningID) { data in + self.inningCountLabel.text = "\(data.inning)" + self.inningPointLabel.text = "초" + self.pitcherNameLabel.text = "\(data.pitcher.name)" + self.pitcherBackNumberLabel.text = "#\(data.pitcher.backNumber)" + self.batterNameLabel.text = "\(data.batter.name)" + self.ballListData = data.ballCount + self.ballListView.reloadData() + + } + ballListView.dataSource = self + } +} + +extension PlayViewController: UITableViewDataSource { + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + print(ballListData.count) + return ballListData.count + } + + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + + let cell = tableView.dequeueReusableCell(withIdentifier: BallListCell.identifier, for: indexPath) as! BallListCell + let ball = ballListData[indexPath.row] + cell.configure(id: indexPath.row, ball: ball, with: ballCount) + return cell } } diff --git a/iOS/baseballApp/baseballApp/Presentation/ViewModel/PlayViewModel.swift b/iOS/baseballApp/baseballApp/Presentation/ViewModel/PlayViewModel.swift new file mode 100644 index 000000000..994463ecb --- /dev/null +++ b/iOS/baseballApp/baseballApp/Presentation/ViewModel/PlayViewModel.swift @@ -0,0 +1,37 @@ +import Foundation +import RxSwift +import RxCocoa + +class PlayViewModel { + private var play = [PlayDTO]() + //private lazy var playStorage = BehaviorSubject<[PlayDTO]>(value: play) + private var disposeBag = DisposeBag() + + + + func savePlay(from data: PlayDTO) { + play.append(data) + //playStorage.onNext(play) + } + +// func getPlay() -> Observable<[PlayDTO]> { +// return playStorage +// } + + func getPlayInfo(gameID: Int, inningID: Int, _ completion: @escaping (PlayDTO)->Void) { + try? APIService.shared.requestPlay(gameID: gameID, inningID: inningID) + .subscribe { playData in + self.savePlay(from: playData) + completion(playData) + } onError: { error in + print(error.localizedDescription) + }.disposed(by: disposeBag) + } + +// private func transformDTO(to play: PlayDTO, completion: @escaping (PlayDTO)->Void +// ){ +// play.forEach { data in +// completion(data) +// } +// } +}