This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1 | |
struct GenericList<Element, RowContent: View>: View where Element: Identifiable { | |
// 2 | |
private let items: [Element] | |
private let rowContent: (Element) -> RowContent | |
// 3 | |
public init(_ items: [Element], @ViewBuilder rowContent: @escaping (Element) -> RowContent) { | |
self.items = items |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension PHAsset { | |
// MARK: This returns an array of alternate assets from a PHAsset | |
func getAlternatePhotos() -> [PHAsset] { | |
/// get the collection of the asset to avoid fetching all photos in the library | |
let collectionFetchResult = PHAssetCollection.fetchAssetCollectionsContaining(self, with: .moment, options: nil) | |
let options = PHFetchOptions() | |
options.sortDescriptors = [NSSortDescriptor.init(key: "creationDate", ascending: true)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MARK:- Async/await Group task | |
// 1 | |
@available(iOS 15, *) | |
func asyncGroups( | |
from categoryIdentifiers: [ItunesCategoryIdentifier]) { | |
// 2 | |
Task.init { | |
// 3 | |
var sections: [ItunesCategorySection] = [] | |
// 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum ItunesCategoryIdentifier: Int, CaseIterable { | |
// 1 | |
case apps | |
case podcasts | |
case tvShows | |
// 2 | |
var title: String { | |
switch self { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func dispatchGroups( | |
from categoryIdentifiers: [ItunesCategoryIdentifier]) { | |
// 1 | |
let dispatchGroup = DispatchGroup() | |
// 2 | |
var sections: [ItunesCategorySection] = [] | |
// 3 | |
for categoryIdentifier in categoryIdentifiers { | |
// 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1 | |
final class ItunesRemote: ObservableObject { | |
// 2 | |
struct ItunesCategorySection: IdentifiableHashable { | |
let sectionID: ItunesCategoryIdentifier | |
let cellIDs: [FeedItemViewModel] | |
var id: ItunesCategoryIdentifier { sectionID } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum APIError: Error { | |
case requestFailed(description: String) | |
case jsonConversionFailure(description: String) | |
case invalidData | |
case responseUnsuccessful(description: String) | |
case jsonParsingFailure | |
case noInternet | |
case failedSerialization |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
import CompositionalList | |
struct FeedView: View { | |
@ObservedObject private var remote = ItunesRemote() | |
@State var selectedItem: FeedItemViewModel? | |
var body: some View { | |
NavigationView { |
NewerOlder