Skip to content

Commit

Permalink
self. は省略される傾向があるため、それが明らかに不要な箇所については省略しました。
Browse files Browse the repository at this point in the history
省略推奨についての確かな根拠は見つけられませんでした。以前に The Swift Programming Language で「通常は省略する」という記載があった気がしたのですけれど、探しても見つけられなかったため、省略しない方針もアリかもしれません。その場合はこのコミットを Revert しましょう。
  • Loading branch information
es-kumagai committed Apr 30, 2024
1 parent fa66109 commit 8365b54
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 22 deletions.
6 changes: 3 additions & 3 deletions Example/Example/Model/DisasterModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ class DisasterModelImpl: DisasterModel {
}

func fetchDisaster(completion: ((String) -> Void)?) {
self.fetchDisasterHandler = completion
self.yumemiDisaster.fetchDisaster()
fetchDisasterHandler = completion
yumemiDisaster.fetchDisaster()
}
}

extension DisasterModelImpl: YumemiDisasterHandleDelegate {

func handle(disaster: String) {
self.fetchDisasterHandler?(disaster)
fetchDisasterHandler?(disaster)
}

}
26 changes: 13 additions & 13 deletions Example/Example/UI/Weather/WeatherViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class WeatherViewController: UIViewController {
super.viewDidLoad()

NotificationCenter.default.addObserver(forName: UIApplication.didBecomeActiveNotification, object: nil, queue: nil) { [unowned self] notification in
self.loadWeather(notification.object)
loadWeather(notification.object)
}
}

Expand All @@ -39,11 +39,11 @@ class WeatherViewController: UIViewController {
}

@IBAction func dismiss(_ sender: Any) {
self.dismiss(animated: true, completion: nil)
dismiss(animated: true, completion: nil)
}

@IBAction func loadWeather(_ sender: Any?) {
self.activityIndicator.startAnimating()
activityIndicator.startAnimating()
weatherModel.fetchWeather(at: "tokyo", date: Date()) { result in
DispatchQueue.main.async {
self.activityIndicator.stopAnimating()
Expand All @@ -58,9 +58,9 @@ class WeatherViewController: UIViewController {
func handleWeather(result: Result<Response, WeatherError>) {
switch result {
case .success(let response):
self.weatherImageView.set(weather: response.weather)
self.minTempLabel.text = String(response.minTemp)
self.maxTempLabel.text = String(response.maxTemp)
weatherImageView.set(weather: response.weather)
minTempLabel.text = String(response.minTemp)
maxTempLabel.text = String(response.maxTemp)

case .failure(let error):
let message: String
Expand All @@ -79,7 +79,7 @@ class WeatherViewController: UIViewController {
print("Close ViewController by \(alertController)")
}
})
self.present(alertController, animated: true, completion: nil)
present(alertController, animated: true, completion: nil)
}
}
}
Expand All @@ -88,14 +88,14 @@ private extension UIImageView {
func set(weather: Weather) {
switch weather {
case .sunny:
self.image = R.image.sunny()
self.tintColor = R.color.red()
image = R.image.sunny()
tintColor = R.color.red()
case .cloudy:
self.image = R.image.cloudy()
self.tintColor = R.color.gray()
image = R.image.cloudy()
tintColor = R.color.gray()
case .rainy:
self.image = R.image.rainy()
self.tintColor = R.color.blue()
image = R.image.rainy()
tintColor = R.color.blue()
}
}
}
2 changes: 1 addition & 1 deletion Sources/YumemiWeather/YumemiDisaster.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class YumemiDisaster {
public init() {}

public func fetchDisaster() {
self.delegate?.handle(disaster: "只今、災害情報はありません。")
delegate?.handle(disaster: "只今、災害情報はありません。")
}

}
6 changes: 3 additions & 3 deletions Sources/YumemiWeather/YumemiWeather.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ final public class YumemiWeather {
/// 擬似 天気予報 API Simple ver
/// - Returns: 天気状況を表す文字列 "sunny" or "cloudy" or "rainy"
public static func fetchWeatherCondition() -> String {
return self.makeRandomResponse().weatherCondition
return makeRandomResponse().weatherCondition
}

/// 擬似 天気予報 API Throws ver
Expand All @@ -92,7 +92,7 @@ final public class YumemiWeather {
throw YumemiWeatherError.unknownError
}

return self.makeRandomResponse().weatherCondition
return makeRandomResponse().weatherCondition
}

/// 擬似 天気予報 API JSON ver
Expand Down Expand Up @@ -155,7 +155,7 @@ final public class YumemiWeather {
/// - Returns: Weather レスポンスの JSON 文字列
public static func syncFetchWeather(_ jsonString: String) throws -> String {
Thread.sleep(forTimeInterval: apiDuration)
return try self.fetchWeather(jsonString)
return try fetchWeather(jsonString)
}

/// 擬似 天気予報 API Callback ver
Expand Down
2 changes: 1 addition & 1 deletion Sources/YumemiWeather/YumemiWeatherList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public extension YumemiWeather {
/// - Returns: 返された AreaResponse の JSON 文字列
static func syncFetchWeatherList(_ jsonString: String) throws -> String {
Thread.sleep(forTimeInterval: apiDuration)
return try self.fetchWeatherList(jsonString)
return try fetchWeatherList(jsonString)
}

/// 擬似 天気予報一覧 API Callback ver
Expand Down
2 changes: 1 addition & 1 deletion Tests/YumemiWeatherTests/YumemiWeatherTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ final class YumemiWeatherTests: XCTestCase {
XCTAssertEqual(error, YumemiWeatherError.unknownError)
}
}
self.wait(for: [exp], timeout: YumemiWeather.apiDuration + 0.1)
wait(for: [exp], timeout: YumemiWeather.apiDuration + 0.1)
}

@available(iOS 13, macOS 10.15, *)
Expand Down

0 comments on commit 8365b54

Please sign in to comment.