Giter Site home page Giter Site logo

kvcvalidationexample's Introduction

Demonstrates a simple use of Key Value Coding Validation. The example is a simple application displaying a text field. Any text field value other than "John" will not pass validation and will display an error. This shows how to use Key-Value Coding validation properly to perform validation before setting a model object value.

You should not perform validation inside an overriden setter. Instead, you should do so in the code that calls the setter, such as an action method.

Don't do this:

- (void) setName:(NSString *)value {
    if ([self validateValue:&value forKey:@"name" error:nil]){
        name = value;
    } else {
    }
}

See ViewController for an example of a correct implementation for a UITextField.

While you should implement validation methods that follow the pattern of validate<Key>:error:, you should not call those methods directly. Instead call validateValue:forKey:error:, which will find and use those methods. Obviously in your implementation of validate<Key>:error: you should not call into validateValue:forKey:error:, which would cause an infinite loop.

This example does not cover how to modify a value inside a validation method. That will be covered in another project, as that has some additional complications.

While this example is not specific to CoreData, all of these rules apply to validation intended to be used with CoreData. Effective use of validation methods with Core Data will be part of another example project. You can, and should, follow this example when implementing a user interface that modifies a Core Data managed object even if you do not implement your own validation methods - CoreData provides implementations of validation methods at runtime that work with this example.

kvcvalidationexample's People

Contributors

quellish avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.