Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

dot syntax works but square bracket syntax doesn't

Posted on 2014-03-01
3
220 Views
Last Modified: 2014-03-02
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
Comment
Question by:developingprogrammer
  • 2
3 Comments
 
LVL 12

Accepted Solution

by:
satsumo earned 500 total points
ID: 39898495
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
 

Author Comment

by:developingprogrammer
ID: 39898510
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
 
LVL 12

Expert Comment

by:satsumo
ID: 39898541
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

Manage your data center from practically anywhere

The KN8164V features HD resolution of 1920 x 1200, FIPS 140-2 with level 1 security standards and virtual media transmissions at twice the speed. Built for reliability, the KN series provides local console and remote over IP access, ensuring 24/7 availability to all servers.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question