Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Swift SwiftUI iOS – using a file for functions

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

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

>Solution :

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 {
...
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading