diff --git a/Source/Collection/CollectionCustomField.swift b/Source/Collection/CollectionCustomField.swift index 10744b0..f4a1efb 100644 --- a/Source/Collection/CollectionCustomField.swift +++ b/Source/Collection/CollectionCustomField.swift @@ -2,6 +2,8 @@ import Foundation +// swiftlint:disable identifier_name + /// A user-defined column in the collection database. public struct CollectionCustomField: Codable { @@ -46,3 +48,5 @@ public struct CollectionCustomFields: Codable { public var fields: [CollectionCustomField]? } + +// swiftlint:enable identifier_name diff --git a/Source/Collection/CollectionFolder.swift b/Source/Collection/CollectionFolder.swift index ad5f271..d0fb004 100644 --- a/Source/Collection/CollectionFolder.swift +++ b/Source/Collection/CollectionFolder.swift @@ -2,6 +2,8 @@ import Foundation +// swiftlint:disable identifier_name + /// A JSON element that contains the folders array. public struct CollectionFolders: Codable { @@ -18,3 +20,5 @@ public struct CollectionFolder: Codable, Unique { public var resourceUrl: String } + +// swiftlint:enable identifier_name diff --git a/Source/Collection/CollectionFolderItem.swift b/Source/Collection/CollectionFolderItem.swift index fa8e19a..e77db1f 100644 --- a/Source/Collection/CollectionFolderItem.swift +++ b/Source/Collection/CollectionFolderItem.swift @@ -2,6 +2,9 @@ import Foundation +// swiftlint:disable nesting +// swiftlint:disable identifier_name + public struct CollectionFolderItems: Codable, Pageable { public var pagination: Pagination? @@ -75,3 +78,6 @@ public struct CollectionFolderItem: Codable { } } + +// swiftlint:enable nesting +// swiftlint:enable identifier_name diff --git a/Source/Collection/CollectionRelease.swift b/Source/Collection/CollectionRelease.swift index c5ea295..322e1d1 100644 --- a/Source/Collection/CollectionRelease.swift +++ b/Source/Collection/CollectionRelease.swift @@ -2,6 +2,9 @@ import Foundation +// swiftlint:disable identifier_name +// swiftlint:disable nesting + public struct CollectionRelease: Codable { public var basicInformation: [Information]? @@ -71,3 +74,6 @@ public struct CollectionRelease: Codable { } } + +// swiftlint:enable identifier_name +// swiftlint:enable nesting diff --git a/Source/Database/Artist.swift b/Source/Database/Artist.swift index d3a9543..1b83c19 100644 --- a/Source/Database/Artist.swift +++ b/Source/Database/Artist.swift @@ -2,6 +2,8 @@ import Foundation +// swiftlint:disable identifier_name + public struct Artist: Codable, Unique { public var dataQuality: String? @@ -21,3 +23,5 @@ public struct Artist: Codable, Unique { } } + +// swiftlint:enable identifier_name diff --git a/Source/Database/ArtistSummary.swift b/Source/Database/ArtistSummary.swift index d794aea..1f29556 100644 --- a/Source/Database/ArtistSummary.swift +++ b/Source/Database/ArtistSummary.swift @@ -2,6 +2,8 @@ import Foundation +// swiftlint:disable identifier_name + public struct ArtistSummary: Codable, Unique { public var artistNameVariation: String? @@ -23,3 +25,5 @@ public struct ArtistSummary: Codable, Unique { } } + +// swiftlint:enable identifier_name diff --git a/Source/Database/BandMember.swift b/Source/Database/BandMember.swift index 7e5590f..d19bc0d 100644 --- a/Source/Database/BandMember.swift +++ b/Source/Database/BandMember.swift @@ -2,6 +2,8 @@ import Foundation +// swiftlint:disable identifier_name + public struct BandMember: Codable, Unique { public var active: Bool? @@ -10,3 +12,5 @@ public struct BandMember: Codable, Unique { public var resourceUrl: String } + +// swiftlint:enable identifier_name diff --git a/Source/Database/RecordLabel.swift b/Source/Database/RecordLabel.swift index ee4f6c7..a1a7654 100644 --- a/Source/Database/RecordLabel.swift +++ b/Source/Database/RecordLabel.swift @@ -2,6 +2,8 @@ import Foundation +// swiftlint:disable identifier_name + public struct RecordLabel: Codable, Unique { public var contactInfo: String? @@ -17,3 +19,5 @@ public struct RecordLabel: Codable, Unique { public var urls: [String]? } + +// swiftlint:enable identifier_name diff --git a/Source/Database/Release.swift b/Source/Database/Release.swift index b2fc082..106107a 100644 --- a/Source/Database/Release.swift +++ b/Source/Database/Release.swift @@ -2,6 +2,8 @@ import Foundation +// swiftlint:disable identifier_name + public struct Release: Codable, HasArtistSummaries, Unique { public var artists: [ArtistSummary]? @@ -76,3 +78,5 @@ public struct Release: Codable, HasArtistSummaries, Unique { } } + +// swiftlint:enable identifier_name diff --git a/Source/Database/ReleaseLabel.swift b/Source/Database/ReleaseLabel.swift index d460cf5..6bc746a 100644 --- a/Source/Database/ReleaseLabel.swift +++ b/Source/Database/ReleaseLabel.swift @@ -2,6 +2,8 @@ import Foundation +// swiftlint:disable identifier_name + public struct DiscogsReleaseLabel: Codable, Unique { public var catalogNumber: String? @@ -18,3 +20,5 @@ public struct DiscogsReleaseLabel: Codable, Unique { case resourceUrl } } + +// swiftlint:enable identifier_name diff --git a/Source/Database/ReleaseSummary.swift b/Source/Database/ReleaseSummary.swift index 1bf6820..26a6d60 100644 --- a/Source/Database/ReleaseSummary.swift +++ b/Source/Database/ReleaseSummary.swift @@ -2,6 +2,8 @@ import Foundation +// swiftlint:disable identifier_name + public struct ReleaseSummary: Codable, Unique { public var artist: String @@ -35,3 +37,5 @@ public struct ReleaseSummaries: Codable, Pageable { public var releases: [ReleaseSummary]? } + +// swiftlint:enable identifier_name diff --git a/Source/Database/Sublabel.swift b/Source/Database/Sublabel.swift index d8db914..43a51bf 100644 --- a/Source/Database/Sublabel.swift +++ b/Source/Database/Sublabel.swift @@ -2,6 +2,8 @@ import Foundation +// swiftlint:disable identifier_name + public struct Sublabel: Codable, Unique { public var id: Int @@ -9,3 +11,5 @@ public struct Sublabel: Codable, Unique { public var resourceUrl: String } + +// swiftlint:enable identifier_name diff --git a/Source/Unique.swift b/Source/Unique.swift index f26eb9d..bbe5acf 100644 --- a/Source/Unique.swift +++ b/Source/Unique.swift @@ -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 diff --git a/Source/User Identity/UserIdentity.swift b/Source/User Identity/UserIdentity.swift index 6a62dfb..8bb7d8d 100644 --- a/Source/User Identity/UserIdentity.swift +++ b/Source/User Identity/UserIdentity.swift @@ -2,6 +2,8 @@ import Foundation +// swiftlint:disable identifier_name + public struct UserIdentity: Codable, Unique { public var id: Int @@ -10,3 +12,5 @@ public struct UserIdentity: Codable, Unique { public var username: String } + +// swiftlint:enable identifier_name diff --git a/Source/User Identity/UserProfile.swift b/Source/User Identity/UserProfile.swift index a158414..0075a67 100644 --- a/Source/User Identity/UserProfile.swift +++ b/Source/User Identity/UserProfile.swift @@ -2,6 +2,8 @@ import Foundation +// swiftlint:disable identifier_name + public struct UserProfile: Codable { public var avatarUrl: String @@ -37,3 +39,5 @@ public struct UserProfile: Codable { public var wantlistUrl: URL } + +// swiftlint:enable identifier_name diff --git a/SwiftDiscogsApp/AppDelegate.swift b/SwiftDiscogsApp/AppDelegate.swift index 744ab53..4bb0307 100644 --- a/SwiftDiscogsApp/AppDelegate.swift +++ b/SwiftDiscogsApp/AppDelegate.swift @@ -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 @@ -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) diff --git a/SwiftDiscogsApp/Artist/ArtistsViewController.swift b/SwiftDiscogsApp/Artist/ArtistsViewController.swift index c609358..7557dd5 100644 --- a/SwiftDiscogsApp/Artist/ArtistsViewController.swift +++ b/SwiftDiscogsApp/Artist/ArtistsViewController.swift @@ -10,6 +10,8 @@ class ArtistsViewController: CollectionAndTableViewController, UISearchResultsUp // MARK: - Properties + // swiftlint:disable force_cast + var artistsDisplay: ArtistsDisplay { return display as! ArtistsDisplay } @@ -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?) { @@ -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() @@ -125,7 +130,7 @@ class ArtistsModel: CollectionAndTableModel { var artistMediaItems: [MPMediaItem] = [] { didSet { let artistNames = artistMediaItems.map { $0.albumArtist ?? "(unknown)" } - artists = Array(Set(artistNames)).sorted() + artists = [String](Set(artistNames)).sorted() } } diff --git a/SwiftDiscogsApp/Artist/DiscogsArtistViewController.swift b/SwiftDiscogsApp/Artist/DiscogsArtistViewController.swift index c6365f3..2f3249a 100644 --- a/SwiftDiscogsApp/Artist/DiscogsArtistViewController.swift +++ b/SwiftDiscogsApp/Artist/DiscogsArtistViewController.swift @@ -37,7 +37,7 @@ 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 } } @@ -45,7 +45,9 @@ public class DiscogsArtistViewController: UIViewController { } public var artistView: DiscogsArtistView { + // swiftlint:disable force_cast return view as! DiscogsArtistView + // swiftlint:enable force_cast } public var artistModel = DiscogsArtistModel() @@ -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) @@ -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 } } diff --git a/SwiftDiscogsApp/MediaLibrary/MPMediaCollectionBrowser.swift b/SwiftDiscogsApp/MediaLibrary/MPMediaCollectionBrowser.swift index 8582991..e77118e 100644 --- a/SwiftDiscogsApp/MediaLibrary/MPMediaCollectionBrowser.swift +++ b/SwiftDiscogsApp/MediaLibrary/MPMediaCollectionBrowser.swift @@ -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) diff --git a/SwiftDiscogsApp/MediaLibrary/MPMediaCollectionImporter.swift b/SwiftDiscogsApp/MediaLibrary/MPMediaCollectionImporter.swift index 52ae7c5..692be94 100644 --- a/SwiftDiscogsApp/MediaLibrary/MPMediaCollectionImporter.swift +++ b/SwiftDiscogsApp/MediaLibrary/MPMediaCollectionImporter.swift @@ -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 @@ -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 { diff --git a/SwiftDiscogsApp/MediaLibrary/MockMediaLibrary.swift b/SwiftDiscogsApp/MediaLibrary/MockMediaLibrary.swift index 7920d59..b57322a 100644 --- a/SwiftDiscogsApp/MediaLibrary/MockMediaLibrary.swift +++ b/SwiftDiscogsApp/MediaLibrary/MockMediaLibrary.swift @@ -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 }() diff --git a/SwiftDiscogsApp/MediaLibrary/iTunesMediaLibrary.swift b/SwiftDiscogsApp/MediaLibrary/iTunesMediaLibrary.swift index 77b8097..f09c9e8 100644 --- a/SwiftDiscogsApp/MediaLibrary/iTunesMediaLibrary.swift +++ b/SwiftDiscogsApp/MediaLibrary/iTunesMediaLibrary.swift @@ -2,6 +2,8 @@ import MediaPlayer +// swiftlint:disable type_name + public struct iTunesMediaLibrary: MediaLibrary { public func albums(byArtistNamed artistName: String?) -> [MPMediaItemCollection]? { @@ -86,3 +88,5 @@ private extension String { } } + +// swiftlint:enable type_name diff --git a/SwiftDiscogsApp/Release/MasterReleaseViewController.swift b/SwiftDiscogsApp/Release/MasterReleaseViewController.swift index f36a444..3250a41 100644 --- a/SwiftDiscogsApp/Release/MasterReleaseViewController.swift +++ b/SwiftDiscogsApp/Release/MasterReleaseViewController.swift @@ -25,7 +25,10 @@ public class MasterReleaseViewController: BaseReleaseViewController { } // Get the master release's versions. We don't have to wait for // the actual master release itself to be retrieved. - DiscogsManager.discogs.releasesForMasterRelease(masterReleaseID, pageNumber: 1, resultsPerPage: 200).done { [weak self] (releaseSummaries) in + DiscogsManager.discogs.releasesForMasterRelease(masterReleaseID, + pageNumber: 1, + resultsPerPage: 200) + .done { [weak self] (releaseSummaries) in self?.masterReleaseModel?.releaseVersions = releaseSummaries.versions self?.display?.refresh() }.catch { (error) in diff --git a/SwiftDiscogsApp/Release/ReleaseVersionViewController.swift b/SwiftDiscogsApp/Release/ReleaseVersionViewController.swift index 42548b4..ebc4009 100644 --- a/SwiftDiscogsApp/Release/ReleaseVersionViewController.swift +++ b/SwiftDiscogsApp/Release/ReleaseVersionViewController.swift @@ -16,7 +16,7 @@ class ReleaseVersionViewController: BaseReleaseViewController { if let releaseID = releaseVersion?.id { _ = DiscogsManager.discogs.release(identifier: releaseID).done { [weak self] (release) in self?.release = release - }.catch { (error) in + }.catch { _ in } } } @@ -152,7 +152,7 @@ public class ReleaseVersionView: CoverArtAndTableView { public var release: Release? { didSet { - release?.formats?.forEach { (format) in + release?.formats?.forEach { _ in } } diff --git a/SwiftDiscogsApp/Search/DiscogsSearchView.swift b/SwiftDiscogsApp/Search/DiscogsSearchView.swift index 525d197..27a7c5b 100644 --- a/SwiftDiscogsApp/Search/DiscogsSearchView.swift +++ b/SwiftDiscogsApp/Search/DiscogsSearchView.swift @@ -4,7 +4,7 @@ import Stylobate import UIKit /// The root view of the `DiscogsSearchViewController`. -open class DiscogsSearchView: DiscogsDisplay, SpinnerBusyView, UISearchBarDelegate { +open class DiscogsSearchView: DiscogsDisplay, SpinnerBusyView, UISearchBarDelegate { // MARK: - Private Outlets diff --git a/SwiftDiscogsApp/Song/Song.swift b/SwiftDiscogsApp/Song/Song.swift index 8ef4613..3c6ab55 100644 --- a/SwiftDiscogsApp/Song/Song.swift +++ b/SwiftDiscogsApp/Song/Song.swift @@ -48,6 +48,8 @@ open class Song: NSObject, Codable { } +// swiftlint:disable line_length + let songJSON = """ { "id": 99910009, @@ -72,3 +74,5 @@ let songJSON = """ ] } """ + +// swiftlint:enable line_length diff --git a/SwiftDiscogsApp/Third-Party Services/Discogs/CollectionCustomField+CoreData.swift b/SwiftDiscogsApp/Third-Party Services/Discogs/CollectionCustomField+CoreData.swift index 6762ba6..ef975e3 100644 --- a/SwiftDiscogsApp/Third-Party Services/Discogs/CollectionCustomField+CoreData.swift +++ b/SwiftDiscogsApp/Third-Party Services/Discogs/CollectionCustomField+CoreData.swift @@ -9,7 +9,7 @@ public extension CustomField { inContext context: NSManagedObjectContext) throws -> CustomField? { let predicate = NSPredicate(format: "id = \(discogsField.id)") let sortByID = (\CustomField.id).sortDescriptor() - var entity: CustomField? = nil + var entity: CustomField? if discogsField.type == CollectionCustomField.FieldType.dropdown.rawValue { let fetchRequest = CustomDropdownField.fetchRequest(sortDescriptors: [sortByID], diff --git a/SwiftDiscogsApp/Third-Party Services/Discogs/DiscogsCollectionImporter.swift b/SwiftDiscogsApp/Third-Party Services/Discogs/DiscogsCollectionImporter.swift index e361250..0ec38f2 100644 --- a/SwiftDiscogsApp/Third-Party Services/Discogs/DiscogsCollectionImporter.swift +++ b/SwiftDiscogsApp/Third-Party Services/Discogs/DiscogsCollectionImporter.swift @@ -57,12 +57,13 @@ public class DiscogsCollectionImporter: NSManagedObjectContext { public func importDiscogsCollection(forUserName userName: String) -> Promise { importerDelegate?.willBeginImporting(fromService: service) - return discogs.customCollectionFields(forUserName: userName).then(on: importQueue) { (discogsFieldsResult) -> Promise in + return discogs.customCollectionFields(forUserName: userName) + .then(on: importQueue) { (discogsFieldsResult) -> Promise in self.discogsFields = discogsFieldsResult.fields ?? [] self.importerDelegate?.update(importedItemCount: 1, totalCount: 6, forService: self.service) return self.createCoreDataFields(self.discogsFields) - }.then(on: importQueue) { _ in + }.then(on: importQueue) { _ -> Promise in self.importerDelegate?.update(importedItemCount: 2, totalCount: 6, forService: self.service) return self.discogs.collectionFolders(forUserName: userName) @@ -88,10 +89,10 @@ public class DiscogsCollectionImporter: NSManagedObjectContext { self.importerDelegate?.update(importedItemCount: 5, totalCount: 6, forService: self.service) return self.createCoreDataItems(forDiscogsItems: discogsItems) - }.then(on: importQueue) { _ in + }.then(on: importQueue) { _ -> Promise in self.importerDelegate?.update(importedItemCount: 6, totalCount: 6, forService: self.service) return self.addCoreDataItemsToOtherFolders(forUserName: userName) - }.then(on: importQueue) { _ in + }.then(on: importQueue) { _ -> Promise in self.importerDelegate?.willFinishImporting(fromService: self.service) try self.save() diff --git a/SwiftDiscogsApp/Third-Party Services/Discogs/DiscogsContainer.swift b/SwiftDiscogsApp/Third-Party Services/Discogs/DiscogsContainer.swift index cf2c2cc..fe66e47 100644 --- a/SwiftDiscogsApp/Third-Party Services/Discogs/DiscogsContainer.swift +++ b/SwiftDiscogsApp/Third-Party Services/Discogs/DiscogsContainer.swift @@ -21,7 +21,7 @@ public class DiscogsContainer: NSPersistentContainer { let model = NSManagedObjectModel(contentsOf: modelURL)! super.init(name: "DiscogsCollection", managedObjectModel: model) - loadPersistentStores { (storeDescription, error) in + loadPersistentStores { (_, error) in if let error = error as NSError? { fatalError("Unresolved error \(error), \(error.userInfo)") } @@ -35,8 +35,11 @@ public class DiscogsContainer: NSPersistentContainer { do { try viewContext.save() } catch { - // Replace this implementation with code to handle the error appropriately. - // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. + // Replace this implementation with code to handle the error + // appropriately. `fatalError()` causes the application to + // generate a crash log and terminate. You should not use this + // function in a shipping application, although it may be + // useful during development. let nserror = error as NSError fatalError("Unresolved error \(nserror), \(nserror.userInfo)") } diff --git a/SwiftDiscogsApp/Third-Party Services/Discogs/DiscogsService.swift b/SwiftDiscogsApp/Third-Party Services/Discogs/DiscogsService.swift index dbbd371..0ea1818 100644 --- a/SwiftDiscogsApp/Third-Party Services/Discogs/DiscogsService.swift +++ b/SwiftDiscogsApp/Third-Party Services/Discogs/DiscogsService.swift @@ -39,7 +39,7 @@ class DiscogsService: ThirdPartyService, AuthenticatedService, ImportableService // MARK: Properties /// Called when Discogs authentication is in progress. - var authenticationDelegate: AuthenticatedServiceDelegate? + weak var authenticationDelegate: AuthenticatedServiceDelegate? var importableItemCount: Int? { return userProfile?.numCollection @@ -81,7 +81,7 @@ class DiscogsService: ThirdPartyService, AuthenticatedService, ImportableService let promise = DiscogsManager.discogs.authorize(presentingViewController: viewController, callbackUrlString: AppDelegate.shared.callbackUrl.absoluteString) - promise.then { (credential) -> Promise in + promise.then { _ in return DiscogsManager.discogs.userIdentity() }.done { [weak self] (userIdentity) in self?.handle(userIdentity: userIdentity) diff --git a/SwiftDiscogsApp/Third-Party Services/ThirdPartyService.swift b/SwiftDiscogsApp/Third-Party Services/ThirdPartyService.swift index 7b8d0b6..817fae6 100644 --- a/SwiftDiscogsApp/Third-Party Services/ThirdPartyService.swift +++ b/SwiftDiscogsApp/Third-Party Services/ThirdPartyService.swift @@ -44,7 +44,7 @@ public protocol AuthenticatedService: ThirdPartyService { // MARK: - AuthenticatedServiceDelegate -public protocol AuthenticatedServiceDelegate { +public protocol AuthenticatedServiceDelegate: class { // MARK: Functions diff --git a/SwiftDiscogsApp/Third-Party Services/iTunes/MediaLibraryService.swift b/SwiftDiscogsApp/Third-Party Services/iTunes/MediaLibraryService.swift index 07a8b9f..3f7e861 100644 --- a/SwiftDiscogsApp/Third-Party Services/iTunes/MediaLibraryService.swift +++ b/SwiftDiscogsApp/Third-Party Services/iTunes/MediaLibraryService.swift @@ -8,7 +8,7 @@ final class MediaLibraryService: ThirdPartyService, ImportableService { var importableItemCount: Int? - var importedItemCount: Int = 0{ + var importedItemCount: Int = 0 { didSet { importDelegate?.update(importedItemCount: importedItemCount, totalCount: importableItemCount, @@ -16,7 +16,7 @@ final class MediaLibraryService: ThirdPartyService, ImportableService { } } - var importDelegate: ImportableServiceDelegate? + weak var importDelegate: ImportableServiceDelegate? var importer: MPMediaItemCollectionImporter? diff --git a/SwiftDiscogsAppTests/Artist/DiscogsArtistViewControllerTests.swift b/SwiftDiscogsAppTests/Artist/DiscogsArtistViewControllerTests.swift index bca10b4..ae22ff8 100644 --- a/SwiftDiscogsAppTests/Artist/DiscogsArtistViewControllerTests.swift +++ b/SwiftDiscogsAppTests/Artist/DiscogsArtistViewControllerTests.swift @@ -24,7 +24,7 @@ class DiscogsArtistViewControllerTests: XCTestCase { super.setUp() let bundle = Bundle(for: DiscogsArtistViewController.self) let storyboard = UIStoryboard(name: "Main", bundle: bundle) - viewController = storyboard.instantiateViewController(withIdentifier: "discogsArtist") as? DiscogsArtistViewController + viewController = storyboard.instantiateViewController(withIdentifier: "discogsArtist") XCTAssertNotNil(viewController) _ = viewController?.view // force viewDidLoad() to be called } diff --git a/SwiftDiscogsAppTests/Player/PlayerViewTests.swift b/SwiftDiscogsAppTests/Player/PlayerViewTests.swift index 2df76a5..285b430 100644 --- a/SwiftDiscogsAppTests/Player/PlayerViewTests.swift +++ b/SwiftDiscogsAppTests/Player/PlayerViewTests.swift @@ -26,7 +26,7 @@ class PlayerViewTests: XCTestCase { override func setUp() { let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: PlayerView.self)) - let playerViewController = storyboard.instantiateViewController(withIdentifier: "Player") as! PlayerViewController + let playerViewController = storyboard.instantiateViewController(withIdentifier: "Player") _ = playerViewController.view playerView = (playerViewController.view as? PlayerView)! } diff --git a/SwiftDiscogsAppTests/SectionedModelTests.swift b/SwiftDiscogsAppTests/SectionedModelTests.swift index 824fbfb..73647b5 100644 --- a/SwiftDiscogsAppTests/SectionedModelTests.swift +++ b/SwiftDiscogsAppTests/SectionedModelTests.swift @@ -10,7 +10,7 @@ class SectionedModelTests: XCTestCase { let model = SectionedModel() XCTAssertEqual(model.tableView.numberOfSections, 0) - XCTAssertEqual(model.collectionView.numberOfSections , 0) + XCTAssertEqual(model.collectionView.numberOfSections, 0) } func testInitializerWith1Section() { diff --git a/SwiftDiscogsAppTests/Song/SongModelTests.swift b/SwiftDiscogsAppTests/Song/SongModelTests.swift index d24ea94..2c3f65a 100644 --- a/SwiftDiscogsAppTests/Song/SongModelTests.swift +++ b/SwiftDiscogsAppTests/Song/SongModelTests.swift @@ -5,6 +5,8 @@ import Stylobate import XCTest +// swiftlint:disable force_try + class SongTests: XCTestCase { func testSongModelWithNoSongHasNoSections() { @@ -121,3 +123,5 @@ class SongTests: XCTestCase { }() } + +// swiftlint:enable force_try diff --git a/SwiftDiscogsAppTests/Third-Party Services/Discogs/DiscogsCollectionImporterTests.swift b/SwiftDiscogsAppTests/Third-Party Services/Discogs/DiscogsCollectionImporterTests.swift index b9b8e9b..e00b4ac 100644 --- a/SwiftDiscogsAppTests/Third-Party Services/Discogs/DiscogsCollectionImporterTests.swift +++ b/SwiftDiscogsAppTests/Third-Party Services/Discogs/DiscogsCollectionImporterTests.swift @@ -30,8 +30,9 @@ class DiscogsCollectionImporterTests: XCTestCase { importer.importDiscogsCollection(forUserName: "doesn't matter").done { [unowned self] in let fields: [CustomField] = try CustomField.all(inContext: self.importer) let folders: [Folder] = try Folder.all(inContext: self.importer) + let sortDescriptors = [(\CollectionItem.releaseVersionID).sortDescriptor()] let items: [CollectionItem] = try CollectionItem.all(inContext: self.importer, - sortedBy: [(\CollectionItem.releaseVersionID).sortDescriptor()]) + sortedBy: sortDescriptors) if fields.count == 3 && folders.count == 2 && folders[0].name == "All"