문제

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.

도움이 되었습니까?

해결책

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").

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top