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
/// Creates an AWS AppSync-compatible RequestBody `payload` for subscriptions. | |
/// This is necessary due to the different payload used by Apollo | |
/// Credit to: | |
/// - https://community.apollographql.com/t/using-apollo-with-appsync-directly-on-ios/324/4 | |
/// - https://docs.aws.amazon.com/appsync/latest/devguide/real-time-websocket-client.html#header-parameter-format-based-on-appsync-api-authorization-mode | |
/// - https://github.com/lingfengmarskey/NetworkSample | |
/// | |
/// AppSync payload: | |
/// { | |
/// "id": "subscriptionId", |
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 UIKit | |
/// A type eraser to erase the concrete types of your encodable objects | |
struct AnyEncodable: Encodable { | |
private let encodeClosure: (Encoder) throws -> Void | |
init<T: Encodable>(_ value: T) { | |
encodeClosure = { encoder in | |
try value.encode(to: encoder) | |
} |
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 PlaygroundSupport | |
struct ContentView: View { | |
@State private var sliderValue: CGFloat = 0 | |
private var minSliderValue: CGFloat = 10 | |
private var maxSliderValue: CGFloat = 100 | |
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 testNotifications() { | |
// map all authorizationStatus with expected Result | |
let authorizationStatusMap: [UNAuthorizationStatus: Int] = [.authorized: 1, .denied: 0, .notDetermined: 0, .provisional: 1] | |
UNNotificationSettings.swizzleAuthorizationStatus() | |
authorizationStatusMap.forEach { (key: UNAuthorizationStatus, value: Int) in | |
UNNotificationSettings.fakeAuthorizationStatus = key | |
let mockCenter = UserNotificationCenterMock() | |
let mockCoder = MockNSCoder() |
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 Foundation | |
import Combine | |
extension Publisher{ | |
func isPrimeInteger<T: BinaryInteger>() -> Publishers | |
.CompactMap<Self, T> where Output == T { | |
compactMap{self.isPrime($0)} | |
} | |
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 Foundation | |
import Combine | |
struct Post: Codable{ | |
let userId: Int | |
let id: Int | |
let title: String | |
let body: String | |
} |
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 Foundation | |
| |
public class Throttler { | |
private var workItem = DispatchWorkItem(block: {}) | |
private var previousRun = Date.distantPast | |
private let queue: DispatchQueue | |
private let minimumDelay: TimeInterval | |
| |
public init(minimumDelay: TimeInterval, queue: DispatchQueue = DispatchQueue.main) { |
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
let date1 = Date() | |
let date2 = date1.addingTimeInterval(12000) | |
// Use the date components .year .month .day .hour | |
let diffComponents = Calendar.current.dateComponents([.hour, .minute], from: date1, to: date2) | |
let hours = diffComponents.hour | |
let minutes = diffComponents.minute | |
print("Hours \(hours) Minutes \(minutes)") |
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 Foundation | |
protocol LocalizedView { | |
/// Localized type | |
var localizer: Localizer { get } | |
} | |
extension LocalizedView where Self: UIViewController { | |
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 Foundation | |
/// A protocol to present an alert controller | |
protocol AlertPresentable where Self: UIViewController { | |
/// Present an alert controller | |
/// | |
/// - Parameters: | |
/// - title: The alert title | |
/// - message: The alert message |
NewerOlder