这是我用Objective-C编写的代码,现在我想把它放到Swift代码中。但我发现Swift并没有Class修饰符,它的AnyClass不是我需要的,我该怎么办?
+ (void)postJson:(ZYHttpRequest *)httpRequest resultClass:(Class)resultClass success:(void (^)(ZYBaseResult *result))success failure:(void (^)(NSError *error))failure
{
[self postJsonWithProgressHint:nil httpRequest:httpRequest resultClass:resultClass success:success failure:failure];
}
Typedef struct objc_class * ClassUse“Class”中的Objective-C可以承载类型,但是如何在Swift中编写?
上面的代码,用Swift编写,如何正确编写“resultClass:(Class)resultClass”?
答案 0 :(得分:0)
你可以这样做:
func postJson<T: AnyObject>(httpRequest: ZYHttpRequest, resultClass:T.Type, ...