Skip to content

Commit

Permalink
Format all sources using swift-format
Browse files Browse the repository at this point in the history
  • Loading branch information
mbernson committed Jan 26, 2025
1 parent 51472fd commit 4916528
Show file tree
Hide file tree
Showing 30 changed files with 306 additions and 193 deletions.
7 changes: 7 additions & 0 deletions .swift-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"indentation" : {
"spaces" : 4
},
"tabWidth" : 4,
"version" : 1
}
3 changes: 0 additions & 3 deletions .swiftformat

This file was deleted.

4 changes: 0 additions & 4 deletions .swiftlint.yml

This file was deleted.

4 changes: 2 additions & 2 deletions CCCApi/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ let package = Package(
.library(
name: "CCCApi",
targets: ["CCCApi"]
),
)
],
dependencies: [
// Dependencies declare other packages that this package depends on.
Expand All @@ -23,6 +23,6 @@ let package = Package(
.target(
name: "CCCApi",
dependencies: []
),
)
]
)
18 changes: 12 additions & 6 deletions CCCApi/Sources/CCCApi/ApiService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public class ApiService {
if let date = self.iso8601Formatter.date(from: dateString) {
return date
} else {
throw DecodingError.dataCorruptedError(in: container, debugDescription: "Unable to parse ISO 8601 date")
throw DecodingError.dataCorruptedError(
in: container, debugDescription: "Unable to parse ISO 8601 date")
}
}
}
Expand All @@ -46,14 +47,16 @@ public class ApiService {
}

public func conference(acronym: String) async throws -> Conference {
let (data, _) = try await session.data(from: baseURL.appendingPathComponent("conferences").appendingPathComponent(acronym))
let (data, _) = try await session.data(
from: baseURL.appendingPathComponent("conferences").appendingPathComponent(acronym))
return try decoder.decode(Conference.self, from: data)
}

// MARK: Talks

public func talk(id: String) async throws -> Talk {
let (data, _) = try await session.data(from: baseURL.appendingPathComponent("events").appendingPathComponent(id))
let (data, _) = try await session.data(
from: baseURL.appendingPathComponent("events").appendingPathComponent(id))
let response = try decoder.decode(Talk.self, from: data)
return response
}
Expand All @@ -65,7 +68,8 @@ public class ApiService {
}

