<feed xmlns="http://www.w3.org/2005/Atom"> <id>https://www.codeswift.top/</id><title>CodeSwift</title><subtitle>让编程成为一种乐趣</subtitle> <updated>2025-08-19T14:08:49+08:00</updated> <author> <name>CodeSwift</name> <uri>https://www.codeswift.top/</uri> </author><link rel="self" type="application/atom+xml" href="https://www.codeswift.top/feed.xml"/><link rel="alternate" type="text/html" hreflang="zh-CN" href="https://www.codeswift.top/"/> <generator uri="https://jekyllrb.com/" version="4.4.1">Jekyll</generator> <rights> © 2025 CodeSwift </rights> <icon>/assets/img/favicons/favicon.ico</icon> <logo>/assets/img/favicons/favicon-96x96.png</logo> <entry><title>Apple Network 框架新旧 API 对比</title><link href="https://www.codeswift.top/posts/network-compare/" rel="alternate" type="text/html" title="Apple Network 框架新旧 API 对比" /><published>2025-08-19T14:06:38+08:00</published> <updated>2025-08-19T14:06:38+08:00</updated> <id>https://www.codeswift.top/posts/network-compare/</id> <content type="text/html" src="https://www.codeswift.top/posts/network-compare/" /> <author> <name>CodeSwift</name> </author> <category term="Swift" /> <category term="Network" /> <summary>1. 新旧 Network API 设计差异 Apple 在 2018 年引入了 Network.framework（iOS 12+/macOS 10.14+），提供了如 NWConnection、NWListener、NWBrowser 等类，用于建立网络连接、监听端口和浏览网络服务。这套旧 API 采用 NW 前缀，以面向对象和基于闭包回调的方式工作。例如，NWConnection 通过回调 (stateUpdateHandler 等) 通知状态变化，通过提供闭包的 receive 方法获取数据。开发者需要手动调用 start(queue:) 来启动连接，并在相应的 Dispatch 队列上处理异步事件。 在 iOS/iPadOS/macOS 26（WWDC 2025 发布的系统）中，Apple 为 Network.framework 重新设计了一套 API，引入了 Netw...</summary> </entry> <entry><title>基于 Apple Network Framework 的现代网络开发（iOS / macOS 26）</title><link href="https://www.codeswift.top/posts/apple-network-26/" rel="alternate" type="text/html" title="基于 Apple Network Framework 的现代网络开发（iOS / macOS 26）" /><published>2025-08-19T13:27:38+08:00</published> <updated>2025-08-19T13:27:38+08:00</updated> <id>https://www.codeswift.top/posts/apple-network-26/</id> <content type="text/html" src="https://www.codeswift.top/posts/apple-network-26/" /> <author> <name>CodeSwift</name> </author> <category term="Swift" /> <category term="Network" /> <summary>Apple 的 Network 框架已经发展为一个统一的、对 Swift 友好的工具包，用于在应用中构建安全、高性能的网络功能——无需 BSD 套接字的样板代码和陷阱。本文总结了 iOS 和 macOS 26 引入的新 API 与模式，提供完整代码示例，并解释它们如何与 Swift 的结构化并发模型相契合。 1. 为什么选择 Network Framework？ 按名称连接 &amp;amp; Happy Eyeballs – 自动 DNS 解析与智能 IPv4/IPv6 竞速。 内置 TLS – 无需外部 SSL 库即可实现端到端加密。 移动性与代理支持 – 无缝的网络接口切换（如 Wi-Fi Assist、多路径）。 现代传输协议 – 原生支持 QUIC，此外还有 TCP/UDP。 可组合协议栈 – 以声明式方式叠加 TLS、TLV、Coder 等。 W...</summary> </entry> </feed>
