Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old Nov 15, 2012, 02:48 PM   #1
ag2web
macrumors newbie
 
Join Date: Mar 2011
Objective C Accessors

I am struggling to understand some basic concepts in Objective C, would appreciate if someone can help. This is about accessors - setters and getters. I have Cocoa application with the following classes:

Code:
//AppDelegate.h
#import <Cocoa/Cocoa.h>
@interface AppDelegate : NSObject <NSApplicationDelegate> 
@property (nonatomic, retain) IBOutlet NSTextView *drawerText;
@end

//AppDelegate.h
@implementation AppDelegate
//some methods here
@end

//Another.h
#import <Cocoa/Cocoa.h>
@interface Another : NSViewController
//some properties here
@end


//Another.m
#import "AppDelegate.h"
@implementation Another
- (void) someMethod {
AppDelegate *appD = [AppDelegate new];
NSTextView *drawerText2 = [[NSTextView alloc] init];
drawerText2.string = @"ABC";
appD.drawerText = drawerText2;
NSLog(@"out %@", appD.drawerText.string);
}
@end
I guess the issue I have should be understandable from what I am trying to do in Another.m someMethod. In summary:

- Theres NSTextView *drawerText defined in AppDelegate
- drawerText is an IBOutlet which is properly linked in IB
- I need to display some content in drawerText and the content should come from Another.m class
- When I run someMethod nothing is displayed in drawerText
- when I NSLog drawerText from Another.m it has ABC value
- when I NSLog drawerText from AppDelegate.m it is empty, though not (null)
- when I run the same someMethod from within AppDelegate.m, everything work, i.e. ABC is displayed in drawerText

As I said, I believe I am missing some basic understanding here, as the issue is not only with this particular drawerText but with any control or instance variable defined in one class and set / get from another class.

I read a lot of Objective C docs by Apple, various books (Stephen G. Kochan, SCOTT KNASTER, MARK DALRYMPLE) but I just can't grasp how to use setters and getters across different classes.

I do not have any programming background, Objective C is my first language. Usually, if there is enough time, I can figure out things, but not this time. By reading these books, I even managed to developed couple of simple Cocoa Apps, but had to keep everything in one class, which obviously is not correct, especially when an app becomes more or less complex.

Any help will be appreciated.
__________________
ag2web
http://www.youtube.com/user/ag2web

Last edited by OllyW; Nov 16, 2012 at 03:19 AM. Reason: Please use code tags
ag2web is offline   0 Reply With Quote

 
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Tags
accessors, getters, objective-c, setters

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 06:50 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC