Home > OS >  Swift SwiftUI iOS - using a file for functions
Swift SwiftUI iOS - using a file for functions

Time:06-21

I'm new to Swift/SwiftUI

I created a file called Functions:

import SwiftUI


class Functions {
    
    func cerateViewRouter(whatFirst: String) -> ViewRouter {
        let vrRegister = ViewRouter()
        
        if(whatFirst == "register"){
            vrRegister.currentPage = .register
        }
        
        if(whatFirst == "login"){
            vrRegister.currentPage = .login
        }
        
        return vrRegister
    }
}

and tried to use it:

var vrRegister = Functions.createViewRouter(whatFirst: "register")

I tried around with the syntax and in no way does it work. How to do this?

CodePudding user response:

That declares a function as instant member, but you try to use it as class member. If you want to use it that way make a function static, like

class Functions {
    
    static func cerateViewRouter(whatFrist: String) -> ViewRouter {
...
  • Related