amandeepsingh amandeepsingh - 1 month ago 18
iOS Question

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?

Answer

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
Comments