Screenshot | Video Demo |
---|---|
1️⃣. Two-Way Data Binding in a View-Model Architecture
In MVVM (Model-View-ViewModel) architecture, didSet
can be used to update the view when the model changes, establishing a simple form of two-way data binding.
class ViewModel {
var username: 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
func invertedCombobulatoryFactory(of value: Int) -> Int { | |
// Example transformation: return the negative of the value | |
return -value | |
} | |
func discombobulate(_ values: [Int]) throws -> Int { | |
guard let first = values.first else { | |
throw DiscombobulationError.arrayWasEmpty | |
} | |
guard first >= 0 else { |
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 | |
import SwiftUI | |
class PreviewStoryboardVC: UIViewController { | |
@IBOutlet weak var showResult: UILabel! | |
override func viewDidLoad() { | |
super.viewDidLoad() |
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
enum RowType: String, CaseIterable { | |
case Profile | |
case Info | |
case Rewards | |
} | |
// big array model to store all detail | |
struct DetailInfoModel <T> { | |
var headerTitle : String? | |
var value : T? |
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 Combine | |
class ViewModel { | |
@Published var passedString: String = "" | |
} | |
class FirstViewController: UIViewController { | |
var viewModel = ViewModel() | |