1

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.

Maggie
  • 7,823
  • 7
  • 45
  • 66
  • 2
    If you're getting a SEGFAULT during compilation, it's a compiler bug. – Marcelo Cantos Jun 28 '13 at 09:15
  • Bug? Or is it really something a compiler can't compile? – Maggie Jun 28 '13 at 09:17
  • Can you show the definitions of your classes and properties - without those folk can only guess. Also how can you code not compile *and* produce a runtime segmentation fault? – CRD Jun 28 '13 at 09:18
  • 3
    @Maggie: Feed a compiler Shakespeare, and it still shouldn't SEGFAULT. – Marcelo Cantos Jun 28 '13 at 09:21
  • @CRD I will add the exact definition of classes, although I double checked it and evertyhing seems fine. The error I get is a compile-time error. It just won't compile. – Maggie Jun 28 '13 at 09:35
  • 1
    @Maggie - I've tested this (using basic implementation of your classes) with Xcode 4.6.3, Apple LLVM 4.2 & LLVM GCC 4.2 and it compiles and runs correctly using both compilers. Either there is something else in your code causing the issue or you have a compiler bug. Without more detail I can't say which. – CRD Jun 28 '13 at 22:17
  • Thanx, I've tried with XCode 4.3.3 and it works fine as well. Weird. – Maggie Jun 29 '13 at 09:47

1 Answers1

1

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

Mundi
  • 79,884
  • 17
  • 117
  • 140
  • 2
    "the `is` keyword is an objective-C standard" - I don't get it. `is` is not a keyword in Objective-C. It's just fine to call your `BOOL` properties `isXXXX`. –  Jun 28 '13 at 09:26
  • The `is` prefix for boolean property getters is definitely a common and well known convention. It should be considered "standard" in the only way Objective-C knows: documented and described by Apple documentation. – Nikolai Ruhe Jun 28 '13 at 11:31