我不太清楚有关使用完成处理程序创建自定义函数的语法及其用法。
下面是我编写的用于绘制UIBezier路径的函数。我希望此函数返回一个UIbezierpath,以馈入完成处理程序。我写的正确吗?我希望完成处理程序不返回任何内容。
基于下面的代码,我的“ returnedPath”是我随后可以使用的RETURNED UIbezierpath?
自定义功能的实现:
outlineImageBorderWithBezierPath(topLeft: tl, topRight: tr, bottomRight: br, bottomLeft: bl) { (returnedPath) in
}
func outlineImageBorderWithBezierPath(topLeft: CGPoint, topRight: CGPoint, bottomRight: CGPoint, bottomLeft: CGPoint, completion: (UIBezierPath) -> ()) -> UIBezierPath{
let path = UIBezierPath()
path.move(to: topLeft)
path.addLine(to: topRight)
path.addLine(to: bottomRight)
path.addLine(to: bottomLeft)
path.addLine(to: topLeft)
path.close()
return path
}
答案 0 :(得分:0)
仅当函数内部的任务异步并且因此outlineImageBorderWithBezierPath
中的代码不是不需要完成的情况下才应使用完成,
let path = outlineImageBorderWithBezierPath(topLeft: tl, topRight: tr, bottomRight: br, bottomLeft: bl)
func outlineImageBorderWithBezierPath(topLeft: CGPoint, topRight: CGPoint, bottomRight: CGPoint, bottomLeft: CGPoint) -> UIBezierPath {
let path = UIBezierPath()
path.move(to: topLeft)
path.addLine(to: topRight)
path.addLine(to: bottomRight)
path.addLine(to: bottomLeft)
path.addLine(to: topLeft)
path.close()
return path
}