title: How to access @private instance variable using category in Objective-C?
body: <p>As it states in the Apple's documentation: <a href="http://developer.apple.com/library/mac/#documentation/cocoa/Conceptual/ObjectiveC/Chapters/ocCategories.html#//apple_ref/doc/uid/TP30001163-CH20-SW1" rel="nofollow">http://developer.apple.com/library/mac/#documentation/cocoa/Conceptual/ObjectiveC/Chapters/ocCategories.html#//apple_ref/doc/uid/TP30001163-CH20-SW1</a></p>
  
  <p><code>Note that a category can’t declare additional instance variables for the class; it includes only methods. However, all instance variables within the scope of the class are also within the scope of the category. That includes all instance variables declared by the class, even ones declared @private.</code></p>
  
  <p>However, when I tried to access a private instance variable of UITextField "_selectionRange" I get symbol not found error. Below are my source code and error message for your reference. I apologize for those who read my last example "NSString". It wasn't a good example since there isn't any @private instance variables in NSString class.</p>
  
  <p>NSString+Utilities.h</p>
  
  <pre><code>#import &lt;Foundation/Foundation.h&gt;
  @interface UITextField (Editing)
  - (void)deleteBkw;
  @end
  </code></pre>
  
  <p>NSString+Utilities.m</p>
  
  <pre><code>@implementation UITextField (Editing)
  - (void)deleteBkw {
      NSLog(@"%d:%d", _selectionRange.location, _selectionRange.length);
  }
  @end
  </code></pre>
  
  <p>Error:
  Undefined symbols for architecture i386:
    "_OBJC_IVAR_$_UITextField._selectionRange", referenced from:
        -[UITextField(Editing) deleteBkw] in NSString+Utilities.o
  ld: symbol(s) not found for architecture i386
  collect2: ld returned 1 exit status</p>