Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 12th, 2012  |  syntax: None  |  size: 1.10 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Changing between tabs using a Singleton class causes SIGABRT
  2. @interface SingletonClass : NSObject
  3. {
  4. }
  5.  
  6. @property(nonatomic, retain) NSMutableArray *categoryArray;
  7.  
  8. + (SingletonClass *)sharedInstance;
  9. - (id) init;
  10. - (void)setCategory: (NSMutableArray *) x;
  11. - (NSMutableArray *)getCategory;
  12.  
  13. @end
  14.        
  15. #import "SingletonClass.h"
  16.  
  17. @implementation SingletonClass
  18. @synthesize categoryArray;
  19.  
  20.  
  21. static SingletonClass *sharedInstance = nil;
  22.  
  23. + (SingletonClass *)sharedInstance {
  24.     if (sharedInstance == nil) {
  25.         sharedInstance = [[super allocWithZone:NULL] init];
  26.     }
  27.     return sharedInstance;
  28. }
  29.  
  30. - (id)init
  31. {
  32.     self = [super init];
  33.  
  34.     if (self) {
  35.         categoryArray = [[NSMutableArray alloc] init];
  36.     }
  37.  
  38.     return self;
  39. }
  40.  
  41. + (id)allocWithZone:(NSZone*)zone {
  42.     return [self sharedInstance];
  43. }
  44.  
  45. - (id)copyWithZone:(NSZone *)zone {
  46.     return self;
  47. }
  48.  
  49. - (void)setCategory: (NSMutableArray *)category_array{
  50.     categoryArray = category_array;
  51. }
  52.  
  53. - (NSMutableArray *)getCategory{
  54.     return categoryArray;
  55. }
  56.  
  57. @end
  58.        
  59. SingletonClass* myapp = [SingletonClass sharedInstance];
  60. categories = [myapp getCategory];