⚠️ Note 2023-01-21
Some things have changed since I originally wrote this in 2016. I have updated a few minor details, and the advice is still broadly the same, but there are some new Cloudflare features you can (and should) take advantage of. In particular, pay attention to Trevor Stevens' comment here from 22 January 2022, and Matt Stenson's useful caching advice. In addition, Backblaze, with whom Cloudflare are a Bandwidth Alliance partner, have published their own guide detailing how to use Cloudflare's Web Workers to cache content from B2 private buckets. That is worth reading,
This file contains hidden or 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
/// An iOS style TabView that doesn't reset it's childrens navigation stacks when tabs are switched. | |
public struct UIKitTabView: View { | |
private var viewControllers: [UIHostingController<AnyView>] | |
private var selectedIndex: Binding<Int>? | |
@State private var fallbackSelectedIndex: Int = 0 | |
public init(selectedIndex: Binding<Int>? = nil, @TabBuilder _ views: () -> [Tab]) { | |
self.viewControllers = views().map { | |
let host = UIHostingController(rootView: $0.view) | |
host.tabBarItem = $0.barItem |
This file contains hidden or 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
// APIService.swift | |
// MovieSwift | |
// | |
// Created by Thomas Ricouard on 06/06/2019. | |
// Copyright © 2019 Thomas Ricouard. All rights reserved. | |
// | |
import Foundation | |
struct APIService { | |
let baseURL = URL(string: "https://api.themoviedb.org/3")! |
This file contains hidden or 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 Combine | |
import Foundation | |
enum APIError: Error { | |
case invalidBody | |
case invalidEndpoint | |
case invalidURL | |
case emptyData | |
case invalidJSON | |
case invalidResponse |
This file contains hidden or 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 Foundation | |
// OAuth2Token structure | |
struct OAuth2Token: Codable { | |
let date = Date() // date when the token was initialized | |
var accessToken: String // access token | |
var refreshToken: String? // refresh token (optional) | |
var expiresIn: Int // seconds until token expires | |
var tokenType: String // for example "Bearer" |
https://github.com/n0shake/Public-APIs
This is an attempt to categorise different APIs scoured from the web which make their resources available for consumption.
*Items marked with
are open-source *Items marked with 💸 are trial based APIs
This file contains hidden or 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 Combine | |
struct ZipMany<Element, Failure>: Publisher where Failure: Error { | |
typealias Output = [Element] | |
private let underlying: AnyPublisher<Output, Failure> | |
init<T: Publisher>(publishers: [T]) where T.Output == Element, T.Failure == Failure { | |
let zipped: AnyPublisher<[T.Output], T.Failure>? = publishers.reduce(nil) { result, publisher in | |
if let result = result { |
This file contains hidden or 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 Combine | |
struct AdaptsToSoftwareKeyboard: ViewModifier { | |
@State var currentHeight: CGFloat = 0 | |
func body(content: Content) -> some View { | |
content | |
.padding(.bottom, currentHeight) | |
.edgesIgnoringSafeArea(.bottom) |
This file contains hidden or 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 Foundation | |
import Combine | |
enum APIError: Error, LocalizedError { | |
case unknown, apiError(reason: String), parserError(reason: String) | |
var errorDescription: String? { | |
switch self { | |
case .unknown: | |
return "Unknown error" |
This file contains hidden or 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 Combine | |
import MapKit | |
class CityFinder: NSObject, BindableObject { | |
var didChange = PassthroughSubject<CityFinder, Never>() | |
var results: [String] = [] { | |
didSet { |