Skip to content

Instantly share code, notes, and snippets.

@acalism
Created January 26, 2018 09:17
Show Gist options
  • Save acalism/aa7f6dba4254f2d46ae1225b0dc70a51 to your computer and use it in GitHub Desktop.
Save acalism/aa7f6dba4254f2d46ae1225b0dc70a51 to your computer and use it in GitHub Desktop.
// 这两个方法有冲突(调用时无法区分),除非其中一个去掉IndexPath后的问号
/// 不能有默认参数 nil,因为inout不能操作常量
func shouldChange(indexPath: inout IndexPath?) -> Bool {
indexPath = IndexPath(item: 0, section: 1)
return true
}
/// 可以有默认参数 nil,
func shouldChange(indexPath: UnsafeMutablePointer<IndexPath?>? = nil) -> Bool {
indexPath?.pointee = IndexPath(item: 0, section: 0)
return false
}
var ip: IndexPath?
let should = shouldChange(indexPath: &ip)
if let i = ip {
print(i, should)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment