简体   繁体   中英

Injecting parameter in Typhoon Swift

I am using the following code to inject a enum parameter in Typhoon in Swift:

public dynamic func introPageViewController() -> AnyObject {
        return TyphoonDefinition.withClass(UIPageViewController.self)  {
        (definition) in
            definition.useInitializer("initWithTransitionStyle:navigationOrientation:options:"){

        (initializer) in
        initializer.injectParameterWith(UIPageViewControllerTransitionStyle.Scroll)
        }

    }

}

The problem is that injectParameterWith method only accepts parameters of type AnyObject and the parameter I want to inject is of Int type so this code gives a compiler error. How would I achieve this without causing any compiler error or crash?

As outlined in the Typhoon User Guide here , to inject an enum it is necessary to box it as an NSNumber. I'm actually not sure how to box explicitly in Swift but you could do it with something like:

var num: NSNumber = mode.rawValue

我现在无法尝试,但根据您应该能够将import Foundation添加到文件顶部,它会从Int隐式转换为NSNumber

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM