Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Applications > Mac Applications and Mac App Store

Reply
 
Thread Tools Search this Thread Display Modes
Old Nov 14, 2012, 02:30 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:

//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, etc) 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
ag2web is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Applications > Mac Applications and Mac App Store

Tags
accessors, objective-c, properties, xcode

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Objective C Accessors ag2web Mac Programming 9 Nov 18, 2012 02:53 PM
Objective C question farmerdoug Mac Programming 4 Sep 16, 2012 02:44 PM
Problems with Objective-C++? frank100 Mac Programming 5 Aug 8, 2012 04:49 PM
Testing objective-c Evre iPhone/iPad Programming 21 Jul 12, 2012 07:22 AM
Objective C Syntax nashyo iPhone/iPad Programming 6 Jul 4, 2012 11:56 AM

Forum Jump

All times are GMT -5. The time now is 03:42 PM.

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

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