[Fall In Love With swift] Day 2: Login form

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.