Ok, making the entire reading and increment atomic.
This commit is contained in:
parent
9a0ed2497c
commit
ef0cb81909
1 changed files with 12 additions and 10 deletions
|
|
@ -23,7 +23,7 @@
|
||||||
#import "AFNetworkActivityIndicatorManager.h"
|
#import "AFNetworkActivityIndicatorManager.h"
|
||||||
|
|
||||||
@interface AFNetworkActivityIndicatorManager ()
|
@interface AFNetworkActivityIndicatorManager ()
|
||||||
@property (readwrite, assign) NSInteger activityCount;
|
@property (readwrite, nonatomic, assign) NSInteger activityCount;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation AFNetworkActivityIndicatorManager
|
@implementation AFNetworkActivityIndicatorManager
|
||||||
|
|
@ -40,21 +40,23 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setActivityCount:(NSInteger)activityCount {
|
- (void)setActivityCount:(NSInteger)activityCount {
|
||||||
@synchronized(self) {
|
[self willChangeValueForKey:@"activityCount"];
|
||||||
[self willChangeValueForKey:@"activityCount"];
|
_activityCount = MAX(activityCount, 0);
|
||||||
_activityCount = MAX(activityCount, 0);
|
[self didChangeValueForKey:@"activityCount"];
|
||||||
[self didChangeValueForKey:@"activityCount"];
|
|
||||||
|
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:self.activityCount > 0];
|
||||||
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:self.activityCount > 0];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)startAnimating {
|
- (void)startAnimating {
|
||||||
self.activityCount += 1;
|
@synchronized(self) {
|
||||||
|
self.activityCount += 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)stopAnimating {
|
- (void)stopAnimating {
|
||||||
self.activityCount -= 1;
|
@synchronized(self) {
|
||||||
|
self.activityCount -= 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue