Skip to content

Instantly share code, notes, and snippets.

View jamesrochabrun's full-sized avatar
🇵🇪

James Rochabrun jamesrochabrun

🇵🇪
View GitHub Profile
@jamesrochabrun
jamesrochabrun / TrailingTextLoader.swift
Last active September 30, 2023 05:58
An animated Trailing text
@available(iOS 16.0, macOS 13.0, tvOS 16.0, watchOS 9.0, *)
struct CenteredLoadingText: View {
private let mainText: String
private let dots = [".", ".", "."]
private let repeatInterval: TimeInterval
private let accessibilityLabel: String
private let loadingAnimation: Animation
private let spacing: CGFloat
@jamesrochabrun
jamesrochabrun / GroupTaskImplemnetation.swift
Last active January 3, 2022 23:52
Using Group tasks to synchronize networking calls.
// MARK:- Async/await Group task
// 1
@available(iOS 15, *)
func asyncGroups(
from categoryIdentifiers: [ItunesCategoryIdentifier]) {
// 2
Task.init {
// 3
var sections: [ItunesCategorySection] = []
// 4
@jamesrochabrun
jamesrochabrun / DispatchGroupImplementation.swift
Last active June 17, 2021 21:30
A sample function that uses DispatchGroup API
func dispatchGroups(
from categoryIdentifiers: [ItunesCategoryIdentifier]) {
// 1
let dispatchGroup = DispatchGroup()
// 2
var sections: [ItunesCategorySection] = []
// 3
for categoryIdentifier in categoryIdentifiers {
// 4
@jamesrochabrun
jamesrochabrun / ItunesRemote.swift
Last active June 17, 2021 18:16
Itunes Remote implementation.
// 1
final class ItunesRemote: ObservableObject {
// 2
struct ItunesCategorySection: IdentifiableHashable {
let sectionID: ItunesCategoryIdentifier
let cellIDs: [FeedItemViewModel]
var id: ItunesCategoryIdentifier { sectionID }
}
@jamesrochabrun
jamesrochabrun / ItunesCategoryIdentifier.swift
Last active January 3, 2022 23:47
Itunes category identifier model.
enum ItunesCategoryIdentifier: Int, CaseIterable {
// 1
case apps
case podcasts
case tvShows
// 2
var title: String {
switch self {
@jamesrochabrun
jamesrochabrun / AsyncGenericAPI.swift
Last active June 11, 2021 02:58
Generic API async-await based
enum APIError: Error {
case requestFailed(description: String)
case jsonConversionFailure(description: String)
case invalidData
case responseUnsuccessful(description: String)
case jsonParsingFailure
case noInternet
case failedSerialization
@jamesrochabrun
jamesrochabrun / GenericClosureBasedAPI.swift
Last active June 10, 2021 20:28
Generic closure based API
/// 1 Errors
enum APIError: Error {
case requestFailed(description: String)
case jsonConversionFailure(description: String)
case invalidData
case responseUnsuccessful(description: String)
case jsonParsingFailure
case noInternet
case failedSerialization
import SwiftUI
import CompositionalList
struct FeedView: View {
@ObservedObject private var remote = ItunesRemote()
@State var selectedItem: FeedItemViewModel?
var body: some View {
NavigationView {
// 1
final class MoviesProvider: ObservableObject {
// MARK:- Subscribers
// 2
private var cancellable: AnyCancellable?
// MARK:- Publishers
// 3
@Published var movies: [MovieViewModel] = []
@jamesrochabrun
jamesrochabrun / MovieClient.swift
Last active July 23, 2020 08:33
MovieClient fetches movies from Movies API.
final class MovieClient: CombineAPI {
// 1
let session: URLSession
// 2
init(configuration: URLSessionConfiguration) {
self.session = URLSession(configuration: configuration)
}