0

I have an app where I write to a database using core data. This is working as I can see there is data in there using the SQLLite database browser. I am then retrieving the data into an NSMutable Array and I can see there is 1 record in debug mode using:

Print self.schoolNames.count

but I can't seem to read the array. My line is:

obsSchoolName = [[self.schoolNames objectAtIndex:0] obsSavedSchoolName];

where the attribute name of the field I am trying to access is obsSavedSchoolName.

Any ideas much appreciated.

8
  • What is your problem? Does the compiler not find the method obsSavedSchoolName in any visible interface of <id>? Commented Feb 24, 2013 at 0:15
  • "No known instance of obsSavedSchoolName". If I am in debug mode and trying Print [[self.schoolNames objectAtIndex:0] obsSavedSchoolName] the error is "error: no known method '-obsSavedSchoolName'; cast the message send to the method's return type error: 1 errors parsing expression" Commented Feb 24, 2013 at 0:20
  • It does compile but it does not debug? Strange. Commented Feb 24, 2013 at 0:22
  • obsSavedSchoolName is a method of some class. Some subclass of NSManagedObject I suppose? However, that does not matter much. But you should have included the header file of that very class in the .m file in which you are accessing the method. Commented Feb 24, 2013 at 0:23
  • no - it will not compile. I have commented out the bad line and entered debug mode to try and figure out how to access the array. The error if I try and compile is "No known instance of obsSavedSchoolName" and yet this is the attribute of the core data entity. Commented Feb 24, 2013 at 0:25

1 Answer 1

1

Assuming your subclass of NSManagedObject is named "School". Then do:

#include "School.h"

...

School *tempSchool = [self.schoolNames objectAtIndex:0];
obsSchoolName = [tempSchool obsSavedSchoolName];

or

obsSchoolName = [(School*) [self.schoolNames objectAtIndex:0] obsSavedSchoolName];
Sign up to request clarification or add additional context in comments.

3 Comments

You have reminded me of a step I have missed. I have not created the .h and .m file from the core data model. Perfect - thank you so much.
Or simply:obsSchoolName = [(School*) [self.schoolNames[0] obsSavedSchoolName];
Ah, es. I too create the model objects from core data. If you don't then you can access the data directy from NSManagedObject in an alternative way, similar to fetching key value pairs from NSDictionarys. I just perfer it this way although in most cases this is more work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.