Catch Objective-C exception in Swift

前端 未结 4 1552
日久生厌
日久生厌 2021-02-07 10:56

I am trying to set the value of an @objc object in my Swift code using obj.setValue(value, forKey: key).

It works fine when the object has the

4条回答
  •  长发绾君心
    2021-02-07 11:59

    see this answer:

    //
    //  ExceptionCatcher.h
    //
    
    #import     
    
    NS_INLINE NSException * _Nullable tryBlock(void(^_Nonnull tryBlock)(void)) {
        @try {
            tryBlock();
        }
        @catch (NSException *exception) {
            return exception;
        }
        return nil;
    }
    

提交回复
热议问题