私は台風で迅速に使用していますが、どういうわけかコンポーネントがプロパティ注入によって注入されません。機能しているような単純なタイプの場合Strings
。問題を説明する簡単な例を提供しました。出力には、 へのserviceB
null 参照がある結果が表示されserviceA
ます。すべてのString
プロパティが適切に設定され、エラーはスローされません。私はここで何が間違っていますか?
XCode: 6-beta5、台風: 2.1.0
MYServiceA.swift
@objc(MYServiceA) public class MYServiceA : NSObject {
public var text : String!
}
MYServiceB.swift
@objc(MYServiceB) public class MYServiceB : NSObject {
public var text : String!
public var serivceA : MYServiceA!
}
MYAssembly.swift
public class MYAssembly : TyphoonAssembly {
public func serviceA() -> AnyObject {
var definitionBlock : TyphoonDefinitionBlock = {(definition : TyphoonDefinition!) in
definition.injectProperty("text", with: "some a text")
definition.scope = TyphoonScopeSingleton
}
return TyphoonDefinition.withClass(NSClassFromString("MYServiceA"), configuration: definitionBlock)
}
public func serviceB() -> AnyObject {
var definitionBlock : TyphoonDefinitionBlock = {(definition : TyphoonDefinition!) in
definition.injectProperty("text", with: "some b text")
definition.injectProperty("serivceA", with: self.serviceA())
definition.scope = TyphoonScopeSingleton
}
return TyphoonDefinition.withClass(NSClassFromString("MYServiceB"), configuration: definitionBlock)
}
}
AppDelegate.swift
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication!, didFinishLaunchingWithOptions launchOptions: NSDictionary!) -> Bool {
var assembly : MYAssembly = MYAssembly()
var factory : TyphoonComponentFactory = TyphoonBlockComponentFactory(assembly: assembly) as TyphoonComponentFactory
factory.makeDefault()
var serviceA : MYServiceA = TyphoonComponentFactory.defaultFactory().componentForKey("serviceA") as MYServiceA
println("MYServiceA")
println("- instance=\(serviceA != nil)")
println("- text=\(serviceA.text)")
var serviceB : MYServiceB = TyphoonComponentFactory.defaultFactory().componentForKey("serviceB") as MYServiceB
println("MYServiceB")
println("- instance=\(serviceB != nil)")
println("- text=\(serviceB.text)")
println("- serviceA.instance=\(serviceB.serivceA != nil)")
return true
}
..
}
出力
MYServiceA
- instance=true
- text=some a text
MYServiceB
- instance=true
- text=some b text
- serviceA.instance=false