3

In one of the answers for a question on iOS Framework vs. Static Library, yoAlex5 quoted,

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)

Could anyone please give any example for iOS with minimal code snippet where I can understand how Static Library cannot support inversion of control when a Framework can?

Community
  • 1
  • 1
Sazzad Hissain Khan
  • 29,428
  • 20
  • 134
  • 192

1 Answers1

1

In the accepted answer to the question that you cited, the following is mentioned:

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).

So the main difference on iOS actually is that normally a framework is used in compiled form, whereas a library is used as code. Therefore both support in principle inversion of control.

However, even if everything a framework can, could also be provided by a library, one should definitively restrict certain functionality to frameworks. 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.

Reinhard Männer
  • 11,202
  • 4
  • 45
  • 85
  • *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.* I was asking for minimal example to understand that particular statement. A minimal example with pseudocode also might be helpful. – Sazzad Hissain Khan Feb 24 '20 at 10:34
  • My answer to your question `Could anyone please give any example for iOS with minimal code snippet where I can understand how Static Library cannot support inversion of control when a Framework can?`should point out, that a Static Library **can** support inversion of control. So there is no such example. – Reinhard Männer Feb 24 '20 at 10:38
  • Why did wiki add the phrase, **unlike in libraries** in the statement? What am I missing? – Sazzad Hissain Khan Feb 24 '20 at 10:58
  • To my mind, frameworks **usually** have inversion of control. But since in iOS the essential **practical** difference between a framework and a library is whether it is precompiled or not, one **could** have inversion of control in a library, but one **should not**. Sorry, if this is a little unsatisfactory. – Reinhard Männer Feb 24 '20 at 11:48