Resolved Checking may UItextFields if they are empty

Discussion in 'iOS Programming' started by erdinc27, Dec 23, 2016.

  1. erdinc27 macrumors regular

    Joined:
    Jul 20, 2011
    #1
    hi all. Lets say i have a register form and it has around 15 UITextfields and all of them has to be filled. How i can check if they are empty or not ? I checked like
    Code:
    if (definition.length > 0) {
                if (city.length > 0) {
                    if (district.length > 0) {
                        if (address.length > 0) { 
                        }else {
                        }
    } else {
    }else {
    }
    }else {
    }
    }
    IS there any easier way to do that ?
     
  2. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #2
    You can make an array of the textfields and iterate over the array checking the length. That would give you a true/false value of whether all of the textfields have contents.
     
  3. 1458279 Suspended

    1458279

    Joined:
    May 1, 2010
    Location:
    California
    #3
    +1 on the array, you can also do a table, but array is quick and easy.
    One thing I was going to suggest is that you double check the meaning of 'empty' as I ran into an issue using the length vs isEmpty() or .field == '' or whatever else is an option. You might get different answers and this thru me off a few years ago. I don't remember the details, but you should double check how empty is defined by each method.
     
  4. erdinc27 thread starter macrumors regular

    Joined:
    Jul 20, 2011
    #4
    This suggestion worked perfectly. Thank you man.
     

Share This Page