The contents described in Objective-C have been ported to Swift.
I am not sure what to do with nil in Objective-C on Swift, so I have a question.
How should I write Swift in the following way?
MTLRenderPassDescriptor*testPassDescriptor=view.currentRenderPassDescriptor;
if(testPassDescriptor!=nil){
NNSAssert(@"error:%@", error);
}
Thank you for correcting your question.However, since you didn't write anything meaningful in the most important if, I can't say exactly how to write it or how to write it.
The Optional type mentioned in the comment is valid, so you can write it in the same way as Objective-C.
let testPassDescriptor=view.currentRenderPassDescriptor
if testPassDescriptor!=nil{
//...
}
(I omitted NNSert because it doesn't make sense at all because it uses the variable error
that I don't know how to use it and doesn't appear anywhere.)
© 2024 OneMinuteCode. All rights reserved.