Skip to content

Commit

Permalink
Fix more warning
Browse files Browse the repository at this point in the history
  • Loading branch information
pietrocaselani committed May 19, 2019
1 parent 6fe5611 commit 4dcfb62
Show file tree
Hide file tree
Showing 27 changed files with 207 additions and 439 deletions.
1 change: 1 addition & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ excluded:
- TMDBSwiftTests
- TMDBSwiftTestable
- TVDBSwiftTests
- TVDBSwiftTestable
- CouchTrackerPlayground.playground
- Project.swift

Expand Down
4 changes: 3 additions & 1 deletion TVDBSwift/TVDBTokenRequestInterceptor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ final class TVDBTokenRequestInterceptor: RequestInterceptor {
self.tvdb = tvdb
}

func intercept<T>(target: T.Type, endpoint: Endpoint, done: @escaping MoyaProvider<T>.RequestResultClosure) where T: TVDBType {
func intercept<T>(target: T.Type,
endpoint: Endpoint,
done: @escaping MoyaProvider<T>.RequestResultClosure) where T: TVDBType {
guard let tvdb = self.tvdb else {
done(.failure(MoyaError.requestMapping(endpoint.url)))
return
Expand Down
Empty file removed TVDBSwiftTestable/Empty.swift
Empty file.
15 changes: 15 additions & 0 deletions TVDBSwiftTestable/TVDBTestableBundle.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
public final class TVDBTestableBundle {
public static let bundle = Bundle(for: TVDBTestableBundle.self)

public static func url(forResource name: String) -> URL {
return bundle.url(forResource: name, withExtension: "json")!
}

public static func data(forResource name: String) throws -> Data {
return try Data(contentsOf: url(forResource: name))
}

public static func decode<T: Decodable>(resource name: String, decoder: JSONDecoder = .init()) throws -> T {
return try decoder.decode(T.self, from: data(forResource: name))
}
}
22 changes: 2 additions & 20 deletions TraktSwift/Models/Airs.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
public final class Airs: Codable, Hashable {
public struct Airs: Codable, Hashable {
public let day: String?
public let time: String?
public let timezone: String
Expand All @@ -7,29 +7,11 @@ public final class Airs: Codable, Hashable {
case day, time, timezone
}

public required init(from decoder: Decoder) throws {
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)

day = try container.decodeIfPresent(String.self, forKey: .day)
time = try container.decodeIfPresent(String.self, forKey: .time)
timezone = try container.decode(String.self, forKey: .timezone)
}

public var hashValue: Int {
var hash = timezone.hashValue

if let dayHash = day?.hashValue {
hash ^= dayHash
}

if let timeHash = time?.hashValue {
hash ^= timeHash
}

return hash
}

public static func == (lhs: Airs, rhs: Airs) -> Bool {
return lhs.hashValue == rhs.hashValue
}
}
30 changes: 2 additions & 28 deletions TraktSwift/Models/Base/BaseEpisode.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

public final class BaseEpisode: Codable, Hashable {
public struct BaseEpisode: Codable, Hashable {
public let number: Int
public let collectedAt: Date?
public let plays: Int?
Expand All @@ -15,7 +15,7 @@ public final class BaseEpisode: Codable, Hashable {
case completed
}

public required init(from decoder: Decoder) throws {
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)

number = try container.decode(Int.self, forKey: .number)
Expand All @@ -28,30 +28,4 @@ public final class BaseEpisode: Codable, Hashable {
let lastWatchedAt = try container.decodeIfPresent(String.self, forKey: .lastWatchedAt)
self.lastWatchedAt = TraktDateTransformer.dateTimeTransformer.transformFromJSON(lastWatchedAt)
}

public var hashValue: Int {
var hash = number.hashValue

if let collectedAtHash = collectedAt?.hashValue {
hash = hash ^ collectedAtHash
}

if let playsHash = plays?.hashValue {
hash = hash ^ playsHash
}

if let lastWatchedAtHash = lastWatchedAt?.hashValue {
hash = hash ^ lastWatchedAtHash
}

if let completedHash = completed?.hashValue {
hash = hash ^ completedHash
}

return hash
}

public static func == (lhs: BaseEpisode, rhs: BaseEpisode) -> Bool {
return lhs.hashValue == rhs.hashValue
}
}
20 changes: 7 additions & 13 deletions TraktSwift/Models/Base/BaseIds.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,16 @@ public class BaseIds: Codable, Hashable, CustomStringConvertible {
try container.encodeIfPresent(imdb, forKey: .imdb)
}

public var hashValue: Int {
var hash = trakt.hashValue

if let tmdbHash = tmdb?.hashValue {
hash = hash ^ tmdbHash
}

if let imdbHash = imdb?.hashValue {
hash = hash ^ imdbHash
}

return hash
public func hash(into hasher: inout Hasher) {
hasher.combine(trakt)
hasher.combine(tmdb)
hasher.combine(imdb)
}

public static func == (lhs: BaseIds, rhs: BaseIds) -> Bool {
return lhs.hashValue == rhs.hashValue
return lhs.trakt == rhs.trakt &&
lhs.tmdb == rhs.tmdb &&
lhs.imdb == rhs.imdb
}

public var description: String {
Expand Down
34 changes: 2 additions & 32 deletions TraktSwift/Models/Base/BaseMovie.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

public final class BaseMovie: Codable, Hashable {
public struct BaseMovie: Codable, Hashable {
public let movie: Movie?
public let collectedAt: Date?
public let watchedAt: Date?
Expand All @@ -14,7 +14,7 @@ public final class BaseMovie: Codable, Hashable {
case listedAt = "listed_at"
}

public required init(from decoder: Decoder) throws {
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)

movie = try container.decodeIfPresent(Movie.self, forKey: .movie)
Expand All @@ -28,34 +28,4 @@ public final class BaseMovie: Codable, Hashable {
self.listedAt = TraktDateTransformer.dateTimeTransformer.transformFromJSON(listedAt)
self.watchedAt = TraktDateTransformer.dateTimeTransformer.transformFromJSON(watchedAt)
}

public var hashValue: Int {
var hash = 11

if let movieHash = movie?.hashValue {
hash ^= movieHash
}

if let collectedAtHash = collectedAt?.hashValue {
hash ^= collectedAtHash
}

if let watchedAtHash = watchedAt?.hashValue {
hash ^= watchedAtHash
}

if let listedAtHash = listedAt?.hashValue {
hash ^= listedAtHash
}

if let playsHash = plays?.hashValue {
hash ^= playsHash
}

return hash
}

public static func == (lhs: BaseMovie, rhs: BaseMovie) -> Bool {
return lhs.hashValue == rhs.hashValue
}
}
24 changes: 2 additions & 22 deletions TraktSwift/Models/Base/BaseSeason.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
public final class BaseSeason: Codable, Hashable {
public struct BaseSeason: Codable, Hashable {
public let number: Int
public let episodes: [BaseEpisode]
public let aired: Int?
Expand All @@ -8,32 +8,12 @@ public final class BaseSeason: Codable, Hashable {
case number, episodes, aired, completed
}

public required init(from decoder: Decoder) throws {
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)

number = try container.decode(Int.self, forKey: .number)
episodes = try container.decode([BaseEpisode].self, forKey: .episodes)
aired = try container.decodeIfPresent(Int.self, forKey: .aired)
completed = try container.decodeIfPresent(Int.self, forKey: .completed)
}

public var hashValue: Int {
var hash = number.hashValue

if let airedHash = aired?.hashValue {
hash = hash ^ airedHash
}

if let completedHash = completed?.hashValue {
hash = hash ^ completedHash
}

episodes.forEach { hash = hash ^ $0.hashValue }

return hash
}

public static func == (lhs: BaseSeason, rhs: BaseSeason) -> Bool {
return lhs.hashValue == rhs.hashValue
}
}
50 changes: 2 additions & 48 deletions TraktSwift/Models/Base/BaseShow.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

public final class BaseShow: Codable, Hashable {
public struct BaseShow: Codable, Hashable {
public let show: Show?
public let seasons: [BaseSeason]?
public let lastCollectedAt: Date?
Expand All @@ -21,7 +21,7 @@ public final class BaseShow: Codable, Hashable {
case nextEpisode = "next_episode"
}

public required init(from decoder: Decoder) throws {
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)

show = try container.decodeIfPresent(Show.self, forKey: .show)
Expand All @@ -40,50 +40,4 @@ public final class BaseShow: Codable, Hashable {
self.listedAt = TraktDateTransformer.dateTimeTransformer.transformFromJSON(listedAt)
self.lastWatchedAt = TraktDateTransformer.dateTimeTransformer.transformFromJSON(lastWatchedAt)
}

public var hashValue: Int {
var hash = 11

if let showHash = show?.hashValue {
hash = hash ^ showHash
}

seasons?.forEach { hash = hash ^ $0.hashValue }

if let lastCollectedAtHash = lastCollectedAt?.hashValue {
hash = hash ^ lastCollectedAtHash
}

if let listedAtHash = listedAt?.hashValue {
hash = hash ^ listedAtHash
}

if let playsHash = plays?.hashValue {
hash = hash ^ playsHash
}

if let lastWatchedAtHash = lastWatchedAt?.hashValue {
hash = hash ^ lastWatchedAtHash
}

if let airedHash = aired?.hashValue {
hash = hash ^ airedHash
}

if let completedHash = completed?.hashValue {
hash = hash ^ completedHash
}

hiddenSeasons?.forEach { hash = hash ^ $0.hashValue }

if let nextEpisodeHash = nextEpisode?.hashValue {
hash = hash ^ nextEpisodeHash
}

return hash
}

public static func == (lhs: BaseShow, rhs: BaseShow) -> Bool {
return lhs.hashValue == rhs.hashValue
}
}
6 changes: 3 additions & 3 deletions TraktSwift/Models/Base/BaseTrendingEntity.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
public class BaseTrendingEntity: Codable, Hashable {
public let watchers: Int

public var hashValue: Int {
return watchers.hashValue
public func hash(into hasher: inout Hasher) {
hasher.combine(watchers)
}

public static func == (lhs: BaseTrendingEntity, rhs: BaseTrendingEntity) -> Bool {
return lhs.hashValue == rhs.hashValue
return lhs.watchers == rhs.watchers
}
}
52 changes: 19 additions & 33 deletions TraktSwift/Models/Base/StandardMediaEntity.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import Foundation

public class StandardMediaEntity: Codable, Hashable {
public var title: String?
public var overview: String?
public var rating: Double?
public var votes: Int?
public var updatedAt: Date?
public var translations: [String]?
public let title: String?
public let overview: String?
public let rating: Double?
public let votes: Int?
public let updatedAt: Date?
public let translations: [String]?

private enum CodingKeys: String, CodingKey {
case title
Expand Down Expand Up @@ -40,35 +40,21 @@ public class StandardMediaEntity: Codable, Hashable {
self.updatedAt = TraktDateTransformer.dateTimeTransformer.transformFromJSON(updatedAt)
}

public var hashValue: Int {
var hash = 0

if let titleHash = title?.hashValue {
hash = hash ^ titleHash
}

if let overviewHash = overview?.hashValue {
hash = hash ^ overviewHash
}

if let ratingHash = rating?.hashValue {
hash = hash ^ ratingHash
}

if let votesHash = votes?.hashValue {
hash = hash ^ votesHash
}

if let updatedAtHash = updatedAt?.hashValue {
hash = hash ^ updatedAtHash
}

translations?.forEach { hash = hash ^ $0.hashValue }

return hash
public func hash(into hasher: inout Hasher) {
hasher.combine(title)
hasher.combine(overview)
hasher.combine(rating)
hasher.combine(votes)
hasher.combine(updatedAt)
hasher.combine(translations)
}

public static func == (lhs: StandardMediaEntity, rhs: StandardMediaEntity) -> Bool {
return lhs.hashValue == rhs.hashValue
return lhs.title == rhs.title &&
lhs.overview == rhs.overview &&
lhs.rating == rhs.rating &&
lhs.votes == rhs.votes &&
lhs.updatedAt == rhs.updatedAt &&
lhs.translations == rhs.translations
}
}
Loading

0 comments on commit 4dcfb62

Please sign in to comment.