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)];