Overriding custom KVC methods in Swift?
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