Domanda

While this may be a total n00b question, I haven't encountered a situation like this before and was a bit stunned.
I have a few Objective C classes and each has a few properties declared. All properties are properly declared and synthesized.

Simplified, the structure looks something like:

CompanyData - hasA - DepartmentInfo - hasA - Office - hasA - Employee - hasA - isFemale(BOOL)

If I write something like this:

companyData.departmentInfo.office.currentEmployee.isFemale = YES;

my code won't compile and I get "Segmentation fault: 11" error.

However, if I write:

Employee *currentEmployee = companyData.departmentInfo.office.currentEmployee;
currentEmployee.isFemale = YES;

everything compiles fine. Why? What am I missing here?

I am using XCode 4.5 and LLVM GCC 4.2 compiler.

È stato utile?

Soluzione

Make sure

  1. that isFemale is properly synthesized. Beware, the is keyword is an objective-C standard convention (as in @property (nonatomic, getter=isFemale) BOOL female). If in doubt, try another property name, such as femaleGender.

  2. that the Office propery currentEmployee is of type Employee and that the calling class knows about the the Employee properties (`#include "Employee.h").

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top