我创建了一个带有完成处理程序的函数。有时我需要使用完成块,有时不需要。
这是函数:
func numberCheck(number: String , completion : @escaping (Bool)->()){
//some task do here
completion(true)
}
Run Code Online (Sandbox Code Playgroud)
用:
numberCheck(number: "77" , completion: {_ in
//some task do here
})
Run Code Online (Sandbox Code Playgroud)
但我想让它完成块为零:
numberCheck(number: "77" , completion: nil)
Run Code Online (Sandbox Code Playgroud)
但它给了我一个错误:
Nil 与预期的参数类型 '(Bool) -> ()' 不兼容
通常当我想设置我的行高然后设置
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 300
}
Run Code Online (Sandbox Code Playgroud)
我estimatedHeightForRowAt
应该什么时候使用它有什么好处。
更新!如果我想设置estimatedHeightForRowAt:
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
return // what should i put here
}
Run Code Online (Sandbox Code Playgroud)
更新:
如果我按照我的意愿提供estimatedHeightForRowAt,是否有任何效果表视图滚动?. 例如我给出了estimatedHeightForRowAt 500
我fetch
在swift中的API响应和解析pick url.但我需要检查图像网址或视频网址:
如果我得到图像网址然后显示图像,如果获得视频网址,然后播放视频:
if let url = postMedia?.url{
//need to check here
}
Run Code Online (Sandbox Code Playgroud)
例如
这是我的视频网址:
https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4
https://clips.vorwaerts-gmbh.de/big_buck_bunny.mov
这是图片网址:
https://clips.vorwaerts-gmbh.de/big_buck_bunny.png
https://clips.vorwaerts-gmbh.de/big_buck_bunny.jpg
注意:我知道如何显示图像和播放视频