gpt4 book ai didi

ios - iOS 中控制反转的框架和静态库有何不同?

转载 作者:行者123 更新时间:2023-12-02 04:59:25 24 4
gpt4 key购买 nike

answers 之一关于 iOS FrameworkStatic Library 的问题,yoAlex5 引用,

A Library is essentially a set of functions that you can call, these days usually organized into classes. Each call does some work and returns control to the client.

A Framework embodies some abstract design, with more behavior built in. In order to use it you need to insert your behavior into various places in the framework either by subclassing or by plugging in your own classes. The framework's code then calls your code at these points. The main control of the program is inverted, moved away from you to the framework. (Inversion of Control)

谁能用最少的代码片段给出 iOS 的任何示例,让我能够理解 静态库 为何无法支持控制反转,而 框架 却可以?

最佳答案

accepted answer对于您引用的问题,提到了以下内容:

Hence on iOS, your only option is basically to use a static library or static framework (the main difference being that a static framework is distributed as a compiled .a file most often, whereas a static library may simply be included as a subproject - you can see all of the code - which is compiled first and its resulting .a file used as a dependency by the project).

因此,iOS 上的主要区别实际上是框架通常以编译形式使用,而库则作为代码使用。因此,两者原则上都支持控制反转。

但是,即使框架可以提供的一切也可以由库提供,但人们应该明确限制框架的某些功能。 Wiki says :

Frameworks have key distinguishing features that separate them from normal libraries:
• inversion of control: In a framework, unlike in libraries or in standard user applications, the overall program's flow of control is not dictated by the caller, but by the framework.

• extensibility: A user can extend the framework – usually by selective overriding – or programmers can add specialized user code to provide specific functionality.
• non-modifiable framework code: The framework code, in general, is not supposed to be modified, while accepting user-implemented extensions. In other words, users can extend the framework, but cannot modify its code.

关于ios - iOS 中控制反转的框架和静态库有何不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59873824/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com