SecIdentity + Force Cast Violation: Force casts should be avoided. (force_cast)
Basically, what you're doing is a force downcast, meaning that you guarantee that yours identityPointer
and trustPointer
are objects of SecIdentity
and SecTrust
classes respectively. But what if they are not? You take them out of the dictionary as AnyObject
, so generally they may not cast to the target classes. Swiftlint tells you, that force casting is a bad practise and wants you to avoid it.
However, it seems with CoreFoundation type you can't use a conditional cast as?
, so force cast is your only choice. For this particular case you can disable Swiftlint rule in code adding a special comment.
let secIdentityRef = identityPointer as! SecIdentity // swiftlint:disable:this force_cast
To be on the safe side, you also may check the identity of the object by checking the Core Foundation "type id":
guard let identityPointer = certEntry["identity"],
CFGetTypeID(identityPointer) == SecIdentityGetTypeID() else {
// here you know that the cast will fail
}
let secIdentityRef = identityPointer as! SecIdentity // swiftlint:disable:this force_cast
Which YCbCr matrix to use? BT.709 or BT.601
Using takeUnretainedValue() will give you a CFTypeRef
. This then needs to be downcast to a CFString
. For example, your code could look like this:
if let colorAttachment = CVBufferGetAttachment(image, kCVImageBufferYCbCrMatrixKey, nil)?.takeUnretainedValue(),
CFGetTypeID(colorAttachment) == CFStringGetTypeID() {
let colorAttachmentString = colorAttachment as! CFString
print(colorAttachmentString)
print(colorAttachmentString == kCVImageBufferYCbCrMatrix_ITU_R_601_4)
print(colorAttachmentString == kCVImageBufferYCbCrMatrix_ITU_R_709_2)
}
Which prints:
ITU_R_601_4
true
false
Related Topics
Bool.Hashvalue Valid to Convert to Int
Adding Constraints Programmatically in UIview with UItextview
#If Canimport(Coreimage) Not Working in Swift Package Manager
iOS-Charts Error: Thread1: Exc_Bad_Access (Code=2, Address=0X2A0C220)
3 Component Dynamic Multi UIpickerview Swift
I Opened My App in Xcode 10 and Now I Have Errors in 9.4.1: Sdkapplicationdelegate (Facebookcore)
How to Prevent SQL Injections with User-Search-Terms in Vapor 4 (Fluent 4)
How to Set Default Clouse Param in View Method
How to Pause an Animation in Swiftui
Compiling for iOS 10.3, But Module 'swiftuicharts' Has a Minimum Deployment Target of iOS 13.0
Swift: Simple Dispatchqueue Does Not Run & Notify Correctly
Swift Set UIbutton Setbordercolor in Storyboard
3 Component Dynamic Multi UIpickerview Swift
How to Use Gpx File for UI Tests Only
How to Query Firebase Data Childbyautoid
How to Dynamically Hide Navigation Back Button in Swiftui
Argument of '#Selector' Does Not Refer to an '@Objc' Method (Swift 3)