[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

dot syntax works but square bracket syntax doesn't

Posted on 2014-03-01
3
Medium Priority
?
233 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
[X]
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
  • 2
3 Comments
 
LVL 12

Accepted Solution

by:
satsumo earned 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
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.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

649 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