Return of an object in Realm

0

I am having problems with an object that returns to me in Realm, the strange thing is that if I printo by console the object if it gives me a good impression but nevertheless if I try to access its value it tells me that it is empty. The structure of the object is as follows:

class Favourite : Object {
    var character : Character!
}
  • I create an object and add it to the BD

    let fav = Favourite()
    fav.character = character
    FavouriteDao.sharedInstance.addFavourite(characterFavourite: fav)
    
  • I get all favorite type objects

    func getAllFavourites () - > Results {      return realm.objects (Favorite.self)  }

  • When I get the item and I make a print

    Favourite {
    character = Character {
        name = Spider-Man;
        descriptionC = Bitten by a radioactive spider, high school student Peter Parker gained the speed, strength and powers of a spider. Adopting the name Spider-Man, Peter hoped to start a career using his new abilities. Taught that with great power comes great responsibility, Spidey has vowed to use his powers to help people.;
        thumbnail = Thumbnail {
            id = 815D93D0-C116-4267-978C-9E47C0074D0D;
            path = http://i.annihil.us/u/prod/marvel/i/mg/3/50/526548a343e4b;
            extensionImage = jpg;
        };
    };
    
  • If I try to access the character element, it tells me that it's nil

  • Someone manages to understand why if I make a print of the favorite object it shows me that there is a character inside but nevertheless if I try to access it, it tells me that it does not exist ??

    Greetings.

        
    asked by Alejandro 25.01.2017 в 16:11
    source

    1 answer

    1

    It seems to me that what is missing is the dynamic attribute to the character property. In this way:

    class Favourite : Object {
       dynamic var character : Character!
    }
    
        
    answered by 25.01.2017 / 16:25
    source