Skip to content

Instantly share code, notes, and snippets.

@fitomad
Created June 19, 2019 09:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fitomad/8e3ef4413b15d1ef5757e897cee08e90 to your computer and use it in GitHub Desktop.
Save fitomad/8e3ef4413b15d1ef5757e897cee08e90 to your computer and use it in GitHub Desktop.
//
// OperatingSystemStore.swift
// CombinedUIKit
//
// Created by Adolfo Vera Blasco on 17/06/2019.
// Copyright © 2019 desappstre.com. All rights reserved.
//
import SwiftUI
import Foundation
import Combine
public class OperatingSystemStore: BindableObject
{
// MARK: - BindableObject Protocol -
///
public var didChange = PassthroughSubject<Void, Never>()
// MARK: - Tipo anidado -
// Representa un sistema operativo
public struct OperatingSystem
{
public private(set) var name: String
public private(set) var version: String
public init(named name: String, version: String)
{
self.name = name
self.version = version
}
}
/// Los sistemas operativos. De momento se cargan dos
public private(set) var systems: [OperatingSystem]
/// Empezamos con las dos últimas versiones de **macOS**
public init()
{
self.systems = [
OperatingSystem(named: "Catalina", version: "10.15"),
OperatingSystem(named: "Mojave", version: "10.14")
]
}
///
public func add(_ system: OperatingSystem) -> Void
{
// Añadimos el nuevo sistema operativo
self.systems.append(system)
// Notificamos el cambio a la vista
self.didChange.send()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment