小编sma*_*8dd的帖子

是否可以使用"try?"在guard-statement中检索异常?

在swift中,如果进入else块,是否可以使用short guard let try? 获取发生的异常?

guard let smth = try? myThrowingFunc() else {
    print(error) //can I access the exception here somehow?
    return
}
Run Code Online (Sandbox Code Playgroud)

VS

let smth: AnyObject?
do {
    smth = try myThrowingFunc()
} catch let error {
    print(error)
    return
}
Run Code Online (Sandbox Code Playgroud)

exception try-catch guard swift

10
推荐指数
1
解决办法
2134
查看次数

是否有可能在Swift中捕获NSInternalInconsistencyException?

是否有可能在Swift中捕获NSInternalInconsistencyException?如果是的话,怎么办呢?

exception swift

10
推荐指数
1
解决办法
1223
查看次数

"警告:尝试在*上显示*已经呈现*"的断点

有时会发生这种情况 - 从代码中的不同位置 - 我们想要做的UIViewController.presentViewController(a, b, c),有时我们已经提出了这种情况,在这种情况下我们得到:

Warning: Attempt to present * on * which is already presenting *

有可能打破这个警告吗?我该如何为此设置断点?

breakpoints objective-c uiviewcontroller ios swift

7
推荐指数
1
解决办法
748
查看次数

C++继承方法但返回类型错误(自动转换?typeid(*this)?)

我有一个BaseClass,其方法返回一个类对象,我有一个DerivedClass.现在,当我有一个DerivedClass对象并调用BaseClass中定义的方法时,返回值是ob类型BaseClass,遗憾的是不是DerivedClass类型.

class BaseClass {
public:
  typeof(*this) myMethod1() {return *this;} // nice if that would work
  BaseClass& myMethod2() {return *this;}
  BaseClass myMethod3() {return BaseClass();}
};
class DerivedClass : public BaseClass {};

DerivedClass tmp;
tmp.myMethod1();
tmp.myMethod2();
tmp.myMethod3();
// all three methods should return an object of type DerivedClass,
// but really they return an object of type BaseClass
Run Code Online (Sandbox Code Playgroud)

所以我希望实现的是使用超类的方法,但是使用派生类的返回类型(自动转换?).myMethod1()是我唯一能想到的,但它不起作用.

我搜索过但没有找到任何令人满意的东西.

c++ inheritance casting return return-type

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