{ iOS }

  • Swift 方法桥接到 ObjC 时报 type cannot be represented

    | /

    工程里 SwiftObjective-C 混编已经是常态,经常遇到 Objective-C 代码去调用 Swift 里的方法。最新的 Swift 需要手动标注 @objc 才能把方法暴露。(印象中似乎在 Swift 2.x 的时代,是默认暴露)

    但经常会遇到 method cannot be marked @objc because the type of the parameter cannot be represented in objective-c 类似的错误,直觉为参数、返回值,无法从 Swift 桥接到 Objective-C,有时候一眼就知道缺了什么,有时候则要思考半天,这里简单整理一下几种常见的情况。

  • Swift构造函数(init)与属性观察器(didSet)

    | /

    最近工程里 SwiftObjective-C 混编的场景越来越多了,大家在编写 Swift 代码时,一般都会用 didSet 来作为 Objective-Csetter 的替代。但最近遇到好几起(自己和其他同事)因为 Swiftinit 里对属性赋值没有触发 didSet,进而导致结果不符合预期的问题,看来还是对 Swift 使用不熟练,这里稍微汇总下。(另外,末尾会附上 ChatGPT3.5 的回答情况)

  • Why Should Take "What's New" Seriously

    | /

    For personal APP, it may pay more attention to the writing of “What’s New” to attract more users to download and upgrade.

    If you work for a large company, the content source might be a product manager or operations.

    So how to write What’s New better? We often see some novel serialization or small humor, which is very interesting.

    But in any case, I advise everyone to show your artistic talents on the basis of writing real and updated content.

    Because we have been rejected for violating the "Performance - Accurate Metadata" clause.

  • Why State update doesn't work

    | /

    Recently, some personal apps have begun to try to use SwiftUI.

    Although some simple layouts, SwiftUI is indeed very efficient in development. But in actual development, many problems will be encountered.

    1. The development concept is different from UIKit, which leads to unaccustomed.
    2. Some components only have UIKit and need to be encapsulated.
    3. There will be compatibility issues with different versions of Xcode and operating systems.
    4. Sometimes some writing methods lead to actual effects that do not meet expectations.
    5. And so on.

    I have encountered a situation where the State change does not take effect, and it is also possible that my usage is not completely correct.

  • Quick Fix For Can't add self as subview

    | /

    I believe you can always find a lot of this kind of Crash: Can't add self as subview.

    We also know that we will never write code like add self as subview.

    In fact, in most cases, the push and pop pages with animation and no animation occur at the same time.

    Because we all know that this is often caused by the complexity of the page hierarchy and the unpredictable page jumps. So often choose to shelve this Crash helplessly.

    But we always think about how to eliminate this Crash. Whether it is from the perspective of user experience or from the aspect of Crash rate management.

  • Extension Version Mismatch

    | /

    When we need to intercept the pushed information and customize the display, we need to use the extension capabilities provided by Apple. It means that our project will become a multi-target project.

    At this time, we may encounter the problem of version mismatch.

  • Preprocessor Macros in Pods

    | /

    As mentioned earlier, we can inject macros into Pods from the outside by modifying the Podfile. You can refer to this article Inject TEST macros into Pods.

    Sometimes there are some macros that are expected to be used inside the Pods library we wrote ourselves.

    A common practice, just like ordinary business code, define a macro definition header file, and then import.

    But sometimes there are such scenarios, such as logging or providing some externally exposed APIs, you need to provide the version of the current library.

  • Inject TEST macros into Pods

    | /

    When we develop iOS applications, we often use CocoaPods for third-party library management.

    In addition to external third-party libraries, it is common for CocoaPods to be used as a library management tool for individuals or companies.

    We usually use macros such as DEBUG for environment-sensitive branch compilation.

    CocoaPods provides DEBUG macro injection by default to facilitate our local debugging.

    However, in actual development projects, in addition to using the DEBUG macro to identify local debugging, macros such as TEST or QA are also used to identify the test build package.

    At this time, we expect that the library in Pods can also inject TEST macros on demand.

  • weakSelf in dealloc

    | /

    We all know that it is generally recommended to do simple cleanup in the dealloc method.

    A very important reason is that in the process of destroying an object, if an operation such as weak is performed, it will cause a crash.