gpt4 book ai didi

Swift 标记 : Callback argument breaks documentation string

转载 作者:行者123 更新时间:2023-12-03 21:25:01 29 4
gpt4 key购买 nike

我正在使用 Swift Markup Language记录类方法。一切正常,但是,这里有一个微妙的问题。

下面列出了一些示例来解释我所问的问题。

1) 一切正常

/// My Fancy Method.
///
/// - Parameter number: A number.
/// - Parameter flag: A flag.
func methodWithoutCallback(integer number: Int, boolean flag: Bool) {

}

enter image description here

2) 还不错
/// A method with callback (no arguments).
///
/// - Parameter string: A string.
/// - Parameter callback: A callback without arguments.
func methodWithVoidCallback(string name: String, _ callback: () -> ()) {

}

enter image description here

3) 不完全符合我的预期
/// This time things go wrong...
///
/// - Parameter number: A number.
/// - Parameter callback: Why there is a box with "No description" below?
func methodWithIntCallback(floating number: Float, _ callback: (Int) -> ()) {

}

enter image description here

4) 使用 typealias 会删除那个东西
typealias Callback = (Int) -> ()
/// And, there is a way to repair, but need typealias
///
/// - Parameter number: A number.
/// - Parameter callback: A callback (no box below)
func methodWithTypealiasedIntCallback(floating number: Float, _ callback: Callback) {

}

enter image description here

有人有这个问题吗?或者这是一种预期的行为?使用 时出现问题Xcode 9.2 (9C40b) swift 4 (如果重要的话)。

UPDATE: Seems to be a duplicate of this question. But I wanted to clarify then: there is no way to ignore that box altogether, right? Because here is what you're getting if using proposed approach:


/// So, the box is coming up.
func methodWithCallbackParameterAnnotated(_ callback: (_ value: Int) -> Int) {

}

enter image description here

最佳答案

您还需要在回调中定义所有参数,位于 相同的缩进级别

/**
The box now has a description

- Parameters:
- callback: (Int) -> Int, I just like to define the type of callback here
- value: Here is where you describe the value param of the callback

*/
func methodWithCallbackParameterAnnotated(callback: (_ value: Int) -> Int) {

}

enter image description here

关于Swift 标记 : Callback argument breaks documentation string,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48824386/

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