Skip to content

Commit

Permalink
#45: More SwiftLinting.
Browse files Browse the repository at this point in the history
  • Loading branch information
jrtibbetts committed Jan 12, 2020
1 parent 7b0b823 commit 2056f36
Show file tree
Hide file tree
Showing 37 changed files with 140 additions and 35 deletions.
4 changes: 4 additions & 0 deletions Source/Collection/CollectionCustomField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import Foundation

// swiftlint:disable identifier_name

/// A user-defined column in the collection database.
public struct CollectionCustomField: Codable {

Expand Down Expand Up @@ -46,3 +48,5 @@ public struct CollectionCustomFields: Codable {
public var fields: [CollectionCustomField]?

}

// swiftlint:enable identifier_name
4 changes: 4 additions & 0 deletions Source/Collection/CollectionFolder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import Foundation

// swiftlint:disable identifier_name

/// A JSON element that contains the folders array.
public struct CollectionFolders: Codable {

Expand All @@ -18,3 +20,5 @@ public struct CollectionFolder: Codable, Unique {
public var resourceUrl: String

}

// swiftlint:enable identifier_name
6 changes: 6 additions & 0 deletions Source/Collection/CollectionFolderItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import Foundation

// swiftlint:disable nesting
// swiftlint:disable identifier_name

public struct CollectionFolderItems: Codable, Pageable {

public var pagination: Pagination?
Expand Down Expand Up @@ -75,3 +78,6 @@ public struct CollectionFolderItem: Codable {
}

}

// swiftlint:enable nesting
// swiftlint:enable identifier_name
6 changes: 6 additions & 0 deletions Source/Collection/CollectionRelease.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import Foundation

// swiftlint:disable identifier_name
// swiftlint:disable nesting

public struct CollectionRelease: Codable {

public var basicInformation: [Information]?
Expand Down Expand Up @@ -71,3 +74,6 @@ public struct CollectionRelease: Codable {
}

}

// swiftlint:enable identifier_name
// swiftlint:enable nesting
4 changes: 4 additions & 0 deletions Source/Database/Artist.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import Foundation

// swiftlint:disable identifier_name

public struct Artist: Codable, Unique {

public var dataQuality: String?
Expand All @@ -21,3 +23,5 @@ public struct Artist: Codable, Unique {
}

}

// swiftlint:enable identifier_name
4 changes: 4 additions & 0 deletions Source/Database/ArtistSummary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import Foundation

// swiftlint:disable identifier_name

public struct ArtistSummary: Codable, Unique {

public var artistNameVariation: String?
Expand All @@ -23,3 +25,5 @@ public struct ArtistSummary: Codable, Unique {
}

}

// swiftlint:enable identifier_name
4 changes: 4 additions & 0 deletions Source/Database/BandMember.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import Foundation

// swiftlint:disable identifier_name

public struct BandMember: Codable, Unique {

public var active: Bool?
Expand All @@ -10,3 +12,5 @@ public struct BandMember: Codable, Unique {
public var resourceUrl: String

}

// swiftlint:enable identifier_name
4 changes: 4 additions & 0 deletions Source/Database/RecordLabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import Foundation

// swiftlint:disable identifier_name

public struct RecordLabel: Codable, Unique {

public var contactInfo: String?
Expand All @@ -17,3 +19,5 @@ public struct RecordLabel: Codable, Unique {
public var urls: [String]?

}

// swiftlint:enable identifier_name
4 changes: 4 additions & 0 deletions Source/Database/Release.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import Foundation

// swiftlint:disable identifier_name

public struct Release: Codable, HasArtistSummaries, Unique {

public var artists: [ArtistSummary]?
Expand Down Expand Up @@ -76,3 +78,5 @@ public struct Release: Codable, HasArtistSummaries, Unique {
}

}

// swiftlint:enable identifier_name
4 changes: 4 additions & 0 deletions Source/Database/ReleaseLabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import Foundation

// swiftlint:disable identifier_name

public struct DiscogsReleaseLabel: Codable, Unique {

public var catalogNumber: String?
Expand All @@ -18,3 +20,5 @@ public struct DiscogsReleaseLabel: Codable, Unique {
case resourceUrl
}
}

// swiftlint:enable identifier_name
4 changes: 4 additions & 0 deletions Source/Database/ReleaseSummary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import Foundation

// swiftlint:disable identifier_name

public struct ReleaseSummary: Codable, Unique {

public var artist: String
Expand Down Expand Up @@ -35,3 +37,5 @@ public struct ReleaseSummaries: Codable, Pageable {
public var releases: [ReleaseSummary]?

}

// swiftlint:enable identifier_name
4 changes: 4 additions & 0 deletions Source/Database/Sublabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@

import Foundation

// swiftlint:disable identifier_name

public struct Sublabel: Codable, Unique {

public var id: Int
public var name: String
public var resourceUrl: String

}

// swiftlint:enable identifier_name
4 changes: 4 additions & 0 deletions Source/Unique.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

import Foundation

// swiftlint:disable identifier_name

public protocol Unique {

var id: Int { get }
var resourceUrl: String { get }

}

// swiftlint:enable identifier_name
4 changes: 4 additions & 0 deletions Source/User Identity/UserIdentity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import Foundation

// swiftlint:disable identifier_name

public struct UserIdentity: Codable, Unique {

public var id: Int
Expand All @@ -10,3 +12,5 @@ public struct UserIdentity: Codable, Unique {
public var username: String

}

// swiftlint:enable identifier_name
4 changes: 4 additions & 0 deletions Source/User Identity/UserProfile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import Foundation

// swiftlint:disable identifier_name

public struct UserProfile: Codable {

public var avatarUrl: String
Expand Down Expand Up @@ -37,3 +39,5 @@ public struct UserProfile: Codable {
public var wantlistUrl: URL

}

// swiftlint:enable identifier_name
6 changes: 5 additions & 1 deletion SwiftDiscogsApp/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

// MARK: - Properties

// swiftlint:disable force_cast

static let shared: AppDelegate = (UIApplication.shared.delegate) as! AppDelegate

// swiftlint:enable force_cast

var window: UIWindow?

// MARK: - AppDelegate
Expand All @@ -32,7 +36,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

func application(_ app: UIApplication,
open url: URL,
options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
if url.host! == callbackUrl.host! && url.scheme! == callbackUrl.scheme! {
OAuthSwift.handle(url: url)

Expand Down
9 changes: 7 additions & 2 deletions SwiftDiscogsApp/Artist/ArtistsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class ArtistsViewController: CollectionAndTableViewController, UISearchResultsUp

// MARK: - Properties

// swiftlint:disable force_cast

var artistsDisplay: ArtistsDisplay {
return display as! ArtistsDisplay
}
Expand All @@ -18,6 +20,8 @@ class ArtistsViewController: CollectionAndTableViewController, UISearchResultsUp
return model as! ArtistsModel
}

// swiftlint:enable force_cast

// MARK: - UIViewController

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
Expand Down Expand Up @@ -60,7 +64,8 @@ class ArtistsViewController: CollectionAndTableViewController, UISearchResultsUp

artists?.forEach { (artist) in
let artistName = artist.albumArtist ?? "(unknown)"
self?.artistsModel.artistAlbumCounts[artistName] = mediaLibrary.albums(byArtistNamed: artistName)?.count ?? 0
self?.artistsModel.artistAlbumCounts[artistName]
= mediaLibrary.albums(byArtistNamed: artistName)?.count ?? 0
}
}.done { [weak self] in
self?.artistsDisplay.refresh()
Expand Down Expand Up @@ -125,7 +130,7 @@ class ArtistsModel: CollectionAndTableModel {
var artistMediaItems: [MPMediaItem] = [] {
didSet {
let artistNames = artistMediaItems.map { $0.albumArtist ?? "(unknown)" }
artists = Array<String>(Set<String>(artistNames)).sorted()
artists = [String](Set<String>(artistNames)).sorted()
}
}

Expand Down
9 changes: 6 additions & 3 deletions SwiftDiscogsApp/Artist/DiscogsArtistViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,17 @@ public class DiscogsArtistViewController: UIViewController {
if let artistId = artistSearchResult?.id {
DiscogsManager.discogs.artist(identifier: artistId).done { (artist) in
self.artist = artist
}.catch { (error) in
}.catch { _ in
// HANDLE THE ERROR
}
}
}
}

public var artistView: DiscogsArtistView {
// swiftlint:disable force_cast
return view as! DiscogsArtistView
// swiftlint:enable force_cast
}

public var artistModel = DiscogsArtistModel()
Expand Down Expand Up @@ -120,8 +122,9 @@ public class DiscogsArtistViewController: UIViewController {

private func showDisambiguationList(withResults results: [SearchResult]) {
let storyboard = UIStoryboard(name: "Main", bundle: Bundle.main)
let viewController = storyboard.instantiateViewController(withIdentifier: "DiscogsDisambiguation")

if let disambiguationViewController = storyboard.instantiateViewController(withIdentifier: "DiscogsDisambiguation") as? DiscogsDisambiguationViewController {
if let disambiguationViewController = viewController as? DiscogsDisambiguationViewController {
disambiguationViewController.searchResults = results
disambiguationViewController.artistViewController = self
present(disambiguationViewController, animated: true)
Expand All @@ -138,7 +141,7 @@ public class DiscogsArtistViewController: UIViewController {
&& $0.role == "Main"
&& $0.mainRelease != nil }
self?.artistView.refresh()
}.catch { (error) in
}.catch { _ in
// HANDLE THE ERROR
}
}
Expand Down
10 changes: 5 additions & 5 deletions SwiftDiscogsApp/MediaLibrary/MPMediaCollectionBrowser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,18 @@ public extension MPMediaCollectionBrowser {

if let collections = query.collections {
let totalCount = collections.count
collections.enumerated().forEach({ (_val:(Int, MPMediaItemCollection)) in let (index, collection) = __val;
collections.enumerated().forEach { (index, collection) in
do {
inspect(collection, at: index)
browserDelegate?.willInspect(mediaCollection: collection, at: index, outOf: totalCount)

let totalItemCount = collection.items.count
collection.items.enumerated().forEach({ (_val:(Int, MPMediaItem)) in let (index, item) = __val;
collection.items.enumerated().forEach { (index, item) in
browserDelegate?.willInspect(mediaItem: item, at: index, outOf: totalItemCount)
inspect(item, at: index)
})
}
}
})
}
}

browserDelegate?.didFinishImporting(with: nil)
Expand Down
6 changes: 4 additions & 2 deletions SwiftDiscogsApp/MediaLibrary/MPMediaCollectionImporter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Stylobate
/// inspects the items in a collection.
public class MPMediaItemCollectionImporter: MediaImporter, MPMediaCollectionBrowser {

public var browserDelegate: MPMediaCollectionBrowserDelegate?
public weak var browserDelegate: MPMediaCollectionBrowserDelegate?

public var artistCount: Int = 0

Expand Down Expand Up @@ -41,7 +41,9 @@ public class MPMediaItemCollectionImporter: MediaImporter, MPMediaCollectionBrow

do {
let artist = try fetchOrCreateArtist(named: artistName)!
let masterRelease = try fetchOrCreateMasterRelease(named: releaseTitle, by: [artist], releaseDate: mediaItem.releaseDate)!
let masterRelease = try fetchOrCreateMasterRelease(named: releaseTitle,
by: [artist],
releaseDate: mediaItem.releaseDate)!
let song = try fetchOrCreateSong(named: songName, by: artist)!

if let mediaItemLyrics = mediaItem.lyrics {
Expand Down
9 changes: 8 additions & 1 deletion SwiftDiscogsApp/MediaLibrary/MockMediaLibrary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ class MockMediaLibrary: NSObject, MediaLibrary {
let items: [MockMediaItem] = {
// the explicit variable type is needed to help the Swift compiler
// determine what jsonObject()'s T type is.
let parsedItems: [MockMediaItem] = try! JSONUtils.jsonObject(forFileNamed: "MockMediaLibrary")
let parsedItems: [MockMediaItem]

do {
parsedItems = try JSONUtils.jsonObject(forFileNamed: "MockMediaLibrary")
} catch {
parsedItems = []
assertionFailure("The MockMediaLibrary JSON data couldn't be parsed: \(error)")
}

return parsedItems
}()
Expand Down
Loading

0 comments on commit 2056f36

Please sign in to comment.