Old Driver iOS Weekly #258 | 2023-08-28

Original link: https://github.com/SwiftOldDriver/iOS-Weekly/releases/tag/%23258

ios-weekly

The old driver’s iOS weekly report only presents valuable information for you.

You can also contribute to this project. If you find valuable information, articles, tools, etc., you can submit them to us in Issues , and we will deal with them as soon as possible. Remember to write down the reason for the recommendation. Suggestions and comments are also welcome to Issues .

news

? Flutter 3.13 Update

@CrazyCoderShi : Flutter quarterly update is here! ! ! This update is still under the 3.x series, that is to say, it is still continuously repaired and optimized, so what interesting capabilities have been brought this time:

  • Optimized the performance of Impeller on iOS, and mac OS is already testable
  • Foldable screen devices get support
  • Material 3 continues to improve support, and the next version will default to the M3 option
  • Application lifecycle monitoring improvements
  • TwoDimensional, new scrolling mechanism
  • New slivers, support combination

Novice recommendation

? Applying metal shader to text in SwiftUI

@Cooper Chen : This year’s WWDC23 introduced view modifiers for applying shaders to SwiftUI views, and because shaders also conform to the ShapeStyle protocol, this means developers can directly pass shaders to foregroundStyle view modifiers, Then SwiftUI uses the shader to calculate the pixel color value of the view. This article uses a simple example to understand how to apply the shader to the text. It is a good reference for students who are new to related development.

article

? Swift’s closure capturing mechanics

@JonyFang : Although Swift’s automatic reference counting manages memory, and while we often hear oversimplified rules like “always use weak references in closures”, it’s important to understand how closures capture and refer to objects and values . In daily development, it is necessary to have a deep understanding of these mechanisms and apply them reasonably according to the actual situation.

  1. Implicit capture. When an escape closure is defined, it implicitly captures the objects, values, and functions referenced inside. These closures need to keep strong references to all dependencies in order to prevent them from being deallocated when executed later. Gives an example of how to use GCD to delay showing a UIAlertController, and mentions that this way of catching can lead to some tricky bugs and memory issues. At the same time, it is also mentioned that for view controllers that have been removed from the view hierarchy, careful handling is required to avoid problems.

  2. capture list. By using a capture list inside a closure, it is possible to specify whether an object is captured by a weak reference or the default strong reference. Capturing an object by a weak reference avoids potential retain cycle problems, especially when a reference to self is required. Through examples, it shows the specific application scenarios of using capture lists in closures, and how to avoid the problem of retaining loops. In general, the capture list is an effective way to solve the reference problem in closures, and can more precisely control the reference relationship between objects and values.

  3. Use capture lists to avoid retain loops. Weak references are not the best solution for all situations. How to use self and the lifetime of the closure in memory should be carefully considered in different situations. In short-lived closures, such as UIView animations, capturing self is usually fine and the code is easy to read. But when accessing instance methods and properties in closures, an explicit reference to self is required to explicitly capture the decision. There are situations where it is necessary to retain self for a long time, such as when the current object’s work in the closure is necessary. At the same time, the capture list allows us to directly capture the dependencies of the closure without referencing the entire self. Useful when you only need to access a few properties rather than the entire self.

  4. capture value. Value types are more complex in closure capture. Value types are passed as copies when they are passed in closures, which makes Swift’s value types very powerful, but there may be unexpected cases in certain situations. For example, capturing sender and message properties may result in inconsistent values ​​when assigning a handler closure to a button. For mutable values, the workaround is to just capture self in the closure, and map that value directly to the send method. However, for constants, there is no problem adding these properties to the closure’s capture list.

  5. Unowned references (unowned). The unowned reference in the closure capture is the same as the weak reference, and it is also specified through the capture list, which can only be applied to the reference type. Using unowned effectively achieves the same result as using a force-unwrapped optional, i.e. treating a weak reference as a non-optional, but causing a crash if you try to access it after the reference has been freed. Using unowned , while letting us get rid of optionals, can be very convenient at times, but it can cause a crash after a reference is freed, unless we’re absolutely sure that a given closure won’t trigger accidentally after one of its dependencies is freed. However, instead of using unowned , we can achieve the exact same effect with assertions. While this results in some extra code, it provides a more actionable error message on failure and doesn’t cause a crash in production.

It is important to understand how closures are captured and how to refer to objects and values, and they need to be properly applied in daily development.

? Deterministic builds with clang and lld

@老峰: Reproducible builds (English: Reproducible builds) are also known as deterministic compilation (English: Deterministic compilation), that is, the source code compiled with deterministic compilation will always output the same binary in any path, time, and environment document. This article mainly introduces the basic concept of Deterministic compilation and how to use LLVM to create a deterministic build.

? How to Automate Memory Leak Detection in Your Swift Code with XCTest

@AidenRao : This post describes how to use XCTest to automatically detect memory leaks in Swift code: using the addTearDownBlock method in XCTestCase, at the end of the test method, an assertion checks that the object is properly released.

? How to check if you use a required reason API

@J_Knight_ : When we call certain APIs, we need to inform Apple of the official reasons for using them (such as some system parameters that can be used to identify devices). The author of this article calls this type of API “Required Reason API”. The author briefly introduces the types of these APIs, and also provides a script to find such APIs in the code

the code

SwingAnimation : a code worth 500

@zhuoclassmate : The cause of the incident is that Zili hzlzh “offered a reward” of 500 yuan on Twitter, wanting to know the secret of how widgets can do displacement animation. Apple does not officially support widgets for animation, so to achieve this animation must have found a special way to achieve it. Less than a day after the reward was issued, a developer successfully won the reward.

After I told this to one of our editors who didn’t want to be named, the editor had a strong thirst for knowledge, so he also spent 500 to get the secret. And shared on social networks: “I bought a code for 500 yesterday, which is a good deal.” At the same time, I also said in the circle of friends: “Biaozi, you love learning too much.”

Just when we were immersed in the joy of sharing a secret worth 500 with another person, which was equivalent to earning 500 for nothing, which was equal to the joy of not spending money at the time, a well-known widget developer tree open sourced this solution. So this is a code with a real value of 500. If you need to do widget displacement animation, welcome to learn about it.

Introduce

Restarted to update the “iOS Reliable Internal Recommendation Topic”, and sorted out the positions that have been clearly recruited recently for your reference

[Hangzhou] Alibaba—Content Terminal Technical Team—Mobile Taobao Homepage & Information Flow Direction—iOS/Android

[Shanghai] – Perfect World Esports – iOS

[Beijing/Hangzhou] – Douyin Cast Screen – Android/iOS

[Beijing] – Baidu Wangpan iOS/Android/FE/Server R&D Engineer

[Shenzhen/Guangzhou/Beijing/Sanya] Bytedance – Clipping – Recruitment Client Development

For specific information, please go to: https://www.yuque.com/ioalliance/article/bhutav to view (if you have any recruitment needs, please contact iTDriverr)

Follow us

We are “Old Driver Technology Weekly”, a technical public account that continues to pursue high-quality iOS content, welcome to pay attention.

Follow politely, pay attention to [Old Driver Technology Weekly], reply to “2023”, and receive 2023 and previous year’s internal participation

It also supports RSS feeds: https://github.com/SwiftOldDriver/iOS-Weekly/releases.atom .

illustrate

? Indicates that a tool is needed, ? indicates an editor’s recommendation

Estimated reading time: ? Can be read quickly (1 – 10 mins); ? Moderate (10 – 20 mins); ? Slow (20+ mins)

This article is transferred from: https://github.com/SwiftOldDriver/iOS-Weekly/releases/tag/%23258
This site is only for collection, and the copyright belongs to the original author.