nsstring - Objective-C Language Syntax - "Type Checking" Constant Strings -


cocoa , cocoatouch use string constants frequently, , i'm wondering if there syntax enforces (encourages?) specific set of strings method's argument.

for example, nspersistentstorecoordinator's method -addpersistentstorewithtype:configuration:url:options:error: takes 1 of 4 possible strings first argument.

these strings declared in nspersistentstorecoordinator.h as

coredata_extern nsstring * const nssqlitestoretype ns_available(10_4, 3_0); coredata_extern nsstring * const nsxmlstoretype ns_available(10_4, na); coredata_extern nsstring * const nsbinarystoretype ns_available(10_4, 3_0); coredata_extern nsstring * const nsinmemorystoretype ns_available(10_4, 3_0); 

(fwiw, coredata_extern macro expands extern plus goodies other platforms)

beyond (parameter)asserting within method, there way make sure xcode / clang / llvm encourages these 4 values?

short , long answer: no. method accepts pointer, can throw in there, , if pointer of right type (id or nsstring in case), clang happily allow it. if have own code want tell user method accept values, make clear in documentation , throw descriptive exception.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -