• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 237
  • Last Modified:

dot syntax works but square bracket syntax doesn't

hey guys,

i'm trying to write this line of code and dot syntax works but not square brackets - which perplexes me.

@property(weak,nonatomic)IBOutlet UITextView *tView; //defined in header file

[[self tView] text]=@""; //doesn't work - expression not assignable (in implementation file)
self.tView.text=@""; //this works (in implementation file)

i'm using Xcod 5.0.2
0
developingprogrammer
Asked:
developingprogrammer
  • 2
1 Solution
 
satsumoSoftware DeveloperCommented:
The square brackets don't work because text is a get method. It returns a pointer to the NSString object that is the text property. To set the text property with square bracket syntax you would use:

[[self tlView] setText: @""];
The compiler converts dot syntax to either get or set method according to the context, which is why it works. This question should really be in an Objective-C topic but I can't find one.
0
 
developingprogrammerAuthor Commented:
whao satsumo, that is definitely very enlightening for me. i definitely didn't know that about . syntax and square brackets syntax. but then again i am almost completely new. thanks so much for letting me know though! = )

yup i agree with you that this question should definitely be in Objective C topic but there isn't one and in fact i've raised a question about this which Kent has answered (http://www.experts-exchange.com/Programming/Languages/C/Q_28377590.html). here is the link. i'm hoping that perhaps Objective C can be added as a topic and EE would be enriched = )

thanks once again! = )
0
 
satsumoSoftware DeveloperCommented:
If you're new to Obj-C I very much recommend this book:

http://www.amazon.co.uk/Objective-C-Pocket-Reference-Andrew-Duncan/dp/0596004230

It covers pretty much everything in a straightforward way and it doesn't cost much. It sits on my desk permanently now, so that I can look up those odd bits of syntax. It doesn't cover iOS and its not a 'how to program' guide, but I doubt you need anything like that.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now