diff --git a/Model/Accounts/AccountsBridge.swift b/Model/Accounts/AccountsBridge.swift index 36ffe850..70fe94e3 100644 --- a/Model/Accounts/AccountsBridge.swift +++ b/Model/Accounts/AccountsBridge.swift @@ -13,7 +13,7 @@ struct AccountsBridge: Defaults.Bridge { return [ "id": value.id, "instanceID": value.instanceID ?? "", - "name": value.name ?? "", + "name": value.name, "apiURL": value.urlString, "username": value.username, "password": value.password ?? "" diff --git a/Model/Accounts/AccountsModel.swift b/Model/Accounts/AccountsModel.swift index 2f528fdd..7d0ffb97 100644 --- a/Model/Accounts/AccountsModel.swift +++ b/Model/Accounts/AccountsModel.swift @@ -24,7 +24,7 @@ final class AccountsModel: ObservableObject { return nil } - return AccountsModel.find(id) + return Self.find(id) } var any: Account? { diff --git a/Model/Accounts/InstancesModel.swift b/Model/Accounts/InstancesModel.swift index 4b70360c..0a7d57aa 100644 --- a/Model/Accounts/InstancesModel.swift +++ b/Model/Accounts/InstancesModel.swift @@ -13,7 +13,7 @@ final class InstancesModel: ObservableObject { return nil } - return InstancesModel.shared.find(id) + return Self.shared.find(id) } var lastUsed: Instance? { @@ -21,7 +21,7 @@ final class InstancesModel: ObservableObject { return nil } - return InstancesModel.shared.find(id) + return Self.shared.find(id) } func find(_ id: Instance.ID?) -> Instance? { diff --git a/Model/Applications/InvidiousAPI.swift b/Model/Applications/InvidiousAPI.swift index 6ab26b4b..fd444542 100644 --- a/Model/Applications/InvidiousAPI.swift +++ b/Model/Applications/InvidiousAPI.swift @@ -579,8 +579,6 @@ final class InvidiousAPI: Service, ObservableObject, VideosAPI { let nextPage = json.dictionaryValue["continuation"]?.string var contentItems = [ContentItem]() - var items = [ContentItem]() - if let key = Self.contentItemsKeys.first(where: { json.dictionaryValue.keys.contains($0) }), let items = json.dictionaryValue[key] { diff --git a/Model/Cache/BaseCacheModel.swift b/Model/Cache/BaseCacheModel.swift index 7fa12c6a..a98af136 100644 --- a/Model/Cache/BaseCacheModel.swift +++ b/Model/Cache/BaseCacheModel.swift @@ -4,7 +4,7 @@ import Logging import SwiftyJSON struct BaseCacheModel { - static var shared = BaseCacheModel() + static var shared = Self() static let jsonToDataTransformer: (JSON) -> Data = { try! $0.rawData() } static let jsonFromDataTransformer: (Data) -> JSON = { try! JSON(data: $0) } diff --git a/Model/Cache/BookmarksCacheModel.swift b/Model/Cache/BookmarksCacheModel.swift index c4cdd9d5..d5c59f9d 100644 --- a/Model/Cache/BookmarksCacheModel.swift +++ b/Model/Cache/BookmarksCacheModel.swift @@ -4,7 +4,7 @@ import Logging import SwiftyJSON struct BookmarksCacheModel { - static var shared = BookmarksCacheModel() + static var shared = Self() let logger = Logger(label: "stream.yattee.cache") static let bookmarksGroup = "group.stream.yattee.app.bookmarks" diff --git a/Model/Cache/ChannelPlaylistsCacheModel.swift b/Model/Cache/ChannelPlaylistsCacheModel.swift index 60f3d0df..e9cbc211 100644 --- a/Model/Cache/ChannelPlaylistsCacheModel.swift +++ b/Model/Cache/ChannelPlaylistsCacheModel.swift @@ -4,7 +4,7 @@ import Logging import SwiftyJSON struct ChannelPlaylistsCacheModel: CacheModel { - static let shared = ChannelPlaylistsCacheModel() + static let shared = Self() let logger = Logger(label: "stream.yattee.cache.channel-playlists") static let diskConfig = DiskConfig(name: "channel-playlists") diff --git a/Model/Cache/ChannelsCacheModel.swift b/Model/Cache/ChannelsCacheModel.swift index 05b466a0..a5d23c2f 100644 --- a/Model/Cache/ChannelsCacheModel.swift +++ b/Model/Cache/ChannelsCacheModel.swift @@ -4,7 +4,7 @@ import Logging import SwiftyJSON struct ChannelsCacheModel: CacheModel { - static let shared = ChannelsCacheModel() + static let shared = Self() let logger = Logger(label: "stream.yattee.cache.channels") static let diskConfig = DiskConfig(name: "channels") diff --git a/Model/Cache/FeedCacheModel.swift b/Model/Cache/FeedCacheModel.swift index b446e203..002d32d0 100644 --- a/Model/Cache/FeedCacheModel.swift +++ b/Model/Cache/FeedCacheModel.swift @@ -5,7 +5,7 @@ import Logging import SwiftyJSON struct FeedCacheModel: CacheModel { - static let shared = FeedCacheModel() + static let shared = Self() let logger = Logger(label: "stream.yattee.cache.feed") static let diskConfig = DiskConfig(name: "feed") diff --git a/Model/Cache/PlaylistsCacheModel.swift b/Model/Cache/PlaylistsCacheModel.swift index 4120edaa..ca791cc7 100644 --- a/Model/Cache/PlaylistsCacheModel.swift +++ b/Model/Cache/PlaylistsCacheModel.swift @@ -4,7 +4,7 @@ import Logging import SwiftyJSON struct PlaylistsCacheModel: CacheModel { - static let shared = PlaylistsCacheModel() + static let shared = Self() static let limit = 30 let logger = Logger(label: "stream.yattee.cache.playlists") diff --git a/Model/Cache/VideosCacheModel.swift b/Model/Cache/VideosCacheModel.swift index a3700fd1..840bd25c 100644 --- a/Model/Cache/VideosCacheModel.swift +++ b/Model/Cache/VideosCacheModel.swift @@ -4,7 +4,7 @@ import Logging import SwiftyJSON struct VideosCacheModel: CacheModel { - static let shared = VideosCacheModel() + static let shared = Self() let logger = Logger(label: "stream.yattee.cache.videos") static let diskConfig = DiskConfig(name: "videos") diff --git a/Model/Channel.swift b/Model/Channel.swift index 044ed12d..b54230b3 100644 --- a/Model/Channel.swift +++ b/Model/Channel.swift @@ -91,7 +91,9 @@ struct Channel: Identifiable, Hashable { var subscriptionsText: String? var totalViews: Int? - var verified: Bool? // swiftlint:disable discouraged_optional_boolean + // swiftlint:disable discouraged_optional_boolean + var verified: Bool? + // swiftlint:enable discouraged_optional_boolean var videos = [Video]() var tabs = [Tab]() diff --git a/Model/ChannelPlaylist.swift b/Model/ChannelPlaylist.swift index a8545cab..bc43fde0 100644 --- a/Model/ChannelPlaylist.swift +++ b/Model/ChannelPlaylist.swift @@ -25,7 +25,7 @@ struct ChannelPlaylist: Identifiable { } static func from(_ json: JSON) -> Self { - ChannelPlaylist( + Self( id: json["id"].stringValue, title: json["title"].stringValue, thumbnailURL: json["thumbnailURL"].url, diff --git a/Model/CommentsModel.swift b/Model/CommentsModel.swift index fdf904d9..11a89106 100644 --- a/Model/CommentsModel.swift +++ b/Model/CommentsModel.swift @@ -42,7 +42,9 @@ final class CommentsModel: ObservableObject { firstPage = page.isNil || page!.isEmpty - player.playerAPI(video)?.comments(video.videoID, page: page)? + player + .playerAPI(video)? + .comments(video.videoID, page: page)? .load() .onSuccess { [weak self] response in if let page: CommentsPage = response.typedContent() { diff --git a/Model/ContentItem.swift b/Model/ContentItem.swift index 07a3fb40..e07982a1 100644 --- a/Model/ContentItem.swift +++ b/Model/ContentItem.swift @@ -31,15 +31,15 @@ struct ContentItem: Identifiable { var id: String = UUID().uuidString static func array(of videos: [Video]) -> [ContentItem] { - videos.map { ContentItem(video: $0) } + videos.map { Self(video: $0) } } static func array(of playlists: [ChannelPlaylist]) -> [ContentItem] { - playlists.map { ContentItem(playlist: $0) } + playlists.map { Self(playlist: $0) } } static func array(of channels: [Channel]) -> [ContentItem] { - channels.map { ContentItem(channel: $0) } + channels.map { Self(channel: $0) } } static func < (lhs: ContentItem, rhs: ContentItem) -> Bool { diff --git a/Model/Country.swift b/Model/Country.swift index 890369e0..a3d23606 100644 --- a/Model/Country.swift +++ b/Model/Country.swift @@ -234,6 +234,8 @@ extension Country { } } + // swiftlint:enable switch_case_on_newline + var flag: String { let unicodeScalars = rawValue .unicodeScalars diff --git a/Model/FavoritesModel.swift b/Model/FavoritesModel.swift index f7fc60c6..ac2b85f9 100644 --- a/Model/FavoritesModel.swift +++ b/Model/FavoritesModel.swift @@ -2,7 +2,7 @@ import Defaults import Foundation struct FavoritesModel { - static let shared = FavoritesModel() + static let shared = Self() @Default(.showFavoritesInHome) var showFavoritesInHome @Default(.favorites) var all diff --git a/Model/KeychainModel.swift b/Model/KeychainModel.swift index a68a4f6c..127f0267 100644 --- a/Model/KeychainModel.swift +++ b/Model/KeychainModel.swift @@ -2,7 +2,7 @@ import Foundation import KeychainAccess struct KeychainModel { - static var shared = KeychainModel() + static var shared = Self() var keychain = Keychain(service: "stream.yattee.app") diff --git a/Model/NavigationModel.swift b/Model/NavigationModel.swift index dfa6fde8..96a31cc2 100644 --- a/Model/NavigationModel.swift +++ b/Model/NavigationModel.swift @@ -46,7 +46,7 @@ final class NavigationModel: ObservableObject { case .search: return "search" #if os(tvOS) - case .settings: // swiftlint:disable:this switch_case_alignment + case .settings: return "settings" #endif default: diff --git a/Model/OpenVideosModel.swift b/Model/OpenVideosModel.swift index 046f89a4..55876fd1 100644 --- a/Model/OpenVideosModel.swift +++ b/Model/OpenVideosModel.swift @@ -37,7 +37,7 @@ struct OpenVideosModel { } } - static let shared = OpenVideosModel() + static let shared = Self() var player: PlayerModel! = .shared var logger = Logger(label: "stream.yattee.open-videos") diff --git a/Model/PersistenceController.swift b/Model/PersistenceController.swift index ebbb86e5..8e90c849 100644 --- a/Model/PersistenceController.swift +++ b/Model/PersistenceController.swift @@ -1,10 +1,10 @@ import CoreData struct PersistenceController { - static let shared = PersistenceController() + static let shared = Self() static var preview: PersistenceController = { - let result = PersistenceController(inMemory: true) + let result = Self(inMemory: true) let viewContext = result.container.viewContext do { diff --git a/Model/Player/ScreenSaverManager.swift b/Model/Player/ScreenSaverManager.swift index c981f753..8eeed900 100644 --- a/Model/Player/ScreenSaverManager.swift +++ b/Model/Player/ScreenSaverManager.swift @@ -2,7 +2,7 @@ import Foundation import IOKit.pwr_mgt struct ScreenSaverManager { - static var shared = ScreenSaverManager() + static var shared = Self() var noSleepAssertion: IOPMAssertionID = 0 var noSleepReturn: IOReturn? diff --git a/Model/QualityProfilesModel.swift b/Model/QualityProfilesModel.swift index ee0db821..b9dab2f4 100644 --- a/Model/QualityProfilesModel.swift +++ b/Model/QualityProfilesModel.swift @@ -6,7 +6,7 @@ import Foundation #endif struct QualityProfilesModel { - static let shared = QualityProfilesModel() + static let shared = Self() #if os(tvOS) var tvOSProfile: QualityProfile? { diff --git a/Model/URLBookmarkModel.swift b/Model/URLBookmarkModel.swift index 21751d92..557066ba 100644 --- a/Model/URLBookmarkModel.swift +++ b/Model/URLBookmarkModel.swift @@ -3,7 +3,7 @@ import Logging struct URLBookmarkModel { static let bookmarkPrefix = "urlbookmark-" - static var shared = URLBookmarkModel() + static var shared = Self() var logger = Logger(label: "stream.yattee.url-bookmark") diff --git a/Model/UnwatchedFeedCountModel.swift b/Model/UnwatchedFeedCountModel.swift index d97b9cac..00575946 100644 --- a/Model/UnwatchedFeedCountModel.swift +++ b/Model/UnwatchedFeedCountModel.swift @@ -32,4 +32,5 @@ final class UnwatchedFeedCountModel: ObservableObject { } return nil } + // swiftlint:enable empty_count } diff --git a/Model/Video.swift b/Model/Video.swift index 9920ca63..4913d123 100644 --- a/Model/Video.swift +++ b/Model/Video.swift @@ -117,7 +117,7 @@ struct Video: Identifiable, Equatable, Hashable { } static func local(_ url: URL) -> Video { - Video( + Self( app: .local, videoID: url.absoluteString, streams: [.init(localURL: url)] @@ -167,7 +167,7 @@ struct Video: Identifiable, Equatable, Hashable { static func from(_ json: JSON) -> Self { let dateFormatter = ISO8601DateFormatter() - return Video( + return Self( instanceID: json["instanceID"].stringValue, app: .init(rawValue: json["app"].stringValue) ?? AccountsModel.shared.current.app ?? .local, instanceURL: URL(string: json["instanceURL"].stringValue) ?? AccountsModel.shared.current.instance.apiURL, diff --git a/Shared/Channels/ChannelVideosView.swift b/Shared/Channels/ChannelVideosView.swift index 7a673f8f..d8fadd98 100644 --- a/Shared/Channels/ChannelVideosView.swift +++ b/Shared/Channels/ChannelVideosView.swift @@ -327,7 +327,7 @@ struct ChannelVideosView: View { private var contentTypePicker: some View { Picker("Content type", selection: $contentType) { - if let channel = presentedChannel { + if presentedChannel != nil { ForEach(Channel.ContentType.allCases, id: \.self) { type in if typeAvailable(type) { Label(type.description, systemImage: type.systemImage).tag(type) @@ -432,18 +432,20 @@ struct ChannelVideosView: View { } func load() { - resource?.load().onSuccess { response in - if let page: ChannelPage = response.typedContent() { - if let channel = page.channel { - ChannelsCacheModel.shared.store(channel) + resource? + .load() + .onSuccess { response in + if let page: ChannelPage = response.typedContent() { + if let channel = page.channel { + ChannelsCacheModel.shared.store(channel) + } + self.page = page + self.contentTypeItems.replace(page.results) } - self.page = page - self.contentTypeItems.replace(page.results) } - } - .onFailure { error in - navigation.presentAlert(title: "Could not load channel data", message: error.userMessage) - } + .onFailure { error in + navigation.presentAlert(title: "Could not load channel data", message: error.userMessage) + } } func loadNextPage() { diff --git a/Shared/Documents/DocumentsView.swift b/Shared/Documents/DocumentsView.swift index 7b15fc41..46274335 100644 --- a/Shared/Documents/DocumentsView.swift +++ b/Shared/Documents/DocumentsView.swift @@ -16,7 +16,7 @@ struct DocumentsView: View { Group { if model.isDirectory(standardizedURL) { - NavigationLink(destination: DocumentsView(directoryURL: url)) { + NavigationLink(destination: Self(directoryURL: url)) { VideoBanner(video: video) } } else { diff --git a/Shared/OpenURLHandler.swift b/Shared/OpenURLHandler.swift index 0994770c..03651e25 100644 --- a/Shared/OpenURLHandler.swift +++ b/Shared/OpenURLHandler.swift @@ -4,7 +4,7 @@ import Siesta struct OpenURLHandler { static var firstHandle = true - static var shared = OpenURLHandler() + static var shared = Self() static let yatteeProtocol = "yattee://" var accounts: AccountsModel { .shared } diff --git a/Shared/Player/AppleAVPlayerView.swift b/Shared/Player/AppleAVPlayerView.swift index 87eca885..bdbd9ece 100644 --- a/Shared/Player/AppleAVPlayerView.swift +++ b/Shared/Player/AppleAVPlayerView.swift @@ -5,8 +5,7 @@ import SwiftUI #if os(iOS) struct AppleAVPlayerView: UIViewRepresentable { func makeUIView(context _: Context) -> some UIView { - let playerLayerView = PlayerLayerView(frame: .zero) - return playerLayerView + PlayerLayerView(frame: .zero) } func updateUIView(_: UIViewType, context _: Context) {} diff --git a/Shared/Player/Video Details/CommentView.swift b/Shared/Player/Video Details/CommentView.swift index 28f2d0b6..1cccafba 100644 --- a/Shared/Player/Video Details/CommentView.swift +++ b/Shared/Player/Video Details/CommentView.swift @@ -204,7 +204,7 @@ struct CommentView: View { Group { let last = comments.replies.last ForEach(comments.replies) { comment in - CommentView(comment: comment, repliesID: $repliesID) + Self(comment: comment, repliesID: $repliesID) #if os(tvOS) .focusable() #endif