Women in Technology

Hear us Roar



Article:
  Adding a Preferences Window to Your Application
Subject:   Avoid insertion of empty record
Date:   2001-12-29 19:09:15
From:   michele
In order not to insert an empty record, I've inserted the following statements at the beginning of insertRecord:


// Check if the new record is not empty
if ( ([[firstNameField stringValue] isEqualToString: @""]) &&
([[lastNameField stringValue] isEqualToString: @""]) &&
([[emailField stringValue] isEqualToString: @""]) &&
([[homePhoneField stringValue] isEqualToString: @""]) &&
([[workPhoneField stringValue] isEqualToString: @""]) &&
([[mobilPhoneField stringValue] isEqualToString: @""]) )
{
return;
}

Full Threads Oldest First

Showing messages 1 through 1 of 1.

  • Avoid insertion of empty record
    2003-08-30 15:50:51  anonymous2 [View]

    Cute, but too lugubrious. Use length and the logical or || operator. Will cost less code and will execute much faster. You've got && throughout your snippet - meaning the machine HAS to go through and evaluate each one.

    Besides, your logic is upside down. You are checking for what you DON'T want to find, instead of what you DO want to find.

    Make your logid aright. THIMK a bit. ;P