我是Bash的全新人,但我似乎无法找到一种方法让它做我想做的事.
想象一下,你有一个包含2个文件的树目录:/top.php和/test/bottom.php
如何使我的函数看起来并替换在/top.php和/test/bottom.php中将"hello"改为"bonjour"?
到目前为止,我发现这样做的唯一方法是使用不同的深度级别调用相同的函数两次:
find ./*.php -type f -exec sed -i 's/hello/bonjour/' {} \;
find ./*/*.php -type f -exec sed -i 's/hello/bonjour/' {} \;
Run Code Online (Sandbox Code Playgroud)
当然有一种递归的方式在一行中做到这一点?
我有一个附加了UITapGestureRecognizer的自定义UIView.手势识别器调用一个名为hide()的方法来从superview中删除视图:
func hide(sender:UITapGestureRecognizer){
if let customView = sender.view as? UICustomView{
customView.removeFromSuperview()
}
}
Run Code Online (Sandbox Code Playgroud)
UICustomView还有一个show()方法,可以将其添加为子视图,如下所示:
func show(){
// Get the top view controller
let rootViewController: UIViewController = UIApplication.sharedApplication().windows[0].rootViewController!!
// Add self to it as a subview
rootViewController.view.addSubview(self)
}
Run Code Online (Sandbox Code Playgroud)
这意味着我可以创建一个UICustomView并将其显示为:
let testView = UICustomView(frame:frame)
testView.show() // The view appears on the screen as it should and disappears when tapped
Run Code Online (Sandbox Code Playgroud)
现在,我想将show()方法转换为一个带有完成块的方法,该方法在触发hide()函数时调用.就像是:
testView.show(){ success in
println(success) // The view has been hidden
}
Run Code Online (Sandbox Code Playgroud)
但要这样做,我将不得不从hide()方法调用show()方法的完成处理程序.这可能还是我忽略了什么?