forked from dbukowski/DBDebugToolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed network table view management.
- Loading branch information
Showing
7 changed files
with
292 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
DBDebugToolkit/Classes/Network/MainQueueOperation/DBMainQueueOperation.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// The MIT License | ||
// | ||
// Copyright (c) 2016 Dariusz Bukowski | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
typedef void(^DBMainQueueOperationBlock)(void); | ||
|
||
/** | ||
`DBMainQueueOperation` is a `NSOperation` subclass running a given block on a main queue. | ||
*/ | ||
@interface DBMainQueueOperation : NSOperation | ||
|
||
/** | ||
Initializes `DBMainQueueOperation` object with a block. | ||
@param block The block that will be invoked on the main queue. | ||
*/ | ||
- (instancetype)initWithMainQueueOperationBlock:(DBMainQueueOperationBlock)block; | ||
|
||
/** | ||
Creates and returns a new `DBMainQueueOperation` instance encapsulating a given block. | ||
@param block The block that will be invoked on the main queue. | ||
*/ | ||
+ (instancetype)mainQueueOperationWithBlock:(DBMainQueueOperationBlock)block; | ||
|
||
@end |
97 changes: 97 additions & 0 deletions
97
DBDebugToolkit/Classes/Network/MainQueueOperation/DBMainQueueOperation.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// The MIT License | ||
// | ||
// Copyright (c) 2016 Dariusz Bukowski | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
#import "DBMainQueueOperation.h" | ||
|
||
typedef NS_ENUM(NSUInteger, DBMainQueueOperationState) { | ||
DBMainQueueOperationStateNotStarted, | ||
DBMainQueueOperationStateStarted, | ||
DBMainQueueOperationStateFinished | ||
}; | ||
|
||
@interface DBMainQueueOperation () | ||
|
||
@property (nonatomic, assign) DBMainQueueOperationState state; | ||
@property (nonatomic, copy) DBMainQueueOperationBlock block; | ||
|
||
@end | ||
|
||
@implementation DBMainQueueOperation | ||
|
||
#pragma mark - Initialization | ||
|
||
- (instancetype)initWithMainQueueOperationBlock:(DBMainQueueOperationBlock)block { | ||
self = [super init]; | ||
if (self) { | ||
self.block = block; | ||
self.state = DBMainQueueOperationStateNotStarted; | ||
} | ||
|
||
return self; | ||
} | ||
|
||
+ (instancetype)mainQueueOperationWithBlock:(DBMainQueueOperationBlock)block { | ||
return [[self alloc] initWithMainQueueOperationBlock:block]; | ||
} | ||
|
||
#pragma mark - NSOperation methods | ||
|
||
- (void)start { | ||
if (self.isCancelled) { | ||
[self willChangeValueForKey:@"isFinished"]; | ||
self.state = DBMainQueueOperationStateFinished; | ||
[self didChangeValueForKey:@"isFinished"]; | ||
return; | ||
} | ||
|
||
dispatch_async(dispatch_get_main_queue(), ^{ | ||
[self willChangeValueForKey:@"isExecuting"]; | ||
self.state = DBMainQueueOperationStateStarted; | ||
[self didChangeValueForKey:@"isExecuting"]; | ||
|
||
if (self.block) { | ||
self.block(); | ||
} | ||
|
||
[self willChangeValueForKey:@"isFinished"]; | ||
[self willChangeValueForKey:@"isExecuting"]; | ||
|
||
self.state = DBMainQueueOperationStateFinished; | ||
|
||
[self didChangeValueForKey:@"isFinished"]; | ||
[self didChangeValueForKey:@"isExecuting"]; | ||
}); | ||
} | ||
|
||
- (BOOL)isFinished { | ||
return self.state == DBMainQueueOperationStateFinished; | ||
} | ||
|
||
- (BOOL)isExecuting { | ||
return self.state == DBMainQueueOperationStateStarted; | ||
} | ||
|
||
- (BOOL)isAsynchronous { | ||
return NO; | ||
} | ||
|
||
@end |
38 changes: 38 additions & 0 deletions
38
DBDebugToolkit/Classes/Network/MainQueueOperation/NSOperationQueue+DBMainQueueOperation.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// The MIT License | ||
// | ||
// Copyright (c) 2016 Dariusz Bukowski | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
#import <Foundation/Foundation.h> | ||
#import "DBMainQueueOperation.h" | ||
|
||
/** | ||
`NSOperationQueue` category that provides a helper method for adding a single main queue operation. | ||
*/ | ||
@interface NSOperationQueue (DBMainQueueOperation) | ||
|
||
/** | ||
Adds a single main queue operation encapsulating a given block. | ||
@param block The block that will be invoked on the main queue. | ||
*/ | ||
- (void)addMainQueueOperationWithBlock:(DBMainQueueOperationBlock)block; | ||
|
||
@end |
32 changes: 32 additions & 0 deletions
32
DBDebugToolkit/Classes/Network/MainQueueOperation/NSOperationQueue+DBMainQueueOperation.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// The MIT License | ||
// | ||
// Copyright (c) 2016 Dariusz Bukowski | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
#import "NSOperationQueue+DBMainQueueOperation.h" | ||
|
||
@implementation NSOperationQueue (DBMainQueueOperation) | ||
|
||
- (void)addMainQueueOperationWithBlock:(DBMainQueueOperationBlock)block { | ||
DBMainQueueOperation *operation = [DBMainQueueOperation mainQueueOperationWithBlock:block]; | ||
[self addOperation:operation]; | ||
} | ||
|
||
@end |
Oops, something went wrong.