2

if i use dot notation in xcode 4 code completion doesn't work for me (pressing ESC):

NSString *s = @"demo";
NSLog(@"%lu", [s length]); //[s <ESC> code completion works fine
NSLog(@"%lu", s.length); //s.<ESC> code completion doesn't work

??

gert
  • 21
  • 1

1 Answers1

0

Make sure that the property has a valid @property accessor defined.

// in .h

@property (assign) int length;

// in .m

@synthesize length;

Keep in mind you can have your own accessors and setters, but I think code-sense needs @property to show up the dot notation.

AWF4vk
  • 5,810
  • 3
  • 37
  • 70
  • This is correct. Xcode's Code Sense won't autocomplete dot-notation for things that aren't actually properties. It will work at runtime, but you are discouraged from using dot-notation for things that aren't properties. – Lily Ballard Jun 11 '11 at 21:53
  • 1
    But isn't 'length' a property of NSString (Reference says it is a method but s.length() doesn't work) ? – gert Jun 12 '11 at 06:50
  • Ok s.length should be avoided since length is a method, and dot notation should be used only for properties ? – gert Jun 12 '11 at 07:06
  • Gert, depends on how you use / declare it. You can certainly use it and declare it as a property. In both cases, length is a method. In the event that "length" calculates something, then I would use a simple method call to be consistent. But if length returns an internal variable, then declaring it as a @property and using dot-notation makes things simpler and easier to understand. Also, don't forget to upvote / mark the answer. Thanks! – AWF4vk Jun 17 '11 at 00:53