Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Back port convenience functions to Swift 1.2 #83

Merged
merged 1 commit into from Sep 15, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions Operations/Operations/GroupOperation.swift
Expand Up @@ -68,6 +68,10 @@ public class GroupOperation: Operation {
queue.addOperation(operation)
}

public func addOperations(operations: [NSOperation]) {
queue.addOperations(operations, waitUntilFinished: false)
}

final func aggregateError(error: ErrorType) {
aggregateErrors.append(error)
}
Expand Down
4 changes: 2 additions & 2 deletions Operations/Operations/Operation.swift
Expand Up @@ -386,8 +386,8 @@ extension NSOperation {
}

/// Add multiple depdendencies to the operation.
func addDependencies(dependencies: [NSOperation]) {
dependencies.map { self.addDependency($0) }
public func addDependencies(dependencies: [NSOperation]) {
dependencies.map(addDependency)
}
}

Expand Down
6 changes: 0 additions & 6 deletions Operations/Queue/OperationQueue.swift
Expand Up @@ -80,12 +80,6 @@ public class OperationQueue: NSOperationQueue {
public override func addOperations(ops: [AnyObject], waitUntilFinished wait: Bool) {
if let ops = ops as? [NSOperation] {
ops.map(addOperation)

if wait {
for operation in operations {
operation.waitUntilFinished()
}
}
}
}

Expand Down
15 changes: 15 additions & 0 deletions OperationsTests/GroupOperationTests.swift
Expand Up @@ -63,6 +63,21 @@ class GroupOperationTests: OperationTests {
waitForExpectationsWithTimeout(5, handler: nil)
XCTAssertTrue(group.finished)
}

func test__that_adding_multiple_operations_to_a_group_works() {
let group = GroupOperation(operations: [])
let operations: [TestOperation] = (0..<3).map { _ in TestOperation() }
group.addOperations(operations)

addCompletionBlockToTestOperation(group, withExpectation: expectationWithDescription("Test: \(__FUNCTION__)"))
runOperation(group)
waitForExpectationsWithTimeout(3, handler: nil)

XCTAssertTrue(group.finished)
XCTAssertTrue(operations[0].didExecute)
XCTAssertTrue(operations[1].didExecute)
XCTAssertTrue(operations[2].didExecute)
}
}


Expand Down