本文介绍了迅捷-可选的虚空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正忙于使用NSURLProtocolClient的URLProtocol函数:

I was busy using NSURLProtocolClient's URLProtocol function:

welf?.client?.URLProtocol(welf!, didReceiveResponse: operation.response, cacheStoragePolicy: NSURLCacheStoragePolicy.NotAllowed)

我期望它返回Void.但令我惊讶的是,它返回Void?

I was expecting it to return Void. But to my surprise it returns Void?

为什么必须区分VoidVoid?

我已经阅读到Void是空元组类型的类型别名.那么,这与空元组类型与nil之间有区别吗?

I have read that Void is a type alias for the empty tuple type. So, does this have something to do with a distinction between the empty tuple type vs nil?

推荐答案

这仅仅是因为您使用的是.该方法返回Void,但是整个链有可能在调用该方法之前返回nil.

This is simply because you are using Optional Chaining. The method returns Void, but it is possible for the whole chain to return nil before the method is ever called.

从本质上讲,返回值Void表示实际上已进行了调用(自身和客户端均具有值),而nil结果表示其中之一为nil.

Essentially, a return value of Void will mean the call was actually made (self and client both have values) while a nil result will mean that one of those were nil.

这篇关于迅捷-可选的虚空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 20:33