0

Am using Josh Smith's ObjectFactory for instantiating classes by name in Swift. But the below code I tried results in unrecognised selector.

if let survey = surveyFactory.createInstance(className: className, initializer: "initWithStyle", argument: textChoiceStyle!.rawValue , argument2:  textChoices!)

The class name I passed is ORKTextChoiceAnswerFormat and the resulting Obj C expression I need to achieve in Swift as below

ORKTextChoiceAnswerFormat *asd = [[ORKTextChoiceAnswerFormat alloc]initWithStyle:<#(ORKChoiceAnswerStyle)#> textChoices:<#(NSArray * __nonnull)#>];

But am getting it as unrecognised selector in the object factory method

    static id OBJCInitWithArg(id  target,
                          SEL initializer,
                          id  argument, id argument2)
{  IMP imp = [target methodForSelector:initializer];
    id (*initFunc)(id, SEL, id, id) = (void *)imp;
   return initFunc(target, initializer, argument, argument2);
}

And am getting this error in the console

[ORKTextChoiceAnswerFormat initWithStyle]: unrecognized selector sent to instance

Where am I going wrong?

rootcoder
  • 187
  • 2
  • 13
  • You need to use `initWithStyle:`. – jtbandes Sep 09 '15 at 08:22
  • I tried still same `-[ORKTextChoiceAnswerFormat initWithStyle:]: unrecognized selector sent to instance 0x7fe6c0dcb200` – rootcoder Sep 09 '15 at 08:23
  • 1
    Actually, `initWithStyle:` isn't available. What did you expect it to do? See http://researchkit.org/docs/Classes/ORKTextChoiceAnswerFormat.html#//api/name/initWithStyle:textChoices: – jtbandes Sep 09 '15 at 08:23
  • to myself - "Where am I going wrong?" me - I am completely wrong *facepalm* – rootcoder Sep 09 '15 at 08:34

1 Answers1

2

The selector for your initializer is initWithStyle:textChoices:.

Ricardo Sanchez-Saez
  • 9,466
  • 8
  • 53
  • 92
glyuck
  • 3,367
  • 18
  • 14