{"id":4843,"date":"2014-03-30T15:54:48","date_gmt":"2014-03-30T15:54:48","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/how-to-use-ternary-operators-in-a-macro-in-objective-c-collection-of-common-programming-errors\/"},"modified":"2014-03-30T15:54:48","modified_gmt":"2014-03-30T15:54:48","slug":"how-to-use-ternary-operators-in-a-macro-in-objective-c-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/how-to-use-ternary-operators-in-a-macro-in-objective-c-collection-of-common-programming-errors\/","title":{"rendered":"How to use Ternary Operators in a Macro in Objective-C?-Collection of common programming errors"},"content":{"rendered":"<p>The string concatenation with adjacent string literals only works when both are string literals, i.e.<\/p>\n<pre><code>@\"foo\" @\"bar\"       is the same as         @\"foobar\"\n<\/code><\/pre>\n<p>because <code>@\"foo\"<\/code> and <code>@\"bar\"<\/code> are string literals, but<\/p>\n<pre><code>@\"foo\" (@\"bar\")     is compiler error\n<\/code><\/pre>\n<p>because of the <code>(<\/code> in between. This is the same situation as yours. In this case, you&#8217;d better concatenate the two strings in runtime:<\/p>\n<pre><code>#define LoginPageUrl    [BaseURL stringByAppendingString:(QueryStringParam)]\n<\/code><\/pre>\n<p>or force the compiler to see two adjacent string literals by combining the BaseURL and QueryStringParam<\/p>\n<pre><code>#define LoginPageUrl \\\n    ((UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad) ? \\\n        BaseURL @\"deviceType=iPad\" : \\\n        BaseURL @\"deviceType=iPhone\")\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The string concatenation with adjacent string literals only works when both are string literals, i.e. @&#8221;foo&#8221; @&#8221;bar&#8221; is the same as @&#8221;foobar&#8221; because @&#8221;foo&#8221; and @&#8221;bar&#8221; are string literals, but @&#8221;foo&#8221; (@&#8221;bar&#8221;) is compiler error because of the ( in between. This is the same situation as yours. In this case, you&#8217;d better concatenate the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4843","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4843","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=4843"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4843\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4843"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4843"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4843"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}