在其他语言(如C或Java)中,如果我想停止执行一个方法并返回一个我喜欢的值:
@IBAction func button_1(sender: AnyObject) {
if a == b
{
// Do something ...
/* I want to stop here but I don't know how */
}
// Do something else
}
如果是swift,我为按钮指定一个动作
SELECT
p.pub_name
FROM
publishers p
WHERE
p.pub_id IN (SELECT pub_id FROM titles t WHERE t.category = 'psychology)
如何停止在Action中执行脚本? 感谢。
答案 0 :(得分:3)
不确定您遇到了什么问题......您可以使用---Has type template bar---
consists_no_bar: false
consists_alias: false
consists_struct: false
consists_class: false
consists_union: false
consists_variable: false
consists_function: false
consists_overloaded_func: false
consists_reference: false
consists_t_alias: true
consists_t_struct: true
consists_t_class: true
consists_t_union: true
consists_t_variable: false
consists_t_function: false
consists_t_overloaded_function: false
consists_s_variable: false
consists_s_function: false
consists_s_overloaded_func: false
consists_s_t_function: false
consists_s_t_overloaded_function: false
--Has member function template bar---
consists_no_bar: false
consists_alias: false
consists_struct: false
consists_class: false
consists_union: false
consists_variable: false
consists_function: false
consists_overloaded_func: true // implmementation bug
consists_reference: false
consists_t_alias: false
consists_t_struct: false
consists_t_class: false
consists_t_union: false
consists_t_variable: false
consists_t_function: true
consists_t_overloaded_function: true
consists_s_variable: false
consists_s_function: false
consists_s_overloaded_func: true // implmementation bug
consists_s_t_function: true
consists_s_t_overloaded_function: true
--Has member variable template bar---
consists_no_bar: false
consists_alias: false
consists_struct: false
consists_class: false
consists_union: false
consists_variable: false
consists_function: false
consists_overloaded_func: false
consists_reference: false
consists_t_alias: false
consists_t_struct: false
consists_t_class: false
consists_t_union: false
consists_t_variable: true
consists_t_function: false
consists_t_overloaded_function: false
consists_s_variable: false
consists_s_function: false
consists_s_overloaded_func: false
consists_s_t_function: false
consists_s_t_overloaded_function: false
--Has any member template bar---
consists_no_bar: false
consists_alias: false
consists_struct: false
consists_class: false
consists_union: false
consists_variable: false
consists_function: false
consists_overloaded_func: true // implmementation bug
consists_reference: false
consists_t_alias: true
consists_t_struct: true
consists_t_class: true
consists_t_union: true
consists_t_variable: true
consists_t_function: true
consists_t_overloaded_function: true
consists_s_variable: false
consists_s_function: false
consists_s_overloaded_func: true // implmementation bug
consists_s_t_function: true
consists_s_t_overloaded_function: true
就好了。
return
按预期工作。
答案 1 :(得分:0)
您可以在某些条件下使用return语句退出函数作用域,例如guard statment 例如:
@IBAction func SendAction(sender: UIButton) {
guard a != b else {
// Do something
return
}
// Do something else
}