In Swift, the correct answer is almost always protocols and extensions. This is almost never inheritance. Sometimes Cocoa stands in our way, because classes in Cocoa are more common than protocols, but the goal is almost always protocols and extensions. The subclass is our last choice.
Your specific case is confusing because NSOperationQueue already has an open method for canceling operations in the queue ( cancelAllOperations ). If you want to protect the queue from external access (to prevent callers from directly using addOperation ), then you must put the queue in a different type (i.e., Composition) and redirect what you want to the queue. More detailed information about the specific problem you are solving will help us to offer other similar solutions to Swift.
If you need something like protected or friend , private right solution. Put your subclass or your friend in the same file with the target and mark the private thing private . Also, put things that should work together in a framework, and tag the internal attribute. Swift Blog gives a good explanation of why this is an intentional choice.
source share