Information on how to write to Swift like Objective-C if(test!=nil)

Asked 2 years ago, Updated 2 years ago, 424 views

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);
}

swift ios

2022-09-30 21:56

1 Answers

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.)


2022-09-30 21:56

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.