Friday, December 2, 2022
HomeiOS Developmentios - Swift Enum Values With Generics

ios – Swift Enum Values With Generics


I needed to make a guardian view mannequin that comprises some primary stuff that I would like all my view fashions to have in SwiftUI. I am making an attempt to make the guardian view mannequin have a generic variables so I can inherit ParentViewModel in any view mannequin I make with the customized kind.

That is what I’ve tried and bought a Can't discover kind 'T' in scope error on the loaded case. Not likely positive how I could make that generic, any perception right here?

class ParentViewModel: ObservableObject {
    enum Standing {
        case loading
        case loaded(T)
        case error(Error)
    }
    
    @Revealed var standing: Standing = .loading
}

class ChildViewModel: ParentViewModel {
    
    init() {
        self.standing = .loading
    }
    
    init(object: SomeObject) {
        self.standing = .loaded(object)
    }
}

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments