iOS摸鱼周报 第三十三期

本文介绍了iOS开发中的os_signpost工具,用于标记函数执行和测量耗时,以及Objective-C和Swift混编时如何桥接类型。同时,文章还解析了LeetCode的TwoSum问题,探讨了算法面试中的思考过程和多种解题方案。
摘要由CSDN通过智能技术生成

本期概要

  • 话题:感恩节和圣诞节期间 AppStore 将正常接受审核。
  • Tips:使用 os_signpost 标记函数执行和测量函数耗时;混编|将 Objective-C typedef NSString 作为 String 桥接到 Swift 中。
  • 面试模块:LeetCode - #1 Two Sum。
  • 优秀博客:本期为大家整理了一些关于图像识别框架 Vision 的文章。
  • 学习资料:Vue Color Avatar,一个纯前端实现的头像生成网站;一篇全面介绍 WebKit 和 Gecko 内部操作的入门文章。
  • 开发工具:swiftenv。

本期话题

@zhangferry:苹果发布了年末两个重要假期关于 AppStore 审核的声明。往年圣诞节期间一般都是停止审核的,今年则会正常接受提交。但是在 11 月 24 号到 28 号(感恩节),和 12 月 23 号到 27 号(圣诞节)之间的提交审核流程会比较慢。如果可以错开排期的话尽量不要在这个时间段提审。

信息来源:Submissions now accepted through the holidays

开发Tips

使用 os_signpost 标记函数执行和测量函数耗时

整理编辑:zhangferry

ossignpost 是 iOS12 开始支持的一个用于辅助开发调试的轻量工具,它跟 Instruments 的结合使用可以发挥很大作用。ossignpost API 较简单,其主要有两大功能:做标记、测量函数耗时。

首先我们需要引入 os_signpost 并做一些初始化工作:

```swift import os.signpost

// test function func bindModel { let log = OSLog(subsystem: "com.ferry.app", category: "SignLogTest") let signpostID = OSSignpostID(log: log) // ... } ```

其中 subsystem 用于标记应用,category 用于标记调试分类。

后面试下它标记和测量函数的功能。

做标记

swift let functionName: String = #function os_signpost(.event, log: log, name: "Complex Event", "%{public}s", functionName)

注意这个 API 中的 name 和后面的 format 都是 StaticString 类型(format 是可选参数)。StaticString 与 String 的区别是前者的值是由编译时确认的,其初始化之后无法修改,即使是使用 var 创建。系统的日志库 OSLog 也是选择 StaticString 作为参数类型,这么做的目的一部分在于编译器可采取一定的优化,另一部分则是出于对隐私的考量。

The unified logging system considers dynamic strings and complex dynamic objects to be private, and does not collect them automatically. To ensure the privacy of users, it is recommended that log messages consist strictly of static strings and numbers. In situations where it is necessary to capture a dynamic string, you may explicitly declare the string public using the keyword public. For example, %{public}s.

对于调试期间我们需要使用 String 附加参数的话,可以用 %{public}s 的形式格式化参数,以达到捕获动态字符串的目的。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值