tiking76/RxweatherApp

レビューしてみます

Opened this issue · 0 comments

たまたま見つけたのででしゃばります

let text = "\(baseURL)\(location),jp&units=metric&APPID=\(myAPIKey)"

https://github.com/tiking76/RxweatherApp/blob/master/Rxweatherapp/APIFormat.swift#L32

  • クロージャ による循環参照を防ぎましょう
    クロージャ 内で self を強参照してしまうと循環参照してしまいます。
    今回の場合は循環参照してもメモリリークしたように見えない画面ですが、忘れないように毎回書いておくのおすすめです。こんな感じ
        tokyoButton.rx.tap
            .subscribe(onNext: { [weak self] in
                guard let self = self else { return }
                location = LocationData.tokyo.rawValue
                self.client.getAddress()
                self.weatherView.image = UIImage(named: self.client.weathericon)
                self.view.addSubview(self.weatherView)
            })
            .disposed(by: disposedBeg)

https://github.com/tiking76/RxweatherApp/blob/master/Rxweatherapp/ViewController.swift#L29

  • key がそのまま値となるなら書かなくても良いよってやつ
    enum を使う時に String を継承したりしている状態で、="hoge" など書いていない場合、key の値がそのまま値となります。
    Int を継承した場合は 0 から連番で値が設定されたりします。
    https://github.com/tiking76/RxweatherApp/blob/master/Rxweatherapp/LocationData.swift#L12

  • getter のみを外部に公開すると良いかも?
    以下みたいにやると、getter のみ外部に公開できます

private(set) var weathericon: String = ""

https://github.com/tiking76/RxweatherApp/blob/master/Rxweatherapp/APIFormat.swift#L29