Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 03-18-2010, 10:41 AM   #2 (permalink)
Kalimba
Pro. Game Developer
iPhone Dev SDK Supporter
 
Join Date: Feb 2009
Location: żLa Islas Hermosas?
Posts: 2,176
Kalimba is on a distinguished road
Default

Quote:
Originally Posted by PhoneKoke View Post
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
Looks like you should be calling [MyShare sharedManager], rather than [MyShare sharedStuff], no?
__________________
~~ Word Flurry ~~ App Store / Website / Facebook
Kalimba is offline   Reply With Quote
 

» Advertisements
» Stats
Members: 175,542
Threads: 94,066
Posts: 402,677
Top Poster: BrianSlick (7,989)
Welcome to our newest member, DieScumBag
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:42 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.