Solved

dot syntax works but square bracket syntax doesn't

Posted on 2014-03-01
3
219 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
In desperate need of help 8 138
Acrinis True image 2 80
delete-remove 14 87
Display a Float Variable in C without using the function printf. 2 14
Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
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 how to use strings and some functions related to them in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

831 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