菜鸟教程小白 发表于 2022-12-13 05:37:44

ios - 如何访问已激活 plist 的程序集?


                                            <p><p>我正在转换一个项目以使用台风的 plist 集成。我可以看到我添加到 <code>TyphoonInitialAssemblies</code> 键的程序集正在被激活,但是在我不知道如何访问激活的程序集之后。</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>您可以通过注入(inject)程序集来访问程序集。您可以为 App Delegate 定义一个特殊情况定义,如 <a href="https://github.com/appsquickly/Typhoon-example" rel="noreferrer noopener nofollow">shown in the Typhoon example application</a> :</p>

<pre><code>- (PFAppDelegate *)appDelegate
{
return    
    configuration:^(TyphoonDefinition *definition)
    {
      //Inject the assembly
      [definition injectProperty:@selector(assembly)
            with:self];

      //Inject other properties
      [definition injectProperty:@selector(window)
            with:];
      [definition injectProperty:@selector(cityDao)
            with:];            
    }];
}
</code></pre>

<p>。 .或者您也可以将程序集注入(inject)到任何其他 Typhoon 创建的组件中。这对于使用 <a href="https://github.com/appsquickly/Typhoon/wiki/Types%20of%20Injections#injection-with-run-time-arguments" rel="noreferrer noopener nofollow">factory pattern</a> 从一个对象图进行到另一个对象图很有用。 . </p>

<ul>
<li>请注意,对于 App Delegate(或在 Typhoon 之外创建的其他对象),属性和方法注入(inject)可以正常工作,但当然不支持初始化程序注入(inject)。此外,您不能缩小对象的范围,也就是说,在声明为原型(prototype)的 Typhoon 之外创建的单例将保持为单例。 </li>
<li>另外请注意,如果您愿意,您可以使用协议(protocol)支持您的程序集,这样就不必将您的类直接耦合到 Typhoon。 </li>
</ul>

<p>通过 plist 集成引导的程序集也是绑定(bind)到您的初始/主 Storyboard 的程序集,因此任何 <a href="https://github.com/appsquickly/Typhoon/wiki/Auto-injection-%28Objective-C%29" rel="noreferrer noopener nofollow">auto-injection</a>将满足在您的 Storyboard上创建的 ViewController 上定义的属性。这包括一个程序集类型属性,例如:</p>

<pre><code>@property(nonatomic, strong) InjectedClass(MyAssembly) assembly;
</code></pre>

<p><a href="https://github.com/appsquickly/Typhoon/wiki/What%20can%20be%20Injected#injecting-the-assembly-itself" rel="noreferrer noopener nofollow">this feature is here</a> 的文档. </p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 如何访问已激活 plist 的程序集?,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/28847478/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/28847478/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 如何访问已激活 plist 的程序集?