- Data going missing when passed between threads using a Singleton
- @property (nonatomic, assign) ProgressUpdate *progressUpdate;
- // Ask delegate to update and display Progress text
- -(void) updateProgressSummary:(NSString *)summary detail:(NSString *)detail percentComplete:(NSNumber *)complete {
- // These report the proper values
- DLog(@"Reporting Summary - %s", [summary UTF8String]);
- DLog(@"Reporting Detail - %s", [detail UTF8String]);
- DLog(@"Reporting Complete - %i", [complete intValue]);
- if (summary != nil)
- self.progressUpdate.summaryText = summary;
- self.progressUpdate.detailText = detail;
- self.progressUpdate.percentComplete = complete;
- ProgressUpdate *progressUpdateForIssue = [[ProgressUpdate alloc] initWithProgressUpdate:progressUpdate];
- [self.delegate performSelectorOnMainThread:@selector(displayProgress:) withObject:progressUpdateForIssue waitUntilDone:NO];
- [progressUpdateForIssue release];
- }
- @property (nonatomic, retain) NSString *summaryText;
- @property (nonatomic, retain) NSString *detailText;
- @property (nonatomic, retain) NSNumber *percentComplete;
- -(id) initWithProgressUpdate:(ProgressUpdate *)update {
- if ((self = [super init])) {
- summaryText = [update.summaryText copy];
- detailText = [update.detailText copy];
- percentComplete = [[NSNumber alloc] initWithFloat:[update.percentComplete floatValue]];
- }
- // These report nil values
- DLog(@"Reporting in progUpdate summaryText - %s", [summaryText UTF8String]);
- DLog(@"Reporting in progUpdate detailText - %s", [detailText UTF8String]);
- DLog(@"Reporting in progUpdate percentComplete - %i", [percentComplete intValue]);
- return self;
- }
- #import <Foundation/Foundation.h>
- @interface ProgressUpdate : NSObject {
- NSString *summaryText;
- NSString *detailText;
- NSNumber *percentComplete;
- }
- @property (nonatomic, assign) NSString *summaryText;
- @property (nonatomic, assign) NSString *detailText;
- @property (nonatomic, assign) NSNumber *percentComplete;
- -(id) initWith:(ProgressUpdate *)update;
- @end
- #import "ProgressUpdate.h"
- @implementation ProgressUpdate
- @synthesize summaryText, detailText, percentComplete;
- -(id) initWith:(ProgressUpdate *)update {
- self = [super init];
- self.summaryText = update.summaryText;
- self.detailText = update.detailText;
- self.percentComplete = update.percentComplete;
- return self;
- }
- @end
- static ProgressController *sharedInstance;
- + (ProgressController *)sharedInstance {
- @synchronized(self) {
- if (!sharedInstance)
- [[ProgressController alloc] init];
- }
- return sharedInstance;
- }
- +(id)alloc {
- @synchronized(self) {
- NSAssert(sharedInstance == nil, NSLocalizedString(@"Attempted to allocate a second instance of a singleton ProgressController.", @"Attempted to allocate a second instance of a singleton ProgressController."));
- sharedInstance = [super alloc];
- }
- return sharedInstance;
- }
- -(id) init {
- if (self = [super init]) {
- [self open];
- }
- return self;
- }
- .........
- // Ask delegate to update and display Progress text
- -(void) updateProgressSummary:(NSString *)summary detail:(NSString *)detail percentComplete:(NSNumber *)complete {
- if (summary != nil)
- self.progressUpdate.summaryText = summary;
- self.progressUpdate.detailText = detail;
- self.progressUpdate.percentComplete = complete;
- ProgressUpdate *progressUpdateForIssue = [[ProgressUpdate alloc] initWith:progressUpdate];
- [self.delegate performSelectorOnMainThread:@selector(displayProgress:) withObject:progressUpdateForIssue waitUntilDone:NO];
- [progressUpdateForIssue release];
- }
- // Delegate method to display specific text in Progress label
- - (void) displayProgress:(ProgressUpdate *)update {
- [progressSummaryLabel setText:update.summaryText];
- [progressDetailLabel setText:update.detailText];
- [progressBar setProgress:[update.percentComplete intValue]];
- [progressView setNeedsDisplay];
- }
- -(id) initWithProgressUpdate:(ProgressUpdate *)update {
- if ((self = [super init])) {
- summaryText = [update.summaryText copy];
- detailText = [update.detailText copy];
- percentComplete = [[NSNumber alloc] initWithFloat:[update.percentComplete floatValue];
- }
- return self;
- }