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 / ValueOrUnknown.swift
Created December 8, 2022 12:45
ValueOrUnknown.swift - A simple wrapper enum for decoding JSON with optional or unknown/shifting values.
import Foundation
/// Simple wrapper enum for decoding JSON with optional or unknown/shifting values.
///
/// If decoding of the Value type fails, the value is decoded as a string.
///
/// ```swift
/// enum State { case idle; case running; case stopped }
/// try JSONDecoder().decode(ValueOrUnknown<State>.self, from: "waiting") // == .unknown("waiting")
/// ```
@thomsmed
thomsmed / KeychainSecureStorage+SecureStorage.swift
Last active September 26, 2022 12:02
A simple Keychain wrapper for storing arbitrary stuff.
//
// KeychainSecureStorage+SecureStorage.swift
//
import Foundation
enum SecureStorageError: Error {
case invalidKey
case invalidValue
case notFound(description: String?)
@thomsmed
thomsmed / CountriesView.swift
Created August 29, 2022 18:13
CountriesView.swift - From "Detect and utilise consecutive taps on a TabView tab" @ medium.com
//
// CountriesView.swift
//
import SwiftUI
import Combine
// MARK: Country
struct Country: Identifiable, Hashable {
@thomsmed
thomsmed / ContentOneViewModel.swift
Created August 29, 2022 17:55
ContentOneViewModel.swift - From "Detect and utilise consecutive taps on a TabView tab" @ medium.com
//
// ContentOneViewModel.swift
//
import SwiftUI
import Combine
// MARK: ContentOneViewModel
final class ContentOneViewModel: ObservableObject {
@thomsmed
thomsmed / MyTabViewModel.swift
Created August 29, 2022 17:39
MyTabViewModel.swift - From "Detect and utilise consecutive taps on a TabView tab" @ medium.com
//
// MyTabViewModel.swift
//
import Foundation
import Combine
final class MyTabViewModel: ObservableObject {
@Published var selectedTab: MyTabView.Tab = .one
@thomsmed
thomsmed / MyTabView.swift
Created August 29, 2022 17:28
MyTabView.swift - From "Detect and utilise consecutive taps on a TabView tab" @ medium.com
//
// MyTabView.swift
//
import SwiftUI
// MARK: MyTabViewModel
final class MyTabViewModel: ObservableObject {
@thomsmed
thomsmed / TableViewController.swift
Last active August 22, 2022 19:53
TableViewController.swift - From "Expandable and dynamic sized Table Header View and Table Footer View" @ medium.com
//
// TableViewController.swift
//
import UIKit
// ...
final class TableViewController: UITableViewController {
@thomsmed
thomsmed / TableViewController.swift
Last active August 22, 2022 19:52
TableViewController.swift (with animation) - From "Expandable and dynamic sized Table Header View and Table Footer View" @ medium.com
//
// TableViewController.swift
//
import UIKit
// ...
final class TableViewController: UITableViewController {
@thomsmed
thomsmed / TableViewController.swift
Last active August 22, 2022 19:51
TableViewController.swift (without animation) - From "Expandable and dynamic sized Table Header View and Table Footer View" @ medium.com
//
// TableViewController.swift
//
import UIKit
final class TableHeaderView: UIView {
// ...
@thomsmed
thomsmed / TableViewController+TableHeaderView.swift
Last active August 22, 2022 19:50
TableViewController+TableHeaderView.swift - From "Expandable and dynamic sized Table Header View and Table Footer View" @ medium.com
//
// TableViewController+TableHeaderView.swift
//
import UIKit
final class TableHeaderView: UIView {
// ...