Hello everyone,
I'm a long time Java developer coming across to the iPhone and Objective C. This is my first day of coding
I started with the basic hello world app which uses a UIView to write some text on the screen. I then decided to implement a standalone class of my own design and see how to access it and get information from it. So I implemented an interface like this:
I then coded the class like this:
And finally modified the drawRect method of my extension to the UIView class to look like this:
When I run this though, I get the message "Error:request for member 'someText' in something not a structure or union."
If I change it to [myClass setSomeText"hello again"]; then everthing works fine and "hello again" is drawn on the screen.
I've done some reading and even found the Objective C example on wikipedia which appears to be practically identical to my code. It sounds to me that the myClass reference(pointer) is not being seen as type MyClass and therefore the compiler will not compile the code. But everything looks fine and matches the code examples I've been looking at.
Any ideas what I'e stuffed up?
ciao
Derek
I'm a long time Java developer coming across to the iPhone and Objective C. This is my first day of coding
I started with the basic hello world app which uses a UIView to write some text on the screen. I then decided to implement a standalone class of my own design and see how to access it and get information from it. So I implemented an interface like this:
Code:
#import <Foundation/Foundation.h>
@interface MyClass : NSObject {
@private
NSString *someText;
}
@property (retain) NSString *someText;
@end
I then coded the class like this:
Code:
#import "MyClass.h"
@implementation MyClass
@synthesize someText;
@end
And finally modified the drawRect method of my extension to the UIView class to look like this:
Code:
- (void)drawRect:(CGRect)rect {
// Drawing code
CGPoint location = CGPointMake(10,20);
UIFont *font = [UIFont systemFontOfSize:24];
MyClass *myClass = [[MyClass alloc] init];
myClass.someText = @"hello again";
[[UIColor redColor] set];
[[myClass someText] drawAtPoint:location withFont:font];
[myClass release];
}
When I run this though, I get the message "Error:request for member 'someText' in something not a structure or union."
If I change it to [myClass setSomeText"hello again"]; then everthing works fine and "hello again" is drawn on the screen.
I've done some reading and even found the Objective C example on wikipedia which appears to be practically identical to my code. It sounds to me that the myClass reference(pointer) is not being seen as type MyClass and therefore the compiler will not compile the code. But everything looks fine and matches the code examples I've been looking at.
Any ideas what I'e stuffed up?
ciao
Derek