Xcode and optional frameworks

前端 未结 1 1887
挽巷
挽巷 2021-02-19 07:52

Under Linked frameworks and libraries there is a Required or Optional option.

Could somebody explain a situation in

1条回答
  •  天涯浪人
    2021-02-19 08:26

    Optional linking is useful if you're targeting older OS versions where a certain framework might not be available yet. In this case you can set the linkage of the given framework to optional, and this causes the program not to crash on launch if dlopen cannot find the given framework.

    Then in your code you can put guard statements around the usage of this framework in order to avoid crashing b/c of using unresolved symbols:

     if (MyWeakLinkedFunction != NULL)
     {
         result = MyWeakLinkedFunction(); // this function comes from a weakly/optionally linked framework
     }
    

    See: Frameworks and Weak Linking

    0 讨论(0)
提交回复
热议问题