I am trying to convert my reachability function. After bridging Objective-c .h and .m file. Now I a have a function that I call to check in reachability in Objective-C that I want to convert in swift here is the code in 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 {
}
I call this function in Objective-C like this
[self reachabilityCheck];
I also written TryCatch in C and also included in bridge header. My function with try catch now looks like this
func reachabiltyCheck()
{
TryCatch.try({
// try something
}, catch: { (error) in
println("\(error.description)")
}, finally: {
// close resources
})
}
Now at the first line in Reachability *__autoreleasing reach = [Reachability reachabilityForInternetConnection];
I don't know how to convert that in swift and also what *_autorealeasing
means here ?
Edit 1 If I make function like this it gives me error
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
})
if I print b value it prints (Enum Value)
what is the problem ?