objective c - iOS: Unrecognized selector error — but I never call that method and it doesn’t exist -


so pretty weird one.

first of — doesn’t happen when running app via xcode. when app running standalone on device (deployed via testflight or itunes).

i use class called rmlstarreceiptprinter interface portable, bluetooth receipt printer. works fine while running in debug mode while device (iphone/ipad) connected xcode on dev machine.

if run in standalone mode, -[rmlstarreceiptprinter th:]: unrecognized selector sent instance error. but, th: method doesn’t exist in rmlstarreceiptprinter , never called! time when ran it, errored same message selector ex:, doesn’t exist either. there methods contain th , ex substrings in name, tells me kind of weird memory leak or form of corruption makes app send wrong selector name. possible?

bonus: thought when compile in release mode (which in case), package doesn’t contain symbol tables, how come in error logs there class , selector names?

i can answer bonus part of question, , not actual problem.

objective-c uses dynamic dispatch (or messaging) invoke methods. every method invocation goes through following steps:

  • check pointer valid object. referenced memory contain header including called 'isa pointer'. isa pointer type of class object declares be. if memory not reference valid object exc_bad_access error raised.
  • using declared class, lookup in objective-c runtime made (the objective-c runtime linked library - think of tiny virtual machine). if there's entry method name, resolved function pointer.
  • finally function invoked using objective-c calling convention.

the objective-c dispatch table assembled @ runtime, , can modified @ runtime. latter feature makes objective-c dynamic language, despite being otherwise low level. instance, can following:

  • modify class's isa pointer, point new subclass. add methods new sub-class. how cocoa's powerful kvo feature works - property setter sub-classed on fly include broadcasting message subscribers setting property value.
  • besides modifying single instance's behavior isa pointer swizzling, can modify all instances changing dispatch table class. useful aop-like behavior, example saying "all instances of uiviewcontroller must security checked".

anyway, in order programmed @ runtime, messaging information in plain text both in debug , release mode. (swift adds name mangling provide transparent namespaces).

debugging suggestion:

have tried implementing methods category follows?

- (void)th {   nslog(@"%@", [nsthread callstacksymbols]); } 

. . might shed light on things going wrong. however, although can add these methods via category, , insight, if class not have source for, might necessary work vendor resolve problem. (unless you're game try runtime patching!).


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -