Swifter项目中的?? =运算符

问题描述 投票:0回答:1

[我已经在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)
}

我已经见过一个运算符?? =,它在GitHub的Swifter库的源代码中使用过,但是没有什么地方谈论此运算符及其功能...此运算符位于...中的源文件下]]] >>

[我发现开发人员在??=文件中创建了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 swift operator-keyword
1个回答
2
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.