小编cri*_*ka3的帖子

如何制作与 nil 兼容的完成处理程序?

我创建了一个带有完成处理程序的函数。有时我需要使用完成块,有时不需要。

这是函数:

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) -> ()' 不兼容

closures swift

3
推荐指数
1
解决办法
1932
查看次数

heightForRowAt 与estimatedHeightForRowAt 的区别是什么?

通常当我想设置我的行高然后设置

 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

uitableview ios swift

3
推荐指数
2
解决办法
5040
查看次数

如何查看网址是图片还是视频?

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

注意:我知道如何显示图像和播放视频

ios swift

2
推荐指数
2
解决办法
3473
查看次数

标签 统计

swift ×3

ios ×2

closures ×1

uitableview ×1