How to implement the Signup screen using MVVM + Sw

2019-08-28 14:45发布

问题:

[![enter image description here][1]][1]I'm an iOS developer, I am using XIB's (Not Storyboard) and I'm guilty of having Massive View Controllers in my projects so I've been searching for a better way to structure my projects and came across the MVVM (Model-View-ViewModel) architecture. I've been reading a lot of MVVM with iOS and I tried one small task which is sign up screen. But I am getting an error in viewcontroller class. If anyone helps me, It would be great.

回答1:

You get an error because you are calling the init method incorrectly, the code should look something like

let signupscreen = SignupViewModel.init(Firstname: "", 
                                        Lastname: "", 
                                        Mailid: "", 
                                        Mobilenumber: 0, 
                                        Password: "", 
                                        Confirmpassword: "")

and please use lowercase standard for parameter names,firstname instead of Firstname and so on.

Note that after looking at the viewDidLoad code more carefully, it looks to me like the whole init method is unnecessary since you don't need the signupscreen object for anything so an alternative answer is to just delete the code and initialize your ui components directly.



标签: ios swift swift4