Nonsense
After the previous article was published, some garden friends said that after the first article was published, cucumber dishes were all cool. I think it was indeed, and there were indeed a large number of articles in 100, at present, writing things is also a small summary in my spare time. I have to work during the day, and I am working on a web system at night. Recently, the World Cup has been a little time-consuming. Therefore, this series is about sharing experiences with mobile development.
Let's get started with today's demo.
Login form
What we simulate today is a small prototype in our real project, login form.
First, create a single view IOS project and select swift and iPhone.
Click main. storyboard and select use auto layout.
Drag the label and text field on the storyboard as in the previous section.
Then, establish a code connection between the display control and the behavior control.
We create two arrays to store the username and password simulated data in the DB.
var users: NSMutableArray = [ "user1", "user2", "user3" ]var passwords: NSMutableArray = [ "pass1", "pass2", "pass3" ]
Write the following code in the ibaction of the button:
var check = users.containsObject(user.text)if check{ var index = users.indexOfObject(user.text) var passQuery = passwords.objectAtIndex(index) if passQuery as NSString == pass.text { label.text = "Successful Login!" } else { label.text = "Wrong Password" }} else { label.text = "No such user!"}
It can be seen from the function and parameter names that the user name is verified and the Password Logon is valid. In actual scenarios, data should be in the database.
User-friendly prompt for different behavior results.
Final code forming:
Then we run the demo:
Today's demo is complete. I will try to find something more to share with you next time.