In Objective-C, we can declare a function like this:
- (void)getRect:(CGRect *)aRectRef bRect:(CGRect *)bRectRef
{
if (aRectRef) *aRectRef = CGRectZero
if (bRectRef) *bRectRef = CGRectZero
}
and pass NULL
to the function:
CGRect rect;
[self getRect:NULL bRect:rect]
There isn't NULL
in Swift. I can't use nil
as inout param directly either:
func getRect(aRect aRectRef: inout CGRect?, bRect bRectRef: inout CGRect?) -> Void {
...
}
self.getRect(&nil, bRect: rect) // <- ERROR
I must define a variable with nil value and pass it to the function, even though I don't need the variable totally.
How to pass nil
to the function?
UPDATE:
null / nil in swift language just explained nil
in Swift.
Swift optional inout parameters and nil explained how to define a variable with nil value and pass it as inout parameter.
I want to know there is a way to pass nil directly like &nil
to function or not.