Use Swift 5.7 if-let style

This commit is contained in:
Arkadiusz Fal
2022-09-28 16:27:01 +02:00
parent 8f96a7c5e0
commit a086a0f440
50 changed files with 114 additions and 114 deletions

View File

@@ -11,14 +11,14 @@ struct DropFavorite: DropDelegate {
return
}
guard let current = current else {
guard let current else {
return
}
let from = favorites.firstIndex(of: current)
let to = favorites.firstIndex(of: item)
guard let from = from, let to = to else {
guard let from, let to else {
return
}

View File

@@ -32,7 +32,7 @@ struct Buffering: View {
Text(reason)
.font(.system(size: playerControlsLayout.timeFontSize))
if let state = state {
if let state {
Text(state)
.font(.system(size: playerControlsLayout.bufferingStateFontSize).monospacedDigit())
}

View File

@@ -206,12 +206,12 @@ struct PlayerControls: View {
}
var detailsWidth: Double {
guard let player = player, player.playerSize.width.isFinite else { return 200 }
guard let player, player.playerSize.width.isFinite else { return 200 }
return [player.playerSize.width, 600].min()!
}
var detailsHeight: Double {
guard let player = player, player.playerSize.height.isFinite else { return 200 }
guard let player, player.playerSize.height.isFinite else { return 200 }
return [player.playerSize.height, 500].min()!
}

View File

@@ -36,7 +36,7 @@ final class MPVOGLView: GLKView {
}
override func draw(_: CGRect) {
guard needsDrawing, let mpvGL = mpvGL else {
guard needsDrawing, let mpvGL else {
return
}

View File

@@ -53,7 +53,7 @@ struct StreamControl: View {
}
.transaction { t in t.animation = .none }
.onChange(of: player.streamSelection) { selection in
guard let selection = selection else { return }
guard let selection else { return }
player.upgradeToStream(selection)
player.controls.hideOverlays()
}

View File

@@ -143,7 +143,7 @@ struct VideoDetails: View {
var publishedDateSection: some View {
Group {
if let video = video {
if let video {
HStack(spacing: 4) {
if let published = video.publishedDate {
Text(published)
@@ -227,7 +227,7 @@ struct VideoDetails: View {
var detailsPage: some View {
VStack(alignment: .leading, spacing: 0) {
if let video = video {
if let video {
VStack(spacing: 6) {
videoProperties

View File

@@ -33,7 +33,7 @@ struct VideoPlayerSizeModifier: ViewModifier {
}
var usedAspectRatio: Double {
guard let aspectRatio = aspectRatio, aspectRatio > 0, aspectRatio < VideoPlayerView.defaultAspectRatio else {
guard let aspectRatio, aspectRatio > 0, aspectRatio < VideoPlayerView.defaultAspectRatio else {
return VideoPlayerView.defaultAspectRatio
}

View File

@@ -46,7 +46,7 @@ struct SearchTextField: View {
.padding(.trailing, 15)
#endif
if let favoriteItem = favoriteItem {
if let favoriteItem {
#if os(iOS)
FavoriteButton(item: favoriteItem)
.id(favoriteItem.id)

View File

@@ -117,7 +117,7 @@ struct SearchView: View {
#endif
}
.onAppear {
if let query = query {
if let query {
state.queryText = query.query
state.resetQuery(query)
updateFavoriteItem()

View File

@@ -18,7 +18,7 @@ struct AccountValidationStatus: View {
VStack(alignment: .leading) {
Text(isValid ? "Connected successfully (\(app?.name ?? "Unknown"))" : "Connection failed")
if let error = error, !isValid {
if let error, !isValid {
Text(error)
.font(.caption2)
.foregroundColor(.secondary)

View File

@@ -134,7 +134,7 @@ struct InstanceForm: View {
}
func submitForm() {
guard isValid, let app = app else {
guard isValid, let app else {
return
}

View File

@@ -49,7 +49,7 @@ struct TrendingView: View {
Spacer()
}
if let favoriteItem = favoriteItem {
if let favoriteItem {
FavoriteButton(item: favoriteItem, labelPadding: true)
.id(favoriteItem.id)
.labelStyle(.iconOnly)
@@ -85,7 +85,7 @@ struct TrendingView: View {
.toolbar {
#if os(macOS)
ToolbarItemGroup {
if let favoriteItem = favoriteItem {
if let favoriteItem {
FavoriteButton(item: favoriteItem)
.id(favoriteItem.id)
}
@@ -179,7 +179,7 @@ struct TrendingView: View {
}
#if os(tvOS)
if let favoriteItem = favoriteItem {
if let favoriteItem {
FavoriteButton(item: favoriteItem)
.id(favoriteItem.id)
.labelStyle(.iconOnly)

View File

@@ -55,7 +55,7 @@ struct URLParser {
}
var isYoutubeHost: Bool {
guard let urlComponents = urlComponents else { return false }
guard let urlComponents else { return false }
return urlComponents.host == "youtube.com" || urlComponents.host == "www.youtube.com"
}
@@ -132,7 +132,7 @@ struct URLParser {
}
private var pathWithoutForwardSlash: String {
guard let urlComponents = urlComponents else { return "" }
guard let urlComponents else { return "" }
return String(urlComponents.path.dropFirst())
}

View File

@@ -280,7 +280,7 @@ struct VideoCell: View {
}
}
if let time = time, !timeOnThumbnail {
if let time, !timeOnThumbnail {
Spacer()
HStack(spacing: 2) {
@@ -403,7 +403,7 @@ struct VideoCell: View {
if timeOnThumbnail,
!video.live,
let time = time
let time
{
DetailBadge(text: time, style: .prominent)
}
@@ -429,7 +429,7 @@ struct VideoCell: View {
}
.retryOnAppear(true)
.onFailure { _ in
guard let url = url else { return }
guard let url else { return }
thumbnails.insertUnloadable(url)
}

View File

@@ -48,7 +48,7 @@ struct ControlsBar: View {
#if os(iOS)
.background(
EmptyView().sheet(isPresented: $presentingShareSheet) {
if let shareURL = shareURL {
if let shareURL {
ShareSheet(activityItems: [shareURL])
}
}

View File

@@ -39,7 +39,7 @@ struct VideoContextMenuView: View {
@ViewBuilder var contextMenu: some View {
if saveHistory {
Section {
if let watchedAtString = watchedAtString {
if let watchedAtString {
Text(watchedAtString)
}
@@ -115,7 +115,7 @@ struct VideoContextMenuView: View {
return "Watching now".localized()
}
if let watch = watch, let watchedAtString = watch.watchedAtString {
if let watch, let watchedAtString = watch.watchedAtString {
if watchedAtString == "in 0 seconds" {
return "Just watched".localized()
}
@@ -144,7 +144,7 @@ struct VideoContextMenuView: View {
var removeFromHistoryButton: some View {
Button {
guard let watch = watch else {
guard let watch else {
return
}