Created
April 8, 2016 14:46
-
-
Save barbaramartina/df2577b66f57cf414716d1cf0ce4da4c to your computer and use it in GitHub Desktop.
Subclssing a NSOperation to make a synchronous child + Links to the appropiate Apple documentation
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
// | |
// MySynchronousOperation.swift | |
// operationqueues | |
// | |
// Created by Barbara Rodeker on 3/3/16. | |
// Copyright © 2016 Barbara M. Rodeker. All rights reserved. | |
// | |
// This program is free software: you can redistribute it and/or modify | |
// it under the terms of the GNU General Public License as published by | |
// the Free Software Foundation, either version 3 of the License, or | |
// (at your option) any later version. | |
// | |
// This program is distributed in the hope that it will be useful, | |
// but WITHOUT ANY WARRANTY; without even the implied warranty of | |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
// GNU General Public License for more details. | |
// | |
// You should have received a copy of the GNU General Public License | |
// along with this program. If not, see <http://www.gnu.org/licenses/>. | |
// | |
import Foundation | |
class MySynchronousOperation: NSOperation { | |
override func main() { | |
if self.cancelled { | |
return | |
} | |
// DO some processing | |
// cancelled should be checked periodically | |
// From Apple Documentation: In particular, your main task code should periodically check the value of the cancelled property. If the property reports the value true, your operation object should clean up and exit as quickly as possible | |
// https://developer.apple.com/library/mac/documentation/Cocoa/Reference/NSOperation_class/#//apple_ref/doc/uid/TP40004591-RH2-SW18 | |
if self.cancelled { | |
return | |
} | |
// DO more processing | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment