【发布时间】:2015-05-10 14:46:12
【问题描述】:
我正在尝试转换我的可达性功能。桥接 Objective-c .h 和 .m 文件后。现在我有一个函数,我调用它来检查 Objective-C 中的可达性,我想快速转换这里是 Objective-C 中的代码
-(void)reachabilityCheck
{
@try {
Reachability *__autoreleasing reach = [Reachability reachabilityForInternetConnection];
if (reach.currentReachabilityStatus) {
self.isReachable = YES;
}
else
{
self.isReachable = NO;
}
}
@catch (NSException *exception) {
//// [Global writeToLogFile:[exception description]];
}
@finally {
}
我在 Objective-C 中这样调用这个函数
[self reachabilityCheck];
我还用 C 语言编写了 TryCatch,也包含在桥头中。我的 try catch 函数现在看起来像这样
func reachabiltyCheck()
{
TryCatch.try({
// try something
}, catch: { (error) in
println("\(error.description)")
}, finally: {
// close resources
})
}
现在在Reachability *__autoreleasing reach = [Reachability reachabilityForInternetConnection]; 的第一行,我不知道如何快速转换它以及*_autorealeasing 在这里的含义?
编辑 1 如果我制作这样的函数,它会给我错误
func reachabiltyCheck()
{
TryCatch.try({
// try something
var reach: Reachability = Reachability.reachabilityForInternetConnection();
var b = reach.currentReachabilityStatus();
if(b) // Error : Type 'NetworkStatus' does not conform to protocol 'BooleanType'
{
self.isReachable = Yes;
}
else
{
self.isReachable = Yes;
}
}, catch: { (error) in
println("\(error.description)")
}, finally: {
// close resources
})
如果我打印 b 值,它会打印 (Enum Value) 有什么问题?
【问题讨论】:
标签: ios objective-c swift