objective c - What is the naming convention for methods you know will appear in a later SDK? -
i realize there subjectivity in question, considering apple development pretty opinionated naming conventions want in way others understand coding doing. trying ask question in generic way, i'll add of specific details in comments in case affects answer.
let's supporting both ios 6 , ios 7. there new method on existing class exists in ios 7 sdk. assume implementing functionality in way "good enough" app straightforward. but, of course, i'd rather use sdk version better supported, more efficient, , better handle edge cases.
as documented in this q&a straightforward handle situation.
if ([myinstance respondstoselector:@selector(newselector)]) { //use sdk method } else { //use "good enough" implementation. }
but don't want litter code whole bunch of conditional invocations. seems better encapsulate dynamic method selection. (especially in case, method hasn't shipped yet , name/signature might change.)
my instinct add class category implements both functionality wrapper method implements dynamic selection of method.
is right approach? if so, naming conventions should use? (i can't name method same ios7 method or there naming collisions.)
my gut reaction call wrapper method safenewselector , implementation private method called lwnewselector (where lw standard class prefix). i'd rather use considered standard naming convention.
my instinct add class category implements both functionality wrapper method implements dynamic selection of method.
that sounds right. naming convention category methods lowercase prefix, plus underscore. so, if shadowing method called dosomething:withawesome:
, name category method ogr_dosomething:withawesome:
(assuming use ogr
common prefix).
you must prefix category methods. if 2 categories implement same method, undefined behavior run. not compile-time or runtime error. you'll undefined behavior. (and apple can, , does, implement "core" functionality in categories, , cannot detect they've done so.)
Comments
Post a Comment