Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7670365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:48:22+00:00 2026-05-31T15:48:22+00:00

Simple question, I’m currently using Core Data. I have a form which is responsible

  • 0

Simple question, I’m currently using Core Data. I have a form which is responsible for inserting a new item. If there is no category or name, save button should remains disabled. Currently, I’m doing this simple if statement in my controller, but is there any good practice about validation in iOS development?

Like in rails or any PHP MVC framework, any validations should be in the models, Would it be the same for Core data models?

Thank you.

EDIT

What I’ doing currently is I check with textFieldEditingChanged: if both of my textfield are not empty to enable the save button. When they are not empty and the user press Save, I create my new Core data object and then save it. What would you suggest according to your solution?

When a field is modified method

- (IBAction)textFieldEditingChanged:(UITextField *)textField
{
    saveButton.enabled = [self validatesRequiredFields];

    if (textField == descField)
    {
        itemDesc = descField.text;
    }
    else if (textField == personField)
    {
        personName = personField.text;
    }
    else if (textField == valueField)
    {
        itemValue = valueField.text;
    }
}

Validation method

- (BOOL)validatesRequiredFields
{
    if (category != nil && personField.text.length != 0)
    {
        return YES;
    }
    else
    {
        return NO;
    }
}

When the save button is pressed method

- (IBAction)saveButtonPressed
{
    item = [Item createEntity];
    item.type = itemType;
    item.desc = itemDesc;
    item.value = itemValue;
    item.imageFilename = itemImageFilename;
    item.category = category;
    item.addedDate = itemDueDate;

    Person *p = [Person personWithName:personName];

    item.person = p;

    if (dueDateField)
    {
        item.dueDate = itemDueDate;
    }

    [delegate itemAddSaveButtonPressed:item];
}

EDIT 2

What I’m now using

- (BOOL)isValid
{
    BOOL valid;
    NSError *error;

    item.type = itemType;
    item.desc = itemDesc;
    item.value = itemValue;
    item.imageFilename = itemImageFilename;
    item.category = category;
    item.addedDate = itemDueDate;

    if (dueDateField)
    {
        item.dueDate = itemDueDate;
    }

    if (personName.length > 0)
    {
        item.person = [Person personWithName:personName];   
    }
    else
    {
        item.person = nil;
    }

    if ([item validateForInsert:&error])
        valid = YES;
    else 
        valid = NO;

    return valid;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T15:48:23+00:00Added an answer on May 31, 2026 at 3:48 pm

    It’s important to distinguish between validating the managed object that will result from the form and validating the data entered into the form. Core Data will automatically validate the managed object(s) that you add to your context. Your question, though, seems to relate to validating the data entered into the form, possibly before the managed object is even created.

    As you’ve described it, the state of the “save” button depends on presence of a name in one of your fields. Clearly, the view controller needs to be involved here to some degree since model objects don’t know anything about views. One way to handle this is to just let the view controller do its own validation, as you’re doing now. That’s not so bad for simple cases, and it’s the obvious route if you’ve implemented your view controller such that the managed object isn’t created until the user taps the “save” button.

    Another way to do it is to have the view controller create a new managed object when its view is first displayed, and then copy any changes to the user interface over to the managed object. If you do it that way, you can use NSManagedObject’s -validateForInsert: and/or -validateForUpdate: methods to decide whether the data in the managed object is valid, and you can set the state of the “save” button based on the result. This approach means that any validation rules for the managed object will be checked, and changing the rules for the entity won’t require also updating the validation code in the view controller.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

simple question about intent action naming convention: I have a new service that handles
simple question mainly for simplifying purposes but... currently using var categoryList = []; $('#share').children().each(function()
Simple question, but one that I've been curious about...is there a functional difference between
Simple question that we've spent to much time on. We have a server side
simple question for you fellas. I have an image inside a Canvas, with a
Simple question. Say I have a bunch of NIL's in my list q .
Simple question - In c++, what's the neatest way of getting which of two
Simple question: do I have to delete or delete [] c ? Does the
Simple question about Jquery-UI sortable lists (http://jqueryui.com/demos/sortable/#default) I have made: <ul id=sortable> <li class=ui-state-default>An
simple question: I have input fields with inside-labels! Just like the search-box on this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.