Ios 获得;无法识别的选择器发送到类“0”;使用单例

Ios 获得;无法识别的选择器发送到类“0”;使用单例,ios,Ios,我是ios新手,我尝试编写一个简单的单例对象来在控制器之间共享数据。这是我的密码: #import <Foundation/Foundation.h> #import "SynthesizeSingleton.h"; @interface BSStore : NSObject +(BSStore *)sharedStore; @property (nonatomic,strong) NSArray *sharedNotebooks; @end #import "BSSt

我是ios新手,我尝试编写一个简单的单例对象来在控制器之间共享数据。这是我的密码:

#import <Foundation/Foundation.h>
#import "SynthesizeSingleton.h";

@interface BSStore : NSObject

+(BSStore *)sharedStore;

@property (nonatomic,strong) NSArray *sharedNotebooks;

@end



#import "BSStore.h"

@implementation BSStore

SYNTHESIZE_SINGLETON_FOR_CLASS(BSStore)

@synthesize sharedNotebooks;

@end
//读取ViewController中的对象

  Notebook *notebook = [[BSStore sharedStore].sharedNotebooks objectAtIndex:indexPath.row];
我得到:

2012-10-04 02:01:29.053 BarneyShop[1827:f803] +[BSStore sharedStore]: unrecognized selector sent to class 0x69b8
2012-10-04 02:01:29.073 BarneyShop[1827:f803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[BSStore sharedStore]: unrecognized selector sent to class 0x69b8'
*** First throw call stack:

这就是您的Singleton类的外观:

#import "BSStore.h"

@implementation BSStore

@synthesize sharedNotebooks;

+ (BSStore *) sharedStore
{
    static BSStore * singleton;

    if ( ! singleton)
    {
        singleton = [[BSStore alloc] init];

    }
    return singleton;
}

@end
现在您可以拨打:

[BSStore sharedStore].sharedNotebooks;

您不会显示创建singleton的位置。Synthesis_singleton_FOR_CLASS(BSStore)/////SynthesisSingleton.h///CocoaWithLove///由Matt Gallagher于2008年10月20日创建。///版权所有2009马特·加拉赫。保留所有权利。我的意思是:好的。这样就行了。但我上面的代码使用synthesis_SINGLETON_FOR_类有什么问题?上面的代码是什么?您的类为空,这就是问题所在,您没有初始化该类。就您的评论而言,Synthesis_SINGLETON_FOR_CLASS(BSStore)/////synthesissingleton.h///CoCoCoaWithLove///由Matt Gallagher于2008年10月20日创建。///版权所有2009马特·加拉赫。版权所有。
[BSStore sharedStore].sharedNotebooks;