Skip to content

Instantly share code, notes, and snippets.

View xmhafiz's full-sized avatar
🏠
Working from home

Mohd Hafiz xmhafiz

🏠
Working from home
View GitHub Profile
import Combine
import UIKit
class ViewController: UIViewController {
var viewModel = LoginViewModel()
var cancellables = Set<AnyCancellable>()
// ...
}
//
// ViewController.swift
//
import Combine
import UIKit
class ViewController: UIViewController {
var viewModel = LoginViewModel()
var cancellables = Set<AnyCancellable>()
//
// ViewController.swift
//
import UIKit
class ViewController: UIViewController {
// 1
lazy var stackView: UIStackView = {
let view = UIStackView()
//
// LoginViewModel.swift
//
import Combine
import Foundation
// 1
class LoginViewModel: ObservableObject {
// 2
@IBAction func onClickedButton(_ sender: LoaderButton) {
sender.isLoading = true
// simulate sending request
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(2)) {
sender.isLoading = false
}
}
//
// LoaderButton.swift
//
import UIKit
// 1
class LoaderButton: UIButton {
// 2
var spinner = UIActivityIndicatorView()
// 3
import Firebase
import SwiftUI
@main
struct RTDBCodableApp: App {
init() {
FirebaseApp.configure()
}
var body: some Scene {
struct GameData {
static var counter = 0
static var score = 0
static var wins = 0
static var lost = 0
}
// usage
// write
GameData.wins = 5
class ProfileViewController: UIViewController {
//...
//...
func broadcastInfo() {
let image = UIImage() // some image
let data: [String: Any] = ["title": "...some text", "subtitle": "longer text", "image": image]
// post a notification
NotificationCenter.default.post(name: Notification.Name.profileUpdated, object: nil, userInfo: data)
}
// 1
extension Notification.Name {
static let profileUpdated = Notification.Name("OnProfileUpdated")
}
class ViewController: UIViewController {
//...
//...
override func viewDidLoad() {
super.viewDidLoad()