Solved

dot syntax works but square bracket syntax doesn't

Posted on 2014-03-01
3
215 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
port mapped I/o query 10 136
How to create empty file in SAS? 3 313
Problem with form project 66 313
C Programming - If Statement 8 47
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…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
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 opening and writing to files in the C programming language.

772 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now