public func recentTalks() async throws -> [Talk] {
let (data, _) = try await session.data(from: baseURL.appendingPathComponent("events").appendingPathComponent("recent"))
let (data, _) = try await session.data(
from: baseURL.appendingPathComponent("events").appendingPathComponent("recent"))
let response = try decoder.decode(EventsResponse.self, from: data)
return response.events
}
Expand All @@ -91,12 +95,14 @@ public class ApiService {
// MARK: Recordings

public func recordings(for talk: Talk) async throws -> [Recording] {
let (data, _) = try await session.data(from: baseURL.appendingPathComponent("events").appendingPathComponent(talk.guid))
let (data, _) = try await session.data(
from: baseURL.appendingPathComponent("events").appendingPathComponent(talk.guid))
let response = try decoder.decode(TalkExtended.self, from: data)
guard let recordings = response.recordings else {
return []
}
return recordings
return
recordings
// Remove formats Apple doesn't support
.filter { !$0.mimeType.contains("opus") }
.filter { !$0.mimeType.contains("webm") }
Expand Down
10 changes: 8 additions & 2 deletions CCCApi/Sources/CCCApi/Models/Conference.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ public struct Conference: Decodable, Identifiable, Sendable {

public var id: String { slug }

init(acronym: String, slug: String, title: String, updatedAt: Date, eventLastReleasedAt: Date? = nil, events: [Talk]? = nil, link: URL? = nil, description: String? = nil, aspectRatio: AspectRatio? = nil, webgenLocation: String, url: URL, logoURL: URL, imagesURL: URL? = nil, recordingsURL: URL? = nil) {
init(
acronym: String, slug: String, title: String, updatedAt: Date,
eventLastReleasedAt: Date? = nil, events: [Talk]? = nil, link: URL? = nil,
description: String? = nil, aspectRatio: AspectRatio? = nil, webgenLocation: String,
url: URL, logoURL: URL, imagesURL: URL? = nil, recordingsURL: URL? = nil
) {
self.acronym = acronym
self.slug = slug
self.title = title
Expand Down Expand Up @@ -101,7 +106,8 @@ public struct AspectRatio: Decodable, Sendable {
let parts = string.components(separatedBy: ":")
.compactMap(Double.init)
if parts.count != 2 {
throw DecodingError.dataCorruptedError(in: container, debugDescription: "Invalid aspect ratio")
throw DecodingError.dataCorruptedError(
in: container, debugDescription: "Invalid aspect ratio")
} else {
width = parts[0]
height = parts[1]
Expand Down
86 changes: 60 additions & 26 deletions CCCApi/Sources/CCCApi/Models/Examples.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ import Foundation

// swiftlint:disable force_try

public extension Conference {
static let example = Conference(
extension Conference {
public static let example = Conference(
acronym: "MCH2022",
slug: "conferences/camp-NL/mch2022",
title: "May Contain Hackers 2022",
updatedAt: try! Date("2022-07-29T20:45:05Z", strategy: .iso8601),
eventLastReleasedAt: try! Date("2022-07-26T00:00:00Z", strategy: .iso8601),
link: URL(string: "https://mch2022.org/")!,
description: "MCH2022 was a nonprofit outdoor hacker camp taking place in Zeewolde, the Netherlands, July 22 to 26 2022. The event is organized for and by volunteers from and around all facets of the worldwide hacker community.\r\n\r\nKnowledge sharing, technological advancement, experimentation, connecting with your hacker peers and hacking are some of the core values of this event.\r\n\r\nMCH2022 is the successor of a string of similar events happening every four years since 1989. These are GHP, HEU, HIP, HAL, WTH, HAR, OHM and SHA.",
description:
"MCH2022 was a nonprofit outdoor hacker camp taking place in Zeewolde, the Netherlands, July 22 to 26 2022. The event is organized for and by volunteers from and around all facets of the worldwide hacker community.\r\n\r\nKnowledge sharing, technological advancement, experimentation, connecting with your hacker peers and hacking are some of the core values of this event.\r\n\r\nMCH2022 is the successor of a string of similar events happening every four years since 1989. These are GHP, HEU, HIP, HAL, WTH, HAR, OHM and SHA.",
aspectRatio: AspectRatio(width: 16, height: 9),
webgenLocation: "conferences/camp-NL/mch2022",
url: URL(string: "https://static.media.ccc.de/media/events/MCH2022/logo.png")!,
Expand All @@ -27,8 +28,8 @@ public extension Conference {
)
}

public extension Talk {
static let example = Talk(
extension Talk {
public static let example = Talk(
guid: "cf4dc17c-aab4-5868-9b57-100a55a1c2fb",
title: "⚠️ May Contain Hackers 2022 Closing",
subtitle: nil,
Expand All @@ -37,7 +38,7 @@ public extension Talk {
description: "It's over before you know it...",
originalLanguage: "eng",
persons: [
"Elger \"Stitch\" Jonker",
"Elger \"Stitch\" Jonker"
],
tags: [
"mch2022",
Expand All @@ -54,18 +55,32 @@ public extension Talk {
duration: 1066,
conferenceTitle: "May Contain Hackers 2022",
conferenceURL: URL(string: "https://api.media.ccc.de/public/conferences/MCH2022")!,
thumbURL: URL(string: "https://static.media.ccc.de/media/events/MCH2022/110-cf4dc17c-aab4-5868-9b57-100a55a1c2fb.jpg")!,
posterURL: URL(string: "https://static.media.ccc.de/media/events/MCH2022/110-cf4dc17c-aab4-5868-9b57-100a55a1c2fb_preview.jpg")!,
timelineURL: URL(string: "https://static.media.ccc.de/media/events/MCH2022/110-cf4dc17c-aab4-5868-9b57-100a55a1c2fb.timeline.jpg")!,
thumbnailsURL: URL(string: "https://static.media.ccc.de/media/events/MCH2022/110-cf4dc17c-aab4-5868-9b57-100a55a1c2fb.thumbnails.vtt")!,
frontendLink: URL(string: "https://media.ccc.de/v/mch2022-110--may-contain-hackers-2022-closing")!,
url: URL(string: "https://api.media.ccc.de/public/events/cf4dc17c-aab4-5868-9b57-100a55a1c2fb")!,
thumbURL: URL(
string:
"https://static.media.ccc.de/media/events/MCH2022/110-cf4dc17c-aab4-5868-9b57-100a55a1c2fb.jpg"
)!,
posterURL: URL(
string:
"https://static.media.ccc.de/media/events/MCH2022/110-cf4dc17c-aab4-5868-9b57-100a55a1c2fb_preview.jpg"
)!,
timelineURL: URL(
string:
"https://static.media.ccc.de/media/events/MCH2022/110-cf4dc17c-aab4-5868-9b57-100a55a1c2fb.timeline.jpg"
)!,
thumbnailsURL: URL(
string:
"https://static.media.ccc.de/media/events/MCH2022/110-cf4dc17c-aab4-5868-9b57-100a55a1c2fb.thumbnails.vtt"
)!,
frontendLink: URL(
string: "https://media.ccc.de/v/mch2022-110--may-contain-hackers-2022-closing")!,
url: URL(
string: "https://api.media.ccc.de/public/events/cf4dc17c-aab4-5868-9b57-100a55a1c2fb")!,
related: []
)
}

public extension Recording {
static let example = Recording(
extension Recording {
public static let example = Recording(
size: 461,
length: 1066,
mimeType: "video/mp4",
Expand All @@ -77,14 +92,18 @@ public extension Recording {
width: 1920,
height: 1080,
updatedAt: try! Date("2022-07-26T17:41:57Z", strategy: .iso8601),
recordingURL: URL(string: "https://cdn.media.ccc.de/events/MCH2022/h264-hd/mch2022-110-eng-May_Contain_Hackers_2022_Closing_hd.mp4")!, url: URL(string: "https://api.media.ccc.de/public/recordings/60586")!,
eventURL: URL(string: "https://api.media.ccc.de/public/events/cf4dc17c-aab4-5868-9b57-100a55a1c2fb")!,
recordingURL: URL(
string:
"https://cdn.media.ccc.de/events/MCH2022/h264-hd/mch2022-110-eng-May_Contain_Hackers_2022_Closing_hd.mp4"
)!, url: URL(string: "https://api.media.ccc.de/public/recordings/60586")!,
eventURL: URL(
string: "https://api.media.ccc.de/public/events/cf4dc17c-aab4-5868-9b57-100a55a1c2fb")!,
conferenceURL: URL(string: "https://api.media.ccc.de/public/conferences/MCH2022")!
)
}

public extension Array where Element == RelatedTalk {
static let example: [RelatedTalk] = [
extension Array where Element == RelatedTalk {
public static let example: [RelatedTalk] = [
RelatedTalk(
eventID: 2291,
eventGUID: "2f68e356-6c3f-4034-9640-c06d717ed96b",
Expand Down Expand Up @@ -113,8 +132,8 @@ public extension Array where Element == RelatedTalk {
]
}

public extension Array where Element == Recording {
static let example: [Recording] = [
extension Array where Element == Recording {
public static let example: [Recording] = [
Recording(
size: 16,
length: 1066,
Expand All @@ -127,9 +146,14 @@ public extension Array where Element == Recording {
width: 0,
height: 0,
updatedAt: try! Date("2022-07-26T23:32:01Z", strategy: .iso8601),
recordingURL: URL(string: "https://cdn.media.ccc.de/events/MCH2022/mp3/mch2022-110-eng-May_Contain_Hackers_2022_Closing_mp3.mp3")!,
recordingURL: URL(
string:
"https://cdn.media.ccc.de/events/MCH2022/mp3/mch2022-110-eng-May_Contain_Hackers_2022_Closing_mp3.mp3"
)!,
url: URL(string: "https://api.media.ccc.de/public/recordings/60723")!,
eventURL: URL(string: "https://api.media.ccc.de/public/events/cf4dc17c-aab4-5868-9b57-100a55a1c2fb")!,
eventURL: URL(
string:
"https://api.media.ccc.de/public/events/cf4dc17c-aab4-5868-9b57-100a55a1c2fb")!,
conferenceURL: URL(string: "https://api.media.ccc.de/public/conferences/MCH2022")!
),
Recording(
Expand All @@ -144,9 +168,14 @@ public extension Array where Element == Recording {
width: 720,
height: 576,
updatedAt: try! Date("2022-07-26T23:30:43Z", strategy: .iso8601),
recordingURL: URL(string: "https://cdn.media.ccc.de/events/MCH2022/h264-sd/mch2022-110-eng-May_Contain_Hackers_2022_Closing_sd.mp4")!,
recordingURL: URL(
string:
"https://cdn.media.ccc.de/events/MCH2022/h264-sd/mch2022-110-eng-May_Contain_Hackers_2022_Closing_sd.mp4"
)!,
url: URL(string: "https://api.media.ccc.de/public/recordings/60722")!,
eventURL: URL(string: "https://api.media.ccc.de/public/events/cf4dc17c-aab4-5868-9b57-100a55a1c2fb")!,
eventURL: URL(
string:
"https://api.media.ccc.de/public/events/cf4dc17c-aab4-5868-9b57-100a55a1c2fb")!,
conferenceURL: URL(string: "https://api.media.ccc.de/public/conferences/MCH2022")!
),
Recording(
Expand All @@ -161,9 +190,14 @@ public extension Array where Element == Recording {
width: 1920,
height: 1080,
updatedAt: try! Date("2022-07-26T17:41:57Z", strategy: .iso8601),
recordingURL: URL(string: "https://cdn.media.ccc.de/events/MCH2022/h264-hd/mch2022-110-eng-May_Contain_Hackers_2022_Closing_hd.mp4")!,
recordingURL: URL(
string:
"https://cdn.media.ccc.de/events/MCH2022/h264-hd/mch2022-110-eng-May_Contain_Hackers_2022_Closing_hd.mp4"
)!,
url: URL(string: "https://api.media.ccc.de/public/recordings/60586")!,
eventURL: URL(string: "https://api.media.ccc.de/public/events/cf4dc17c-aab4-5868-9b57-100a55a1c2fb")!,
eventURL: URL(
string:
"https://api.media.ccc.de/public/events/cf4dc17c-aab4-5868-9b57-100a55a1c2fb")!,
conferenceURL: URL(string: "https://api.media.ccc.de/public/conferences/MCH2022")!
),
]
Expand Down
6 changes: 5 additions & 1 deletion CCCApi/Sources/CCCApi/Models/Recording.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ public struct Recording: Decodable, Identifiable, Equatable, Sendable {
mimeType.starts(with: "video")
}

init(size: Int?, length: TimeInterval?, mimeType: String, language: String, filename: String, state: String, folder: String, isHighQuality: Bool, width: Int?, height: Int?, updatedAt: Date, recordingURL: URL, url: URL, eventURL: URL, conferenceURL: URL) {
init(
size: Int?, length: TimeInterval?, mimeType: String, language: String, filename: String,
state: String, folder: String, isHighQuality: Bool, width: Int?, height: Int?,
updatedAt: Date, recordingURL: URL, url: URL, eventURL: URL, conferenceURL: URL
) {
self.size = size
self.length = length
self.mimeType = mimeType
Expand Down
12 changes: 10 additions & 2 deletions CCCApi/Sources/CCCApi/Models/Talk.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,14 @@ public struct Talk: Decodable, Identifiable, Equatable, Sendable {
public let url: URL
public let related: [RelatedTalk]

init(guid: String, title: String, subtitle: String?, slug: String, link: URL?, description: String?, originalLanguage: String?, persons: [String], tags: [String], viewCount: Int, isPromoted: Bool, date: Date?, releaseDate: Date, updatedAt: Date, length: TimeInterval, duration: TimeInterval, conferenceTitle: String, conferenceURL: URL, thumbURL: URL?, posterURL: URL, timelineURL: URL, thumbnailsURL: URL, frontendLink: URL, url: URL, related: [RelatedTalk]) {
init(
guid: String, title: String, subtitle: String?, slug: String, link: URL?,
description: String?, originalLanguage: String?, persons: [String], tags: [String],
viewCount: Int, isPromoted: Bool, date: Date?, releaseDate: Date, updatedAt: Date,
length: TimeInterval, duration: TimeInterval, conferenceTitle: String, conferenceURL: URL,
thumbURL: URL?, posterURL: URL, timelineURL: URL, thumbnailsURL: URL, frontendLink: URL,
url: URL, related: [RelatedTalk]
) {
self.guid = guid
self.title = title
self.subtitle = subtitle
Expand Down Expand Up @@ -139,7 +146,8 @@ struct TalkExtended: Decodable {
return []
}

return recordings
return
recordings
.filter { $0.mimeType == "video/mp4" }
}
}
Expand Down
4 changes: 3 additions & 1 deletion CCCTube/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ struct ContentView: View {
case let .playTalk(id):
let talk = try await api.talk(id: id)
let recordings = try await api.recordings(for: talk)
let recording = recordings.first(where: { $0.isHighQuality }) ?? recordings.first(where: { $0.isVideo })
let recording =
recordings.first(where: { $0.isHighQuality })
?? recordings.first(where: { $0.isVideo })
self.talk = TalkToPlay(talk: talk, recordingToPlay: recording)
}
} catch {
Expand Down
9 changes: 7 additions & 2 deletions CCCTube/Extensions/Alert+Error.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import SwiftUI

extension View {
/// Presents an alert when an error is present.
func alert<E: Error>(_ titleKey: LocalizedStringKey, error: Binding<E?>, buttonTitleKey: LocalizedStringKey = "Ok") -> some View {
func alert<E: Error>(
_ titleKey: LocalizedStringKey, error: Binding<E?>,
buttonTitleKey: LocalizedStringKey = "Ok"
) -> some View {
modifier(ErrorAlert(error: error, titleKey: titleKey, buttonTitleKey: buttonTitleKey))
}
}
Expand Down Expand Up @@ -42,5 +45,7 @@ private struct ErrorAlert<E: Error>: ViewModifier {

#Preview("Error alert") {
Text(verbatim: "Preview text")
.alert("Preview error title", error: .constant(CCCTubeError(message: "Failed to load all the things")))
.alert(
"Preview error title",
error: .constant(CCCTubeError(message: "Failed to load all the things")))
}
16 changes: 8 additions & 8 deletions CCCTube/Features/Browse/BrowseView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,20 @@ struct BrowseView: View {
NavigationStack {
ScrollView {
#if os(tvOS)
if query == .popular {
YearPicker(year: $year)
}
if query == .popular {
YearPicker(year: $year)
}
#endif

TalksGrid(talks: talks)
}
.toolbar {
#if !os(tvOS)
if query == .popular {
ToolbarItem(placement: .topBarTrailing) {
YearPicker(year: $year)
if query == .popular {
ToolbarItem(placement: .topBarTrailing) {
YearPicker(year: $year)
}
}
}
#endif
}
.overlay {
Expand All @@ -57,7 +57,7 @@ struct BrowseView: View {
}
}
#if !os(tvOS)
.navigationTitle(query.localizedTitle)
.navigationTitle(query.localizedTitle)
#endif
.task(id: year) {
await refresh()
Expand Down
2 changes: 1 addition & 1 deletion CCCTube/Features/Conferences/ConferenceCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// Created by Mathijs Bernson on 26/01/2025.
//

import SwiftUI
import CCCApi
import SwiftUI

struct ConferenceCell: View {
let conference: Conference
Expand Down
Loading

0 comments on commit 4916528

Please sign in to comment.