[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-6752":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":16,"stars7d":17,"stars30d":17,"stars90d":16,"forks30d":16,"starsTrendScore":16,"compositeScore":18,"rankGlobal":10,"rankLanguage":10,"license":19,"archived":20,"fork":20,"defaultBranch":21,"hasWiki":22,"hasPages":20,"topics":23,"createdAt":10,"pushedAt":10,"updatedAt":24,"readmeContent":25,"aiSummary":26,"trendingCount":16,"starSnapshotCount":16,"syncStatus":27,"lastSyncTime":28,"discoverSource":29},6752,"Reachability.swift","ashleymills\u002FReachability.swift","ashleymills","Replacement for Apple's Reachability re-written in Swift with closures","",null,"Swift",7975,947,113,84,0,1,39.93,"MIT License",false,"master",true,[],"2026-06-12 02:01:29","# Reachability.swift\n\nReachability.swift is a replacement for Apple's Reachability sample, re-written in Swift with closures.\n\nIt is compatible with **iOS** (8.0 - 12.0), **OSX** (10.9 - 10.14) and **tvOS** (9.0 - 12.0)\n\nInspired by https:\u002F\u002Fgithub.com\u002Ftonymillion\u002FReachability\n\n## Supporting **Reachability.swift**\nKeeping **Reachability.swift** up-to-date is a time consuming task. Making updates, reviewing pull requests, responding to issues and answering emails all take time. \n\nPlease consider sponsoring me https:\u002F\u002Fgithub.com\u002Fsponsors\u002Fashleymills, it's a great way to say thanks!\n\nIf you're an iOS developer who's looking for a quick and easy way to create App Store screenshots, please try out my app [Screenshot Producer](https:\u002F\u002Fitunes.apple.com\u002Fapp\u002Fapple-store\u002Fid1252374855?pt=215893&ct=reachability&mt=8)…\n\n Devices | Layout | Copy | Localize | Export      \n:------:|:------:|:------:|:------:|:------:\n![](http:\u002F\u002Fis2.mzstatic.com\u002Fimage\u002Fthumb\u002FPurple118\u002Fv4\u002F64\u002Faf\u002F55\u002F64af55bc-2ef0-691c-f5f3-4963685f7f63\u002Fsource\u002F552x414bb.jpg) |  ![](http:\u002F\u002Fis4.mzstatic.com\u002Fimage\u002Fthumb\u002FPurple128\u002Fv4\u002Ffb\u002F4c\u002Fbd\u002Ffb4cbd2f-dd04-22ba-4fdf-5ac652693fb8\u002Fsource\u002F552x414bb.jpg) |  ![](http:\u002F\u002Fis1.mzstatic.com\u002Fimage\u002Fthumb\u002FPurple118\u002Fv4\u002F5a\u002F4f\u002Fcf\u002F5a4fcfdf-ca04-0307-9f2e-83178e8ad90d\u002Fsource\u002F552x414bb.jpg) |  ![](http:\u002F\u002Fis4.mzstatic.com\u002Fimage\u002Fthumb\u002FPurple128\u002Fv4\u002F17\u002Fea\u002F56\u002F17ea562e-e045-96e7-fcac-cfaaf4f499fd\u002Fsource\u002F552x414bb.jpg) |  ![](http:\u002F\u002Fis4.mzstatic.com\u002Fimage\u002Fthumb\u002FPurple118\u002Fv4\u002F59\u002F9e\u002Fdd\u002F599edd50-f05c-f413-8e88-e614731fd828\u002Fsource\u002F552x414bb.jpg)\n\nAnd don't forget to **★** the repo. This increases its visibility and encourages others to contribute.\n\nThanks\nAsh\n\n\n## Got a problem?\n\nPlease read https:\u002F\u002Fgithub.com\u002Fashleymills\u002FReachability.swift\u002Fblob\u002Fmaster\u002FCONTRIBUTING.md before raising an issue.\n\n## Installation\n### Manual\nJust drop the **Reachability.swift** file into your project. That's it!\n\n### CocoaPods\n[CocoaPods][] is a dependency manager for Cocoa projects. To install Reachability.swift with CocoaPods:\n\n 1. Make sure CocoaPods is [installed][CocoaPods Installation].\n\n 2. Update your Podfile to include the following:\n\n    ``` ruby\n    use_frameworks!\n    pod 'ReachabilitySwift'\n    ```\n\n 3. Run `pod install`.\n\n[CocoaPods]: https:\u002F\u002Fcocoapods.org\n[CocoaPods Installation]: https:\u002F\u002Fguides.cocoapods.org\u002Fusing\u002Fgetting-started.html#getting-started\n \n 4. In your code import Reachability like so:\n   `import Reachability`\n\n### Carthage\n[Carthage][] is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.\nTo install Reachability.swift with Carthage:\n\n1. Install Carthage via [Homebrew][]\n  ```bash\n  $ brew update\n  $ brew install carthage\n  ```\n\n2. Add `github \"ashleymills\u002FReachability.swift\"` to your Cartfile.\n\n3. Run `carthage update`.\n\n4. Drag `Reachability.framework` from the `Carthage\u002FBuild\u002FiOS\u002F` directory to the `Linked Frameworks and Libraries` section of your Xcode project’s `General` settings.\n\n5. Add `$(SRCROOT)\u002FCarthage\u002FBuild\u002FiOS\u002FReachability.framework` to `Input Files` of Run Script Phase for Carthage.\n\n6. In your code import Reachability like so:\n`import Reachability`\n\n\n[Carthage]: https:\u002F\u002Fgithub.com\u002FCarthage\u002FCarthage\n[Homebrew]: http:\u002F\u002Fbrew.sh\n[Photo Flipper]: https:\u002F\u002Fitunes.apple.com\u002Fapp\u002Fapple-store\u002Fid749627884?pt=215893&ct=GitHubReachability&mt=8\n\n### Swift Package Manager (SPM)\nThe Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler. To integrate using Apple's Swift package manager from xcode :\n\n1. File -> Swift Packages -> Add Package Dependency...\n\n2. Enter package URL : https:\u002F\u002Fgithub.com\u002Fashleymills\u002FReachability.swift, choose the latest release\n\n## Example - closures\n\nNOTE: All closures are run on the **main queue**.\n\n```swift\n\u002F\u002Fdeclare this property where it won't go out of scope relative to your listener\nlet reachability = try! Reachability()\n\nreachability.whenReachable = { reachability in\n    if reachability.connection == .wifi {\n        print(\"Reachable via WiFi\")\n    } else {\n        print(\"Reachable via Cellular\")\n    }\n}\nreachability.whenUnreachable = { _ in\n    print(\"Not reachable\")\n}\n\ndo {\n    try reachability.startNotifier()\n} catch {\n    print(\"Unable to start notifier\")\n}\n```\n\nand for stopping notifications\n\n```swift\nreachability.stopNotifier()\n```\n\n## Example - notifications\n\nNOTE: All notifications are delivered on the **main queue**.\n\n```swift\n\u002F\u002Fdeclare this property where it won't go out of scope relative to your listener\nlet reachability = try! Reachability()\n\n\u002F\u002Fdeclare this inside of viewWillAppear\n\n     NotificationCenter.default.addObserver(self, selector: #selector(reachabilityChanged(note:)), name: .reachabilityChanged, object: reachability)\n    do{\n      try reachability.startNotifier()\n    }catch{\n      print(\"could not start reachability notifier\")\n    }\n```\n\nand\n\n```swift\n@objc func reachabilityChanged(note: Notification) {\n\n  let reachability = note.object as! Reachability\n\n  switch reachability.connection {\n  case .wifi:\n      print(\"Reachable via WiFi\")\n  case .cellular:\n      print(\"Reachable via Cellular\")\n  case .unavailable:\n    print(\"Network not reachable\")\n  }\n}\n```\n\nand for stopping notifications\n\n```swift\nreachability.stopNotifier()\nNotificationCenter.default.removeObserver(self, name: .reachabilityChanged, object: reachability)\n```\n\n## Want to help?\n\nGot a bug fix, or a new feature? Create a pull request and go for it!\n\n## Let me know!\n\nIf you use **Reachability.swift**, please let me know about your app and I'll put a link [here…](https:\u002F\u002Fgithub.com\u002Fashleymills\u002FReachability.swift\u002Fwiki\u002FApps-using-Reachability.swift) and tell your friends!\n\nCheers,\nAsh\n","Reachability.swift 是一个用 Swift 语言重写的网络可达性检测库，替代了苹果官方的 Reachability 示例，并使用闭包来处理网络状态变化。其核心功能包括监测设备的网络连接状态（如Wi-Fi、蜂窝数据等），并能在网络状态发生变化时通过闭包回调通知开发者。该库支持iOS 8.0 - 12.0, macOS 10.9 - 10.14, 以及 tvOS 9.0 - 12.0平台，具有良好的跨平台兼容性。适用于需要实时监控网络状况的应用场景，比如确保应用在网络条件不佳时不执行敏感操作或提供用户友好的提示信息。安装方式多样，支持手动添加文件、CocoaPods和Carthage等多种集成方法。",2,"2026-06-11 03:08:42","top_language"]