|
|
@@ -32,7 +32,7 @@ Just drop the **Reachability.swift** file into your project. That's it!
|
|
|
## Example - closures
|
|
|
|
|
|
````
|
|
|
- let reachability: Reachability?
|
|
|
+ let reachability: Reachability
|
|
|
do {
|
|
|
reachability = try Reachability.reachabilityForInternetConnection()
|
|
|
} catch {
|
|
|
@@ -41,7 +41,7 @@ Just drop the **Reachability.swift** file into your project. That's it!
|
|
|
}
|
|
|
|
|
|
|
|
|
- reachability!.whenReachable = { reachability in
|
|
|
+ reachability.whenReachable = { reachability in
|
|
|
// this is called on a background thread, but UI updates must
|
|
|
// be on the main thread, like this:
|
|
|
dispatch_async(dispatch_get_main_queue()) {
|
|
|
@@ -52,7 +52,7 @@ Just drop the **Reachability.swift** file into your project. That's it!
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- reachability!.whenUnreachable = { reachability in
|
|
|
+ reachability.whenUnreachable = { reachability in
|
|
|
// this is called on a background thread, but UI updates must
|
|
|
// be on the main thread, like this:
|
|
|
dispatch_async(dispatch_get_main_queue()) {
|
|
|
@@ -61,7 +61,7 @@ Just drop the **Reachability.swift** file into your project. That's it!
|
|
|
}
|
|
|
|
|
|
do {
|
|
|
- try reachability!.startNotifier()
|
|
|
+ try reachability.startNotifier()
|
|
|
} catch {
|
|
|
print(\"Unable to start notifier")
|
|
|
}
|
|
|
@@ -71,7 +71,7 @@ Just drop the **Reachability.swift** file into your project. That's it!
|
|
|
and for stopping notifications
|
|
|
|
|
|
````
|
|
|
-reachability?.stopNotifier()
|
|
|
+reachability.stopNotifier()
|
|
|
````
|
|
|
|
|
|
## Example - notifications
|
|
|
@@ -79,7 +79,7 @@ reachability?.stopNotifier()
|
|
|
This sample will use `NSNotification`s to notify when the interface has changed. They will be delivered on the **MAIN THREAD**, so you *can* do UI updates from within the function.
|
|
|
|
|
|
````
|
|
|
- let reachability: Reachability?
|
|
|
+ let reachability: Reachability
|
|
|
do {
|
|
|
reachability = try Reachability.reachabilityForInternetConnection()
|
|
|
} catch {
|
|
|
@@ -90,9 +90,9 @@ This sample will use `NSNotification`s to notify when the interface has changed.
|
|
|
NSNotificationCenter.defaultCenter().addObserver(self,
|
|
|
selector: "reachabilityChanged:",
|
|
|
name: ReachabilityChangedNotification,
|
|
|
- object: reachability!)
|
|
|
+ object: reachability)
|
|
|
|
|
|
- reachability!.startNotifier()
|
|
|
+ reachability.startNotifier()
|
|
|
````
|
|
|
|
|
|
and
|
|
|
@@ -117,10 +117,10 @@ and
|
|
|
and for stopping notifications
|
|
|
|
|
|
````
|
|
|
-reachability!.stopNotifier()
|
|
|
+reachability.stopNotifier()
|
|
|
NSNotificationCenter.defaultCenter().removeObserver(self,
|
|
|
name: ReachabilityChangedNotification,
|
|
|
- object: reachability!)
|
|
|
+ object: reachability)
|
|
|
````
|
|
|
|
|
|
## Want to help?
|