Skip to content

Instantly share code, notes, and snippets.

View thomsmed's full-sized avatar
:octocat:
✌️😎

Thomas Asheim Smedmann thomsmed

:octocat:
✌️😎
View GitHub Profile
@thomsmed
thomsmed / ContentView.swift
Last active January 1, 2022 23:36
ContentView.swift - From "Share authentication state across your apps, App Clips and Widgets" @ medium.com
//
// ContentView.swift
//
import SwiftUI
struct ContentView: View {
@State var isAuthenticated = Dependencies.authService.hasSignedInBefore
@State var state: String = Dependencies.authService.hasSignedInBefore ? "You are signed in!" : "You are not signed in"
@thomsmed
thomsmed / SharedAppAuthStateWidget.swift
Created January 1, 2022 22:47
SharedAppAuthStateWidget.swift - From "Share authentication state across your apps, App Clips and Widgets" @ medium.com
//
// SharedAppAuthStateWidget.swift
//
import WidgetKit
import SwiftUI
import Intents
struct Provider: IntentTimelineProvider {
func placeholder(in context: Context) -> WidgetEntry {
@thomsmed
thomsmed / Dependencies.swift
Last active January 6, 2022 07:44
Dependencies.swift (main app) - From "Share authentication state across your apps, App Clips and Widgets" @ medium.com
//
// Dependencies.swift
//
import Foundation
struct Dependencies {
private static let migrationRepository: AuthStateRepository = SharedUserDefaultsAuthStateRepository(appGroupIdentifier: "group.com.mydomain.shared")
private static let authStateRepository: AuthStateRepository = KeychainAuthStateRepository(accessGroup: "<teamId>.com.mydomain.shared",
serviceName: "com.mydomain.myapp",
@thomsmed
thomsmed / Dependencies.swift
Last active January 6, 2022 06:25
Dependencies.swift (App Clip) - From "Share authentication state across your apps, App Clips and Widgets" @ medium.com
//
// Dependencies.swift
//
import Foundation
struct Dependencies {
private static let authStateRepository: AuthStateRepository = SharedUserDefaultsAuthStateRepository(appGroupIdentifier: "group.com.mydomain.shared")
private static let auth0AuthService = Auth0AuthService(configuration: Auth0Configuration(openIdDomain: "<openIdDomain>",
openIdClientId: "<openIdClientId>",
@thomsmed
thomsmed / Dependencies.swift
Last active January 6, 2022 06:24
Dependencies.swift (Widget) - From "Share authentication state across your apps, App Clips and Widgets" @ medium.com
//
// Dependencies.swift
//
import Foundation
struct Dependencies {
private static let authStateRepository: AuthStateRepository = KeychainAuthStateRepository(accessGroup: "<teamId>.com.mydomain.shared",
serviceName: "com.mydomain.myapp",
accountName: "My App",
@thomsmed
thomsmed / Dependencies.swift
Created January 6, 2022 07:45
Dependencies.swift (secondary app) - From "Share authentication state across your apps, App Clips and Widgets" @ medium.com
//
// Dependencies.swift
//
import Foundation
struct Dependencies {
private static let authStateRepository: AuthStateRepository = KeychainAuthStateRepository(accessGroup: "<teamId>.com.mydomain.shared",
serviceName: "com.mydomain.myapp",
accountName: "My App")
@thomsmed
thomsmed / UIScrollView+scrollToTop.swift
Created February 8, 2022 14:51
UIScrollView+scrollToTop.swift
//
// UIScrollView+scrollToTop.swift
//
import Foundation
import UIKit
extension UIScrollView {
func scrollToTop(_ completion: (() -> Void)? = nil) {
guard contentOffset.y != -adjustedContentInset.top else {
@thomsmed
thomsmed / SinglePageController.swift
Last active May 14, 2022 10:48
SinglePageController.swift - From "Swap root view controllers using a custom container view controller" @ medium.com
//
// SinglePageController.swift
//
import UIKit
import Cartography
class SinglePageController: UIViewController {
private func removeChildViewControllers() {
@thomsmed
thomsmed / SceneFlowController.swift
Last active May 14, 2022 10:52
SceneFlowController.swift - From "Swap root view controllers using a custom container view controller" @ medium.com
//
// SceneFlowController.swift
//
import UIKit
protocol SceneFlowController: AnyObject {
func signedOut()
func signedIn()
func completedOnboarding()
@thomsmed
thomsmed / ChatHostScanner.swift
Created April 13, 2022 22:22
ChatHostScanner.swift - From "Core Bluetooth by example - Part four: The Central" @ medium.com
//
// ChatHostScanner.swift
//
import Foundation
import Combine
struct DiscoveredChatHost {
let name: String?
let uuid: UUID