单例传值

Singleton.h

@interfaceSingleton :NSObject

@property(nonatomic,copy)NSString* musicName;

+(Singleton*)singletonInstance;

@end

Singleton.m

@implementationSingleton

staticSingleton* single =nil;

+(Singleton*)singletonInstance{

//判断全局变量single值的情况

if(single!=nil) {

returnsingle;

}

single= [[Singletonalloc]init];

returnsingle;

}

RootViewController.m

/*

单例的使用

*/

//---------//

[[SingletonsingletonInstance]setMusicName:@"少年锦时"];

//---------//

LoginViewController.m

[buttonsetTitle:[[SingletonsingletonInstance]musicName]forState:(UIControlStateNormal)];

你可能感兴趣的:(单例传值)