11
votes

I have an object class of NotSureItem in which I am adding some attribute of item. In my app I am using Realm for database but when I added the the description attributes in my app its shows me an error of overriding the stored property. And It also giving some error like this 'Getter for 'description' with Objective-C selector 'description' conflicts with getter for 'description' from superclass 'NSObject' with the same Objective-C selector'. Here its my code object class.

import Foundation
import Realm

class NotSureItem: RLMObject {
    dynamic var title = ""
    dynamic var description = ""
    dynamic var dateTime = NSDate()
}
1
Piyush is right. Plus, even if it wasn't NSObject subclass, you'd still want to avoid description property name because that would conflict with CustomStringConvertible should you ever want to add that conformance at a some future point (very useful for debugging purposes). - Rob

1 Answers

20
votes

Because it conflicts with the -description method in NSObject (recall that Core Data dynamically generates property accessors and mutators — a property named ‘description’ would require creating an accessor method called -description).

Note that a property name cannot be the same as any no-parameter method name of NSObject or NSManagedObject. For example, you cannot give a property the name "description". There are hundreds of methods on NSObject which may conflict with property names—and this list can grow without warning from frameworks or other libraries. You should avoid very general words (like "font”, and “color”) and words or phrases which overlap with Cocoa paradigms (such as “isEditing” and “objectSpecifier”).