Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I found it! The answer was, of course, on NSHipster and relates to the <a href="http://nshipster.com/__attribute__/" rel="nofollow"><code>__attribute__</code> directive</a>.</p> <p>In my particular case, the <code>const</code> specifier seems to fit best: </p> <blockquote> <p>The const attribute specifies that a function does not examine any values except their arguments, and have no effects except the return value. Note that a function that has pointer arguments and examines the data pointed to must not be declared const. Likewise, a function that calls a non-const function usually must not be const.</p> </blockquote> <p>So I was going to declare my class method as:</p> <p><code> + (UIColor *)primaryTintColor __attribute__((const)); </code></p> <p>After adding the <code>__attribute__</code> directive as above, the code compiled without error and behaves as expected under Xcode 5.0.2 and the iOS SDK 7.0.</p> <p>But as others have pointed out in the comments below, methods resolve internally to a function that includes a pointer argument to resolve <code>self</code>, so <code>__attribute__((const))</code> is <em>never</em> appropriate for methods. In this case, while it's a simple call to <code>+[UIColor colorWithRed:green:blue:alpha:]</code> I'll leave it as it is, but when it gets more complex—say, to slightly customise the values for different devices—I may well use a static variable to cache the value and use performance profiling to quantify any improvement.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload