Skip to content

Commit

Permalink
Modernized
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Hersh committed Mar 26, 2015
1 parent f7613bb commit 21048ae
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 50 deletions.
2 changes: 1 addition & 1 deletion Example/Podfile
Expand Up @@ -7,5 +7,5 @@ xcodeproj 'SSOperationsExample'
pod 'SSOperations', :path => "../SSOperations.podspec"

target :SSOperationsTests, :exclusive => true do
pod 'MXGSynchronizeTest'
pod 'SSOperations', :path => "../SSOperations.podspec"
end
7 changes: 2 additions & 5 deletions Example/Podfile.lock
@@ -1,17 +1,14 @@
PODS:
- MXGSynchronizeTest (1.1.0)
- SSOperations (0.0.3)
- SSOperations (0.1.0)

DEPENDENCIES:
- MXGSynchronizeTest
- SSOperations (from `../SSOperations.podspec`)

EXTERNAL SOURCES:
SSOperations:
:path: ../SSOperations.podspec

SPEC CHECKSUMS:
MXGSynchronizeTest: 8f2f041ca6896caec74463ab43743d97d3dc8c18
SSOperations: 25c0f7301d3597e09ae4d462c2e5405500bef235
SSOperations: 1c376d41ebfd44aab5c575da3f7458f0c92d5efa

COCOAPODS: 0.35.0
4 changes: 4 additions & 0 deletions Example/SSOperationsExample.xcodeproj/project.pbxproj
Expand Up @@ -469,6 +469,8 @@
COPY_PHASE_STRIP = NO;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_GENERATE_TEST_COVERAGE_FILES = YES;
GCC_INSTRUMENT_PROGRAM_FLOW_ARCS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
Expand Down Expand Up @@ -515,6 +517,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 83F66D6F1BDD9F2CA32F25C3 /* Pods.debug.xcconfig */;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "SSOperationsExample/SSOperationsExample-Prefix.pch";
INFOPLIST_FILE = "SSOperationsExample/SSOperationsExample-Info.plist";
Expand All @@ -527,6 +530,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 4C7239018484A5BCAD64ECF2 /* Pods.release.xcconfig */;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "SSOperationsExample/SSOperationsExample-Prefix.pch";
INFOPLIST_FILE = "SSOperationsExample/SSOperationsExample-Info.plist";
Expand Down
2 changes: 1 addition & 1 deletion Example/SSOperationsExample/SSViewController.h
Expand Up @@ -6,7 +6,7 @@
// Copyright (c) 2013 Splinesoft. All rights reserved.
//

#import <UIKit/UIKit.h>
@import UIKit;

@interface SSViewController : UIViewController

Expand Down
6 changes: 3 additions & 3 deletions Example/SSOperationsExample/SSViewController.m
Expand Up @@ -31,15 +31,15 @@ - (void)viewDidLoad {
[concurrentQueue name]);

// Run some operations!
for( NSUInteger i = 0; i < 10; i++ ) {
for (NSUInteger i = 0; i < 10; i++) {
[serialQueue ss_addBlockOperationWithBlock:^(SSBlockOperation *operation) {
for( NSUInteger j = 0; j < 100; j++ )
NSLog(@"Serial #%i: %i", i, j);
NSLog(@"Serial #%@: %@", @(i), @(j));
}];

[concurrentQueue ss_addBlockOperationWithBlock:^(SSBlockOperation *operation) {
for( NSUInteger j = 0; j < 100; j++ )
NSLog(@"Concurrent #%i: %i", i, j);
NSLog(@"Concurrent #%@: %@", @(i), @(j));
}];
}
}
Expand Down
51 changes: 21 additions & 30 deletions Example/SSOperationsTests/SSOperationsTests.m
Expand Up @@ -6,29 +6,15 @@
// Copyright (c) 2014 Splinesoft. All rights reserved.
//

#import <XCTest/XCTest.h>
#import <NSOperationQueue+SSAdditions.h>
#import <SSBlockOperation.h>
#import <XCTest+MXGSynchronizeTest.h>
@import XCTest;
#import <SSOperations.h>

@interface SSOperationsTests : XCTestCase

@end

@implementation SSOperationsTests

- (void)setUp
{
[super setUp];
// Put setup code here. This method is called before the invocation of each test method in the class.
}

- (void)tearDown
{
// Put teardown code here. This method is called after the invocation of each test method in the class.
[super tearDown];
}

- (void)testOperationQueuesInitialize
{
NSOperationQueue *singleQueue = [NSOperationQueue ss_serialOperationQueue];
Expand All @@ -48,29 +34,34 @@ - (void)testOperationSubmit
{
NSOperationQueue *singleQueue = [NSOperationQueue ss_serialOperationQueue];

[XCTest mxg_synchronizeTest:^(BOOL *finished) {
[singleQueue ss_addBlockOperationWithBlock:^(SSBlockOperation *operation) {
XCTAssertFalse([NSThread isMainThread], @"Should not run on main thread");
*finished = YES;
}];
XCTestExpectation *submitExpectation = [self expectationWithDescription:@"Single queue submit"];

[singleQueue ss_addBlockOperationWithBlock:^(SSBlockOperation *operation) {
XCTAssertFalse([NSThread isMainThread], @"Should not run on main thread");
[submitExpectation fulfill];
}];

[self waitForExpectationsWithTimeout:5 handler:nil];
}

- (void)testSerialQueue
{
NSOperationQueue *singleQueue = [NSOperationQueue ss_serialOperationQueue];
NSDate *expectedEndDate = [[NSDate date] dateByAddingTimeInterval:1];

[XCTest mxg_synchronizeTest:^(BOOL *finished) {
[singleQueue ss_addBlockOperationWithBlock:^(SSBlockOperation *operation) {
sleep(1);
}];
[singleQueue ss_addBlockOperationWithBlock:^(SSBlockOperation *operation) {
XCTAssertTrue([[NSDate date] compare:expectedEndDate] == NSOrderedDescending,
@"Should have run serially");
*finished = YES;
}];
XCTestExpectation *serialExpectation = [self expectationWithDescription:@"Serial Queue"];

[singleQueue ss_addBlockOperationWithBlock:^(SSBlockOperation *operation) {
sleep(2);
}];

[singleQueue ss_addBlockOperationWithBlock:^(SSBlockOperation *operation) {
XCTAssertTrue([[NSDate date] compare:expectedEndDate] == NSOrderedDescending,
@"Should have run serially");
[serialExpectation fulfill];
}];

[self waitForExpectationsWithTimeout:8 handler:nil];
}

@end
3 changes: 2 additions & 1 deletion SSOperations.podspec
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "SSOperations"
s.version = "0.0.3"
s.version = "0.1.0"
s.summary = "Handy NSOperationQueue and NSBlockOperation helpers."
s.homepage = "https://github.com/splinesoft/SSOperations"
s.license = { :type => 'MIT', :file => 'LICENSE' }
Expand All @@ -10,4 +10,5 @@ Pod::Spec.new do |s|
s.requires_arc = true
s.source_files = 'SSOperations/*.{h,m}'
s.frameworks = 'Foundation'
s.compiler_flags = '-fmodules'
end
2 changes: 1 addition & 1 deletion SSOperations/NSOperationQueue+SSAdditions.h
Expand Up @@ -6,7 +6,7 @@
// Copyright (c) 2013 Splinesoft. All rights reserved.
//

#import <Foundation/Foundation.h>
@import Foundation;
#import "SSBlockOperation.h"

@interface NSOperationQueue (SSAdditions)
Expand Down
16 changes: 9 additions & 7 deletions SSOperations/NSOperationQueue+SSAdditions.m
Expand Up @@ -9,15 +9,17 @@
#import "SSOperations.h"

@interface NSOperationQueue (SSNaming)
+ (NSString *) defaultQueueName;

+ (NSString *) ss_defaultQueueName;

@end

@implementation NSOperationQueue (SSAdditions)

#pragma mark - Constructors

+ (instancetype) ss_serialOperationQueue {
return [self ss_serialOperationQueueNamed:[self defaultQueueName]];
return [self ss_serialOperationQueueNamed:[self ss_defaultQueueName]];
}

+ (instancetype)ss_serialOperationQueueNamed:(NSString *)name {
Expand All @@ -26,7 +28,7 @@ + (instancetype)ss_serialOperationQueueNamed:(NSString *)name {
}

+ (instancetype) ss_concurrentMaxOperationQueue {
return [self ss_concurrentMaxOperationQueueNamed:[self defaultQueueName]];
return [self ss_concurrentMaxOperationQueueNamed:[self ss_defaultQueueName]];
}

+ (instancetype)ss_concurrentMaxOperationQueueNamed:(NSString *)name {
Expand All @@ -36,7 +38,7 @@ + (instancetype)ss_concurrentMaxOperationQueueNamed:(NSString *)name {

+ (instancetype) ss_concurrentQueueWithConcurrentOperations:(NSUInteger)operationCount {
return [self ss_concurrentQueueWithConcurrentOperations:operationCount
named:[self defaultQueueName]];
named:[self ss_defaultQueueName]];
}

+ (instancetype)ss_concurrentQueueWithConcurrentOperations:(NSUInteger)operationCount
Expand All @@ -56,10 +58,10 @@ - (void) ss_addBlockOperationWithBlock:(SSBlockOperationBlock)block {

#pragma mark - naming

+ (NSString *)defaultQueueName {
return [NSString stringWithFormat:@"%@-%f",
+ (NSString *) ss_defaultQueueName {
return [NSString stringWithFormat:@"%@-%@",
NSStringFromClass(self),
[[NSDate date] timeIntervalSince1970]];
@([[NSDate date] timeIntervalSince1970])];
}

@end
2 changes: 1 addition & 1 deletion SSOperations/SSBlockOperation.h
Expand Up @@ -6,7 +6,7 @@
// Copyright (c) 2013 Splinesoft. All rights reserved.
//

#import <Foundation/Foundation.h>
@import Foundation;

/**
* A block operation that is passed itself as an input when executed.
Expand Down

0 comments on commit 21048ae

Please sign in to comment.