I was playing around with the concept of Singleton's so I can have some shared variables that I can use throughout the code. Being a noob to all of this I have run into the following compiler warning and crash of the program. I am guessing I have missed something critical in accessing MyShare but I'm not seeing it.
When I compile I get a warning...
MyShare *slideryear = [MyShare sharedStuff]; <- Compiler Warning here "Warning "MyShare" may not respond to +sharedStuff
This is where the program crashes and then in the Console I see
*** +[MyShare sharedStuff]: unrecognized selector sent to class 0x5118
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** +[MyShare sharedStuff]: unrecognized selector sent to class 0x5118'
Here's the code snippets. I based this off of some DerekNeely.com samples and some Apple pages. It has to be something really obvious that I have missed the concept. Thanks for any help in advance.
Code:
*************
MyShared.h
*************
#import <Foundation/Foundation.h>
@interface MyShare : NSObject {
NSString *whatyearisit;
}
@property (nonatomic, retain) NSString *whatyearisit;
+ (MyShare *)sharedManager;
@end
*************
MyShared.m
*************
#import "MyShared.h"
static MyShare *sharedStuff = nil;
@implementation MyShare
@synthesize whatyearisit;
#pragma mark -
#pragma mark Singleton Methods
+ (MyShare *)sharedManager {
if(sharedStuff == nil) {
sharedStuff = [[super allocWithZone:NULL] init];
}
return sharedStuff;
}
+ (id)allocWithZone:(NSZone *)zone {
return [[self sharedManager] retain];
// other general Singleton stuff not listed since that is not relevant
...
...
*************
MySlideController.m
*************
#import "MySlideController.h"
#import "MyShared.h"
implementation MySlideController
- (IBAction)changeyearresults:(id)sender {
//setup the shared variable... and make sure it works
MyShare *slideryear = [MyShare sharedStuff]; <- Compiler Warning here "Warning "MyShare" may not respond to +sharedStuff and then crash on execution.
slideryear.whatyearisit = @"Not Determined Yet";
...
...
} @end