Swift中的???(三重问号)运算符是否存在?
Swift中是否存在
???(三重问号)运算符? Hey there! Let me set things straight for you: Swift absolutely does not have a ??? (triple question mark) operator.
It’s super common to mix up or mishear operators, so there’s a good chance your interviewer might have been referring to Swift’s widely used ?? (nil-coalescing operator) instead. Here’s a quick recap of how that one works:
- The
??operator takes an optional value and a default value. If the optional has a non-nil value, it unwraps and returns that; if it’s nil, it returns the default value instead. - Example usage:
let username: String? = nil let displayName = username ?? "Guest" // displayName will be "Guest" since username is nil
Since the ??? operator doesn’t exist in Swift at all, that’s why you couldn’t find any relevant results when searching for it. No need to second-guess your own research here!
内容的提问来源于stack exchange,提问作者Ali Mehdi
相关产品推荐
相关产品推荐

