29

I've been attempting to work with version 0.20.3 of the Restkit library. Recently an error has occurred that I cannot figure out how to solve. It is the following:

Property 'managedObjectStore' not found on object of type 'RKObjectManager *'

It happens at the line containing

objectManager.managedObjectStore = managedObjectStore;

A small block of my code is listed below to help with identification. I used CocoaPods to install all the necessary libraries and everything seems to link properly.

#import "AppDelegate.h"
#import <RestKit/RestKit.h>
#import <RestKit/CoreData.h>
#import <CoreData/CoreData.h>
#import <RestKit/ObjectMapping.h>
#import "Temperature.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:    (NSDictionary *)launchOptions
{

    //let AFNetworking manage the activity indicator
    [AFNetworkActivityIndicatorManager sharedManager].enabled = YES;

    // Override point for customization after application launch.
    RKObjectManager *objectManager = [RKObjectManager managerWithBaseURL:[NSURL URLWithString:@"http://grid.no-ip.biz/grid"]];
    NSURL *modelURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Grideye" ofType:@"momd"]];

    //Initialize managed object store
    NSManagedObjectModel *managedObjectModel = [[[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL ] mutableCopy];
    RKManagedObjectStore *managedObjectStore = [[RKManagedObjectStore alloc] initWithManagedObjectModel:managedObjectModel];

    objectManager.managedObjectStore = managedObjectStore;

   // Setup our object mappings
   /**
   Mapping by entity. Here we are configuring a maping by targetting a Core Data entity with a specific
   name. This allows us to map back Sensor database objects directly onto NSManagedObject instances
   there is no backing model class
   */
   RKEntityMapping *sensorMapping = [RKEntityMapping mappingForEntityForName:@"SensorID" inManagedObjectStore:managedObjectStore];
   sensorMapping.identificationAttributes = @[ @"sensorID"];
   [sensorMapping addAttributeMappingsFromDictionary:@{
        @"sensorID" : @"sensorID",
        @"cellNum"  : @"cellNum",
        @"timeStamp": @"timeStamp",
        @"temp"     : @"temp"
        }];

   //Update date format so that we can parse Sensor dates properly
   [RKObjectMapping addDefaultDateFormatterForString:@"E MMM d HH:mm:ss Z y" inTimeZone:nil];

   // Register our mappings with the provider
   RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:sensorMapping method:RKRequestMethodGET pathPattern:@":grid" keyPath:nil statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];

Thanks for whatever input you can provide!

Wain
  • 118,658
  • 15
  • 128
  • 151
Cale Spratt
  • 291
  • 3
  • 4
  • Did you upgrade from 0.1x to 0.20.3? Any other compilation errors / warnings? – Wain Sep 16 '13 at 12:41
  • Please mark answers that answered the question as "Accepted". This not only helps the person that took time to post an answer, but helps the SO community. – LJ Wilson Jul 16 '15 at 13:02

6 Answers6

73

I had exactly the same issue when upgrading from 0.20.1 to 0.20.3.

What you need to do is to import CoreData before importing RestKit.

#import <CoreData/CoreData.h>
#import <RestKit/RestKit.h>

is working.

but

#import <RestKit/RestKit.h>
#import <CoreData/CoreData.h>

is not working.

Tomusm
  • 2,208
  • 19
  • 20
26

Add in build settings User Header Search Paths "${PROJECT_DIR}/Pods" recursive. This solved the problem in my case.

Di B.
  • 1,009
  • 10
  • 11
4

In XCode6 on creating new project "pch" file isn't created by default, I had to create pch file manually following PCH File in Xcode 6

I got it working After importing headers in pch file:

#import <CoreData/CoreData.h>
#import <RestKit/RestKit.h>
Community
  • 1
  • 1
Aqib Mumtaz
  • 4,936
  • 1
  • 36
  • 33
3

Add

#import <CoreData/CoreData.h>  

to your .pch file.

George
  • 125
  • 2
  • 8
2

The root cause of this issue is in RKObjectManager.h

#ifdef _COREDATADEFINES_H
#   if __has_include("RKCoreData.h")
#       define RKCoreDataIncluded
#   endif
#endif

This include has changed names so everywhere RKCoreData.h appears change to RestKit/CoreData.h there are several include files that use this construct so do a global search.

Jim Holland
  • 1,180
  • 12
  • 19
0

If you are upgrading from 0.20 to 0.26 (say, upgrading a very old project that hadn't been updated for years), you may find that both of the following, suggested in other answers, are insufficient:

  • add #import <CoreData/CoreData.h> in pch
  • add #import <CoreData/CoreData.h> before #import <RestKit/RestKit.h>

Instead, at the top of the relevant file where you are importing restkit,

// Workaround for bug on RestKit 0.26.0 according to https://github.com/RestKit/RestKit/issues/2352
#ifndef RKCoreDataIncluded 
#define RKCoreDataIncluded 
#endif
auspicious99
  • 3,902
  • 1
  • 44
  • 58