• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Overriding custom KVC methods in Swift?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Overriding custom KVC methods in Swift?


  • Subject: Overriding custom KVC methods in Swift?
  • From: Daryle Walker <email@hidden>
  • Date: Sat, 04 Jun 2016 10:10:55 -0400

I just looked through the Key-Value Coding Programming Guide, and I’m wondering what the prototypes are of the name-customized methods for your properties in Swift.  Since the KVC protocol is informal, getting the names and/or types wrong doesn’t mean an error, but that your implementation is ignored and default handling is done.

For instance:

//=====
   func validateBody(ioValue: AutoreleasingUnsafeMutablePointer<AnyObject?>) throws {
       guard let newBody = ioValue.memory as? NSString else {
           throw NSCocoaError.KeyValueValidationError
       }

       let errors = self.dynamicType.problemsValidatingBody(newBody as String)
       if !errors.isEmpty {
           throw errors.first!
       }
       // Else: do nothing
   }
//=====

is this the correct signature to KVC-validate a property named “body” in Swift?

(Incidentally, is that a good implementation?)

—
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT com

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


  • Follow-Ups:
    • Re: Overriding custom KVC methods in Swift?
      • From: Quincey Morris <email@hidden>
  • Prev by Date: NSFileWrapper
  • Next by Date: Re: NSFileWrapper
  • Previous by thread: Re: NSFileWrapper
  • Next by thread: Re: Overriding custom KVC methods in Swift?
  • Index(es):
    • Date
    • Thread