Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot override with a stored property 'description'

Tags:

ios

swift

realm

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()
}
like image 423
shahin ali agharia Avatar asked Oct 27 '15 07:10

shahin ali agharia


People also ask

Can we override stored property in Swift?

You can provide a custom getter (and setter, if appropriate) to override any inherited property, regardless of whether the inherited property is implemented as a stored or computed property at source.

How do you override property in Swift?

We use the override keyword to declare method overriding. For example, class Vehicle { func displayInfo(){ ... } } class Car: Vehicle { // override method override func displayInfo() { ... } }

What is a computed property in Swift?

Computed Properties. In addition to stored properties, classes, structures, and enumerations can define computed properties, which don't actually store a value. Instead, they provide a getter and an optional setter to retrieve and set other properties and values indirectly.


1 Answers

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”).

like image 104
Piyush Sharma Avatar answered Sep 17 '22 13:09

Piyush Sharma