gpt4 book ai didi

ios - Swifter项目中的?? =运算符是什么

转载 作者:行者123 更新时间:2023-12-01 15:57:28 25 4
gpt4 key购买 nike

我已经在GitHub的Swifter库的源代码中看到了一个运算符??=,但没有人在谈论此运算符及其功能...这个运算符位于SwifterFollowers.swift Line 89.源文件下

此文件的代码段:

func getUserFollowersIDs(for userTag: UserTag,
cursor: String? = nil,
count: Int? = nil,
success: CursorSuccessHandler? = nil,
failure: FailureHandler? = nil) {
let path = "followers/ids.json"

var parameters = [String: Any]()
parameters[userTag.key] = userTag.value
parameters["cursor"] ??= cursor /* --- Here --- */
parameters["stringify_ids"] = true
parameters["count"] ??= count

self.getJSON(path: path, baseURL: .api, parameters: parameters, success: { json, _ in
success?(json["ids"], json["previous_cursor_str"].string, json["next_cursor_str"].string)
}, failure: failure)
}

最佳答案

我在Operator++文件中发现了开发人员创建的??=

然后,此运算符仅在Swifter项目中工作,这是逻辑:

/// If `rhs` is not `nil`, assign it to `lhs`.
infix operator ??= : AssignmentPrecedence // { associativity right precedence 90 assignment } // matches other assignment operators

/// If `rhs` is not `nil`, assign it to `lhs`.
func ??=<T>(lhs: inout T?, rhs: T?) {
guard let rhs = rhs else { return }
lhs = rhs
}

关于ios - Swifter项目中的?? =运算符是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59285594/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com