Swift 在调用 super.init 之前必须初始化变量
Oct 10, 2022
先看一下踩坑的代码: public class MyView: UIView { private var count = 0 public init(count: Int) { super.init(frame: .zero) self.count = count } // 重写 setFrame 方法 override public var frame: CGRect { didSet { let w = frame.width * count } } } 以上示例中,count 属性是在 super.init(frame:) 之后才赋值, 但是由于重写了 frame 属性的 didSet 方法,而且在其中使用到了 count 属性, 这样就导致了一个隐含的 BUG:在初始化方法中触发的 frame 的 didSet 方法里使用的 count 属性的值是 0 而不是外部传进来的值。 …
C++ 11 中的原始字符串字面量(Raw String Literal)
Oct 09, 2022
C++ 11 开始增加了 UTF-16 和 UTF-32 字符串字面量,默认的字符串字面量是 UTF8,三种编码的写法如下: // UTF-8 const char *utf8_string = "abc"; const char *utf8_string2 = u8"abc"; // UTF-16 const char16_t *utf16_string = u"abc"; // UTF-32 const char32_t *utf32_string = U"abc"; 在字符字面量中,斜杠 \ 是转义字符,需要写为 \\ 的形式才能表示一个普通的斜杠,在写正则表达式的时候就特别不方便: …
Swift 5 ABI 和 Module 的稳定性
Oct 02, 2022
Swift 5.0 开始,实现了 ABI 稳定性,意味着同样的源码,即使是使用不同版本的 Swift 编译, 编译后的程序都可以在 Swift 5 Runime 下运行,而不需要要求目标环境的 Runtime 和开发环境一致。 …
macOS 命令行工具编辑 plist 文件
Oct 01, 2022
plutil 是 macOS 下的一个命令行工具,用于编辑和处理 *.plist 格式的文件。 转换文件格式 plutil -convert xml1 ToolchainInfo.plist 文件类型说明:xml1 XML 格式,binary1 二进制格式,json JSON 格式。 修改键值 ToolchainInfo.plist 文件的内容: …
Swift Package Tools Version 的写法
Sep 30, 2022
在写 Package.swift 的时候,通常第一行是使用注释的形式指定要使用的 Swift 版本: // swift-tools-version: 5.4 我把 5.4 调整为 5.0,于是改为这样: // swift-tools-version: 5.0 没想到 Xcode 报错了: Showing Recent Messages horizontal whitespace sequence [U+0020] immediately preceding the version specifier is supported by only Swift ≥ 5.4; consider removing the sequence for Swift 5.0.0 错误提示说:仅在 Swift ≥ 5.4 时候才能允许版本号之前有空格的写法,如果要保留写法需要指定 Swift 版本为 5.4 才行。 …
pfctl 简介
Sep 27, 2022
在 macOS 10.10 开始,系统防火墙工具由 ipfw 替换为了 pfctl,关于 pf 防火墙的使用手册可以参考这里: https://murusfirewall.com/Documentation/OS%20X%20PF%20Manual.pdf 开启 IP 转发功能 开启 IPv4 转发功能: $ sudo sysctl net.inet.ip.forwarding=1 net.inet.ip.forwarding: 0 -> 1 开启 IPv6 转发功能: …
Windows 11 安装 Microsoft Store
Sep 26, 2022
使用管理员权限打开 Power Shell,输入命令: Get-AppxPackage -allusers | Select Name, PackageFullName 列出所有微软官方的包名称,找到 Microsoft.WindowsStore 对应的完整包名称: Name PackageFullName ---- --------------- Microsoft.WindowsStore Microsoft.WindowsStore_22207.1401.1.0_arm64__8wekyb3d8bbwe 把完整包名拷贝,然后输入以下命令开始安装: Add-AppxPackage -register 'C:\Program Files\WindowsApps\Microsoft.WindowsStore_22207.1401.1.0_arm64__8wekyb3d8bbwe\AppxManifest.xml' -DisableDevelopmentMod 安装结束后就可以在所有应用中找到 Microsoft Store 了。 …
mitmproxy 入门指南
Sep 25, 2022
mitmproxy 是开源的免费的 HTTP 抓包工具。 安装 mitmproxy 下载:mitmproxy-8.1.1-osx.tar.gz 解压得到三个核心程序:mitmproxy, mitmdump, mitmweb $ tar xvf ./mitmproxy-8.1.1-osx.tar.gz x mitmproxy x mitmdump x mitmweb 在 macOS 上需要先移除额外的属性,否则执行的时候会触发看门狗询问是否允许执行的提示。 …
bitcode 被废弃了
Sep 24, 2022
在 Xcode 14 的发布日志中: https://developer.apple.com/documentation/xcode-release-notes/xcode-14-release-notes Apple Clang Compiler Deprecations Starting with Xcode 14, bitcode is no longer required for watchOS and tvOS applications, and the App Store no longer accepts bitcode submissions from Xcode 14. Xcode no longer builds bitcode by default and generates a warning message if a project explicitly enables bitcode: “Building with bitcode is deprecated. Please update your project and/or target settings to disable bitcode.” The capability to build with bitcode will be removed in a future Xcode release. IPAs that contain bitcode will have the bitcode stripped before being submitted to the App Store. Debug symbols for past bitcode submissions remain available for download. (86118779) …
Windows 11 22H2 安装时跳过网络连接
Sep 22, 2022
Windows 11 22H2 更新中,默认会要求系统必须连接上 Internet 否则无法进行下一步安装。 解决方法: 按下 Shift + F10,调出命令行界面,输入 oobe\BypassNRO.cmd,然后回车。系统会重启然后重新始安装流程,就不再强制要求连接 Internet 了: …