Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/113.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 泛型Objective-C类的扩展无法访问该类';s运行时的泛型参数_Ios_Swift_Exception_Swift4_Nsfetchedresultscontroller - Fatal编程技术网

Ios 泛型Objective-C类的扩展无法访问该类';s运行时的泛型参数

Ios 泛型Objective-C类的扩展无法访问该类';s运行时的泛型参数,ios,swift,exception,swift4,nsfetchedresultscontroller,Ios,Swift,Exception,Swift4,Nsfetchedresultscontroller,我有以下NSFetchedResultsController扩展名: extension NSFetchedResultsController { func tryObjectAtIndex(_ indexPath: IndexPath) throws -> AnyObject // ERROR HERE { do { try ObjC.catchException {

我有以下
NSFetchedResultsController
扩展名:

extension NSFetchedResultsController
{
    func tryObjectAtIndex(_ indexPath: IndexPath) throws -> AnyObject // ERROR HERE
    {
        do
        {
            try ObjC.catchException
            {
                return self.object(at: indexPath) // CAUSE
            }
        }
        catch
        {
            print("An error ocurred: \(error)")
        }
    }
}
其中,
ObjC
是一个Objective-C类(from)。这是
.h

#import <Foundation/Foundation.h>

@interface ObjC : NSObject

+ (BOOL)catchException:(void(^)())tryBlock error:(__autoreleasing NSError **)error;

@end
tryObjectAtIndex
出现泛型Objective-C类的错误
扩展无法在运行时访问该类的泛型参数

相关问题的唯一答案是建议在函数前面添加
@objc
。但是在上面的代码中,这没有任何区别

调用self.object(at:)
会导致此问题。但是实际上,没有Objective-C异常处理,因此只要
返回self.object(at:indexPath)
作为函数体,就不会发生错误

我如何解决这个问题


重要提示:我使用的是Xcode 8.3.2,目前无法更新(因为这是一个遗留项目)。

您可以改为使用子类吗?
@implementation ObjC

+ (BOOL)catchException:(void(^)())tryBlock error:(__autoreleasing NSError **)error
{
    @try
    {
        tryBlock();
        return YES;
    }
    @catch (NSException *exception)
    {
        *error = [[NSError alloc] initWithDomain:exception.name code:0 userInfo:exception.userInfo];
        return NO;
    }
}

@end