Amazon.com Widgets Instance Variables
Welcome, Guest. Please login or register.
Did you miss your activation email?
June 20, 2013, 03:44:46 AM
Home Help Search chat Login Register   
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan
                     

+  Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+  Programming in Objective-C, 4th edition
| |-+  General Discussion
| | |-+  Instance Variables
Pages: [1]   Go Down
Print
Author Topic: Instance Variables  (Read 624 times)
jonthornham
Full Member
***
Posts: 169



WWW Email




« on: April 27, 2012, 04:50:31 PM »

I am currently learning about ARC and noticed the following in some of the updated texts I've been reading.

I am used to seeing:

Code: (Objective-C)
@interface myViewController: UIViewController
{
        UIButton *myButton;
}

@property (nonatomic, retain) IBOutlet UIButton *myButton;

@end

@implementation myViewController

@synthesize myButton;

...

@end

I see the new format is:

Code: (Objective-C)
@interface myViewController: UIViewController

@property (weak, nonatomic) IBOutlet UIButton *myButton;

@end

@implementation myViewController

@synthesize myButton;

...

@end

I am assuming that the section:

Code: (Objective-C)
{
        UIButton *myButton;
}

Is recognized by simply typing:

Code: (Objective-C)
@property (weak, nonatomic) IBOutlet UIButton *myButton;

Is this true?  Also, is this technically due to ARC or is it that the compiler in Xcode 4.2 allows for the change?

Finally, I notice in the new addition of the book you add the following to the @implementation section:

{
        int numerator;
        int denominator;
}

However, this is not added to the example I used above and is not in the "Transition to ARC" guide.  Is this because they are not objects or is there another reason they are added in the book.

Take care,

Jon
Logged

Jon Thornham
jonthornham
Full Member
***
Posts: 169



WWW Email




« Reply #1 on: April 28, 2012, 09:48:50 PM »

I just found the answer to part of my question.  The reason the declarations for numerator and denominator where in the book was because the variables were not synthesized yet.  The addition of the @porperty and @synthesize calls eliminates the need to declare the instance variables. Pretty cool. 

I still have my second question.  Is this part of ARC, or is it simply that Xcode is smarter?

Take care,

Jon
Logged

Jon Thornham
happyzhb
Administrator
Newbie
*****
Posts: 47


Email




« Reply #2 on: May 11, 2012, 09:06:45 AM »

jonthornham, it is not part of ARC. I believe Xcode is just getting smarter.

However, the part that "retain" is changed to "weak" in the brackets ("nonatomic" is unchanged) is because of ARC.
Logged
jonthornham
Full Member
***
Posts: 169



WWW Email




« Reply #3 on: May 11, 2012, 09:14:57 AM »

Thank you for the reply I appreciate it.
Logged

Jon Thornham
jcmeyer5
Newbie
*
Posts: 2






« Reply #4 on: May 22, 2012, 07:55:04 AM »

Okay, so for a follow up... is there any reason we would want to put instance variables (other than properties) in the interface file anymore?  Seems to me that properties takes care of the "public" part of variable declaration (since public variables will pretty much always need setter/getter methods), and that anything else should probably be in the implementation file.

Is there a reason I would want a public iVar that is NOT a property?

Thanks!

Jim
Logged
Pages: [1]   Go Up
Print
Jump to:  



Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 classroomM.com. All rights reserved.