Note that there are some explanatory texts on larger screens.

plurals
  1. POGet NSMutableDictionary from Singleton?
    primarykey
    data
    text
    <p>I created a singleton class in order to share an object inside my program. Here's the code:</p> <p>SelectedRow.h</p> <pre><code>#import &lt;Foundation/Foundation.h&gt; #import "TableEntry.h" @interface SelectedRow : NSObject { TableEntry *rowValue; } @property (nonatomic, retain) TableEntry *rowValue; + (id)sharedManager; - (void)setVariable:(TableEntry*)value; @end </code></pre> <p>and SelectedRow.m</p> <pre><code>#import "SelectedRow.h" #import "TableEntry.h" @implementation SelectedRow @synthesize rowValue; + (id)sharedManager { static SelectedRow *sharedMyManager = nil; static dispatch_once_t onceToken; dispatch_once(&amp;onceToken, ^{ sharedMyManager = [[self alloc] init]; }); return sharedMyManager; } - (id)init { if (self = [super init]) { rowValue = [[TableEntry alloc] init]; } return self; } - (void)setVariable:(TableEntry*)value { rowValue = value; } @end </code></pre> <p>while TableEntry.h</p> <pre><code>#import &lt;Foundation/Foundation.h&gt; @interface TableEntry : NSObject { @private NSString *videoId; NSString *videoCategory; NSString *videoTitle; NSString *videoDescription; NSDate *videoDate; NSMutableArray *videoRelatedVideos; NSDictionary *videoAdditionalInformation; NSString *videoAccessControl; NSArray *videoFields; NSMutableDictionary *days; NSMutableDictionary *views; NSMutableDictionary *watchtime; NSMutableDictionary *subscribers; NSMutableDictionary *shares; } @property (copy) NSString *videoId; @property (copy) NSString *videoCategory; @property (copy) NSString *videoTitle; @property (copy) NSString *videoDescription; @property (copy) NSMutableArray *videoRelatedVideos; @property (copy) NSDictionary *videoAdditionalInformation; @property (copy) NSArray *videoFields; @property (copy) NSString *videoAccessControl; @property (copy) NSDate *videoDate; @property (copy) NSMutableDictionary *days; @property (copy) NSMutableDictionary *views; @property (copy) NSMutableDictionary *subscribers; @property (copy) NSMutableDictionary *shares; @property (copy) NSMutableDictionary *watchtime; - (id)setId:(NSString*)Id setCategory:(NSString*)Category setDate:(NSDate*)date setTitle:(NSString*)title setDescription:(NSString*)description setRelatedVideos:(NSMutableArray*)relatedVideos setAdditionalInformation:(NSDictionary*)additionalInformation setAccessControl:(NSString*)accessControl setFields:(NSArray*)fields setDays:(NSMutableDictionary*)days setViews:(NSMutableDictionary*)views setSubscribers:(NSMutableDictionary*)subscribers setShares:(NSMutableDictionary*)shares setWatchtime:(NSMutableDictionary*)watchtime; - (NSString*)extractId; - (NSString*)extractCategory; - (NSString*)extractTitle; - (NSString*)extractDescription; - (NSMutableArray*)extractRelatedVideos; - (NSDictionary*)extractAdditionalInformationVideos; - (NSDictionary*)extractAccessControlVideos; - (NSArray*)extractFields; - (NSMutableDictionary*)extractDays; - (NSMutableDictionary*)extractViews; - (NSMutableDictionary*)extractSubscribers; - (NSMutableDictionary*)extractShares; - (NSMutableDictionary*)extractWatchtime; @end </code></pre> <p>and TableEntry.m</p> <pre><code>- (id)init { self = [super init]; if (self) { videoId = @"9bZkp7q19f0"; videoCategory = @"Music"; videoTitle = @"Demo Title"; videoDescription = @"Demo description"; videoDate = [NSDate date]; videoAdditionalInformation = [NSDictionary alloc]; videoRelatedVideos = [NSMutableArray alloc]; videoAccessControl = @"demo accesControl"; videoFields = [NSArray alloc]; days = [NSMutableDictionary alloc]; views = [NSMutableDictionary alloc]; shares = [NSMutableDictionary alloc]; subscribers = [NSMutableDictionary alloc]; watchtime = [NSMutableDictionary alloc]; } return self; } - (id)setId:(NSString*)Id setCategory:(NSString*)Category setDate:(NSDate*)date setTitle:(NSString*)title setDescription:(NSString*)description setRelatedVideos:(NSMutableArray*)relatedVideos setAdditionalInformation:(NSDictionary*)additionalInformation setAccessControl:(NSString*)accessControl setFields:(NSArray*)fields setDays:(NSMutableDictionary*)Days setViews:(NSMutableDictionary*)Views setSubscribers:(NSMutableDictionary*)Subscribers setShares:(NSMutableDictionary*)Shares setWatchtime:(NSMutableDictionary*)Watchtime { videoId = Id; videoCategory = Category; videoDate = date; videoTitle = title; videoDescription = description; videoRelatedVideos = relatedVideos; videoAccessControl = accessControl; videoAdditionalInformation = additionalInformation; videoFields = fields; days = Days; views = Views; subscribers = Subscribers; watchtime = Watchtime; shares = Shares; return self; } - (NSString*)extractId { return self.videoId; } - (NSString*)extractCategory{ return self.videoCategory; } - (NSString*)extractTitle{ return self.videoTitle; } - (NSString*)extractDescription{ return self.videoDescription; } - (NSMutableArray*)extractRelatedVideos{ return self.videoRelatedVideos; } - (NSString*)extractAccessControlVideos{ return self.videoAccessControl; } - (NSDictionary*)extractAdditionalInformationVideos{ return self.videoAdditionalInformation; } - (NSArray*)extractFields{ return self.videoFields; } - (NSMutableDictionary*)extractDays{ return self.days; } - (NSMutableDictionary*)extractSubscribers{ return self.subscribers; } - (NSMutableDictionary*)extractWatchtime{ return self.watchtime; } - (NSMutableDictionary*)extractShares{ return self.shares; } - (NSMutableDictionary*)extractViews{ return self.views; } @end </code></pre> <p>I can extract any values from the singleton with:</p> <pre><code>SelectedRow *selectedRow = [SelectedRow sharedManager]; NSString *videoID = [selectedRow.rowValue extractId]; </code></pre> <p>the problem arises with any NSMutableDictionary. If I try:</p> <pre><code>SelectedRow *selectedRow = [SelectedRow sharedManager]; NSMutableDictionary *days = [selectedRow.rowValue extractDays]; </code></pre> <p>or with any other NSMutableDictionary I get this error:</p> <pre><code>[NSMutableDictionary count]: method sent to an uninitialized mutable dictionary object </code></pre> <p>what I'm I doing wrong? Thanks</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload