Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Declare a read-only @NSManaged property in Swift for Parse's PFRelation

I'm using Parse object store in my iOS application and I've created a custom subclass for my Parse object, which looks somewhat like this:

class MyThing: PFObject, PFSubclassing {

   // ...PFSubclassing protocol...

   @NSManaged var name: String
   @NSManaged var somethingElse: String
   @NSManaged var relatedThings: PFRelation

 }

The relatedThings property works: I am able to fetch the related objects from the store. However, I keep getting this warning from Parse:

[Warning]: PFRelation properties are always readonly,
but MyApp.MyThing.relatedThings was declared otherwise.

In Objective-C, I could have easily marked that property as readonly, but I am unsure how to do that in Swift to silence the warning.

Using let instead of var is not allowed in combination with @NSManaged.

Adding private(set) has no effect either:

@NSManaged private(set) var relatedThings: PFRelation

So how does Parse expect me to declare the relationship property?

like image 406
Arnold Avatar asked Aug 17 '15 00:08

Arnold


1 Answers

Now you should use:

var relatedThings: PFRelation! {
    return relationForKey("relatedThings")
}
like image 96
iGenio Avatar answered Sep 28 '22 06:09

iGenio