I am developing an app using SDK 8.1, Apple LLVM 6.0 and Xcode 6.1.1. The deployment target is 6.0. I'm using NSOperationQueue
and I want to use QoS whenever it's available.
The code I'm using is:
if ([self.operationQueue respondsToSelector:@selector(setQualityOfService:)]
&& (&NSOperationQualityOfServiceUserInitiated)) {
[self.operationQueue performSelector:@selector(setQualityOfService:) withObject: NSOperationQualityOfServiceUserInitiated];
} else {
//Other stuff not related to the scope of this question
}
The error I get is:
Use of undeclared identifier 'NSOperationQualityOfServiceUserInitiated'
I added the if (&NSOperationQualityOfServiceUserInitiated)
part to check if this constant exists. This code worked with older versions of Xcode/Obj-C Compiler.
I am able to use selectors with performSelectorWithIdentifier
but what about constants that do not have a defined value in the docs? The value of this constant is set by NSQualityOfServiceUserInitiated
but there is no definition for this value that can be hardcoded.
How do I fix that?
There are several things wrong with the code.
NSOperationQualityOfServiceUserInitiated
is a native type (NSInteger
) so you can't use it the way that you are in either line.qualityOfService
is a property of type NSQualityOfService
. Your attempt to pass an argument to the qualityOfService
method (getter method) makes no sense. If you are trying to set the quality of service, you need to call the setter but you can't use performSelector
.You want:
if ([self.operationQueue respondsToSelector:@selector(qualityOfService)]) {
self.operationQueue.qualityOfService = NSOperationQualityOfServiceUserInitiated;
} else {
//Other stuff not related to the scope of this question
}
This code will compile fine as long as your Base SDK is iOS 8.0 or later. The Deployment Target doesn't matter.
If you also want to build this code with Xcode 5 or earlier (a Base SDK of iOS 7 or earlier) then you need to wrap the code with the proper compiler directives to check for the Base SDK.