<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>

<channel>
	<title>CoCoa Crumbs</title>
	<atom:link href="http://www.cocoacrumbs.com/blog/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.cocoacrumbs.com/blog</link>
	<description>Yet another CoCoa blog</description>
	<pubDate>Tue, 27 Oct 2009 19:31:05 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.3</generator>
	<language>en</language>
			<item>
		<title>Going fullscreen in Cocoa - Part III</title>
		<link>http://www.cocoacrumbs.com/blog/?p=128</link>
		<comments>http://www.cocoacrumbs.com/blog/?p=128#comments</comments>
		<pubDate>Tue, 27 Oct 2009 19:25:34 +0000</pubDate>
		<dc:creator>kvnieuwe</dc:creator>
		
		<category><![CDATA[CoCoa]]></category>

		<guid isPermaLink="false">http://www.cocoacrumbs.com/blog/?p=128</guid>
		<description><![CDATA[Time for a completely different approach. This time when I start the fade out to black, I create a borderless window with the same dimensions as the screen I want to fade. This window has a black background but with an initial alpha value of 0.0 (so it&#8217;s not visible yet). Let&#8217;s call this a [...]]]></description>
			<content:encoded><![CDATA[<p>Time for a completely different approach. This time when I start the fade out to black, I create a borderless window with the same dimensions as the screen I want to fade. This window has a black background but with an initial alpha value of 0.0 (so it&#8217;s not visible yet). Let&#8217;s call this a curtain window which act as a layer above anything else that might be on the screen. During the fading period, I increase the alpha value in small steps to 1.0 so that the black background of the curtain window becomes gradually visible thus obscuring everything below it. During the reverse fade, I change the alpha value back to 0.0 again in small steps and at the end I simply remove the curtain window.</p>
<p>During the fade process, I also hide the cursur using</p>
<p><code>[NSCursor hide];</code></p>
<p>and</p>
<p><code>[NSCursor unhide];</code></p>
<p>This is the final fade code:</p>
<style type="text/css">
	@import "/blog/wp-content/themes/wp-andreas01/coloring-halloween.css";
</style>
<p>
<body>
<pre class="textmate-source coloring"><span class="source source_objc++"><span class="support support_class support_class_cocoa">NSWindow</span>    *curtainWindow;

...

- (<span class="storage storage_type storage_type_c">void</span>)fadeInDisplay:(<span class="support support_class support_class_cocoa">NSScreen</span>*)theScreen
             fadeTime:(<span class="storage storage_type storage_type_c">double</span>)fadeTime
<span class="meta meta_block meta_block_c">{
    <span class="storage storage_type storage_type_c">int</span>     fadeSteps       = <span class="constant constant_numeric constant_numeric_c">100</span>;
    <span class="storage storage_type storage_type_c">double</span>  fadeInterval    = (fadeTime / (<span class="storage storage_type storage_type_c">double</span>) fadeSteps);

    <span class="storage storage_type storage_type_c">int</span>     step;
    <span class="storage storage_type storage_type_c">double</span>  fade;

    <span class="keyword keyword_control keyword_control_c">if</span><span class="meta meta_initialization meta_initialization_c"> <span class="punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_c">(</span></span><span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="variable variable_language variable_language_objc">self</span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">curtainWindow</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span> != <span class="constant constant_language constant_language_objc">nil</span>)
    <span class="meta meta_block meta_block_c">{
        <span class="keyword keyword_control keyword_control_c">for</span><span class="meta meta_initialization meta_initialization_c"> <span class="punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_c">(</span></span>step = <span class="constant constant_numeric constant_numeric_c">0</span>; step &lt; fadeSteps; step++)
        <span class="meta meta_block meta_block_c">{
            fade = <span class="constant constant_numeric constant_numeric_c">1.0</span> - (step * fadeInterval);
            <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="variable variable_language variable_language_objc">self</span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">curtainWindow</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">setAlphaValue<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span>fade</span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>;

            <span class="support support_class support_class_cocoa">NSDate</span> *nextDate = <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="support support_class support_class_cocoa">NSDate</span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">dateWithTimeIntervalSinceNow<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span>fadeInterval</span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>;
            <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="support support_class support_class_cocoa">NSRunLoop</span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">currentRunLoop</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">runUntilDate<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span>nextDate</span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>;
        }</span> <span class="commentt comment_block comment_block_c"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">/*</span> end for <span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">*/</span></span>
    }</span> <span class="commentt comment_block comment_block_c"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">/*</span> end if <span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">*/</span></span>
    <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="variable variable_language variable_language_objc">self</span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">curtainWindow</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">close</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>;
    <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="variable variable_language variable_language_objc">self</span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">setCurtainWindow<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span><span class="constant constant_language constant_language_objc">nil</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>;

    <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="support support_class support_class_cocoa">NSCursor</span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">unhide</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>;
}</span> <span class="commentt comment_block comment_block_c"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">/*</span> end fadeInDisplay:fadeTime: <span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">*/</span></span>

- (<span class="storage storage_type storage_type_c">void</span>)fadeOutDisplay:(<span class="support support_class support_class_cocoa">NSScreen</span>*)theScreen
              fadeTime:(<span class="storage storage_type storage_type_c">double</span>)fadeTime;
<span class="meta meta_block meta_block_c">{
    <span class="storage storage_type storage_type_c">int</span>     fadeSteps       = <span class="constant constant_numeric constant_numeric_c">100</span>;
    <span class="storage storage_type storage_type_c">double</span>  fadeInterval    = (fadeTime / (<span class="storage storage_type storage_type_c">double</span>) fadeSteps);

    <span class="storage storage_type storage_type_c">int</span>     step;
    <span class="storage storage_type storage_type_c">double</span>  fade;

    <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="support support_class support_class_cocoa">NSCursor</span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">hide</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>;

    <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="variable variable_language variable_language_objc">self</span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">setCurtainWindow<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span><span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="support support_class support_class_cocoa">NSWindow</span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">alloc</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>
        initWithContentRect:<span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span>theScreen <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">frame</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>
                  styleMask:<span class="support support_constant support_constant_cocoa">NSBorderlessWindowMask</span>
                    backing:<span class="support support_constant support_constant_cocoa">NSBackingStoreBuffered</span>
                      defer:<span class="constant constant_language constant_language_objc">YES</span>
                     screen:theScreen<span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>;

    <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="variable variable_language variable_language_objc">self</span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">curtainWindow</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">setAlphaValue<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span><span class="constant constant_numeric constant_numeric_c">0.0</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>;
    <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="variable variable_language variable_language_objc">self</span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">curtainWindow</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">setBackgroundColor<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span><span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="support support_class support_class_cocoa">NSColor</span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">blackColor</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>;
    <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="variable variable_language variable_language_objc">self</span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">curtainWindow</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">setLevel<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span>NSScreenSaverWindowLevel</span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>;

    <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="variable variable_language variable_language_objc">self</span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">curtainWindow</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">makeKeyAndOrderFront<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span><span class="constant constant_language constant_language_objc">nil</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>;
    <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="variable variable_language variable_language_objc">self</span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">curtainWindow</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">setFrame<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span><span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="variable variable_language variable_language_objc">self</span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">curtainWindow</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>
        <span class="support support_function support_function_any-method support_function_any-method_objc">frameRectForContentRect:</span><span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span>theScreen <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">frame</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>
                           <span class="support support_function support_function_any-method support_function_any-method_name-of-parameter support_function_any-method_name-of-parameter_objc">display<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span><span class="constant constant_language constant_language_objc">YES</span>
                           <span class="support support_function support_function_any-method support_function_any-method_name-of-parameter support_function_any-method_name-of-parameter_objc">animate<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span><span class="constant constant_language constant_language_objc">NO</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>;

    <span class="keyword keyword_control keyword_control_c">for</span><span class="meta meta_initialization meta_initialization_c"> <span class="punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_c">(</span></span>step = <span class="constant constant_numeric constant_numeric_c">0</span>; step &lt; fadeSteps; step++)
    <span class="meta meta_block meta_block_c">{
        fade = step * fadeInterval;
        <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="variable variable_language variable_language_objc">self</span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">curtainWindow</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">setAlphaValue<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span>fade</span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>;

        <span class="support support_class support_class_cocoa">NSDate</span> *nextDate = <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="support support_class support_class_cocoa">NSDate</span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">dateWithTimeIntervalSinceNow<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span>fadeInterval</span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>;
        <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="support support_class support_class_cocoa">NSRunLoop</span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">currentRunLoop</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">runUntilDate<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span>nextDate</span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>;
    }</span> <span class="commentt comment_block comment_block_c"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">/*</span> end for <span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">*/</span></span>
}</span> <span class="commentt comment_block comment_block_c"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">/*</span> end fadeOutDisplay:fadeTime: <span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">*/</span></span></span></pre>
<p></body></p>
<p>For me, this works a lot better than changing the gamma values as in part II of the series. The screen fades smoothly to black without becoming first brighter as it happened when I change the gamma values of a screen. And I don&#8217;t have to worry about that kCGErrorNoneAvailable error code.</p>
<p>And here you can download a small sample project: <a href="http://www.cocoacrumbs.com/blog/wp-content/uploads/2009/10/gofullscreen-part-iii-usinglayer.zip" title="goFullScreen_part_III_usingLayer.zip">goFullScreen_part_III_usingLayer.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.cocoacrumbs.com/blog/?feed=rss2&amp;p=128</wfw:commentRss>
		</item>
		<item>
		<title>Going fullscreen in Cocoa - Part II</title>
		<link>http://www.cocoacrumbs.com/blog/?p=124</link>
		<comments>http://www.cocoacrumbs.com/blog/?p=124#comments</comments>
		<pubDate>Tue, 27 Oct 2009 19:19:25 +0000</pubDate>
		<dc:creator>kvnieuwe</dc:creator>
		
		<category><![CDATA[CoCoa]]></category>

		<guid isPermaLink="false">http://www.cocoacrumbs.com/blog/?p=124</guid>
		<description><![CDATA[In part I I described the the easiest solution of going full screen using the fade effect I wanted. However it had a couple of problems:

The enterFullScreenMode and exitFullScreenMode methods as they are implemented in Leopard (OS X 10.5) hide the dock and menubar for you but no means to show the menubar again when [...]]]></description>
			<content:encoded><![CDATA[<p>In part I I described the the easiest solution of going full screen using the fade effect I wanted. However it had a couple of problems:</p>
<ul>
The enterFullScreenMode and exitFullScreenMode methods as they are implemented in Leopard (OS X 10.5) hide the dock and menubar for you but no means to show the menubar again when the mouse hits the top of the screen (Snow Leopard fixes this).</p>
<p>CGDisplayFade() unfortunately fades all displays which isn&#8217;t what I wanted (only the screen where the window is located should go through the fade in/out cycle).
</ul>
<h2>Avoiding enterFullScreenMode and exitFullScreenMode</h2>
<p>The trick I used is creating a new, borderless, window which will take over the full screen. I use the SetSystemUIMode() API to hide both the dock and menubar (and by specifying kUIOptionAutoShowMenuBar the menubar will appear again when the mouse hits the top of the screen). The SetSystemUIMode() function is part of the carbon framework. But don&#8217;t be afraid, this function is safe to use in a 64 bit application.</p>
<p><strong>Remark:</strong> If you&#8217;re using a document based cocoa application you may consider creating a new NSWindowController for the borderless window.</p>
<style type="text/css">
	@import "/blog/wp-content/themes/wp-andreas01/coloring-halloween.css";
</style>
<p>
<body>
<pre class="textmate-source coloring"><span class="source source_objc">- (<span class="storage storage_type storage_type_objc">IBAction</span>)toggleFullscreen:(<span class="storage storage_type storage_type_id storage_type_id_objc">id</span>)sender
<span class="meta meta_block meta_block_c">{
    <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="variable variable_language variable_language_objc">self</span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">fadeOutDisplay<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span><span class="meta meta_function-call meta_function-call_c"><span class="support support_function support_function_any-method support_function_any-method_c">CGMainDisplayID</span>(</span>)
                <span class="support support_function support_function_any-method support_function_any-method_name-of-parameter support_function_any-method_name-of-parameter_objc">fadeTime<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span><span class="constant constant_numeric constant_numeric_c">1.0</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>;

    <span class="keyword keyword_control keyword_control_c">if</span><span class="meta meta_initialization meta_initialization_c"> <span class="punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_c">(</span></span><span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="variable variable_language variable_language_objc">self</span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">fullScreenWindow</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span> != <span class="constant constant_language constant_language_objc">nil</span>)
    <span class="meta meta_block meta_block_c">{
        <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="variable variable_language variable_language_objc">self</span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">fullScreenWindow</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>
            <span class="support support_function support_function_any-method support_function_any-method_objc">setFrame:</span><span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span>window <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">contentRectForFrameRect<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span><span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span>window <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">frame</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>
             <span class="support support_function support_function_any-method support_function_any-method_objc">display:</span><span class="constant constant_language constant_language_objc">YES</span>
             <span class="support support_function support_function_any-method support_function_any-method_objc">animate:</span><span class="constant constant_language constant_language_objc">NO</span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>;

        <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span>window <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">setContentView<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span><span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span>fullScreenWindow <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">contentView</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>;
        <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span>window <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">makeKeyAndOrderFront<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span><span class="constant constant_language constant_language_objc">nil</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>;

        <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="variable variable_language variable_language_objc">self</span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">fullScreenWindow</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">close</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>;
        <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="variable variable_language variable_language_objc">self</span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">setFullScreenWindow<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span><span class="constant constant_language constant_language_objc">nil</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>;

<span class="meta meta_function-call meta_function-call_c"><span class="punctuation punctuation_whitespace punctuation_whitespace_function-call punctuation_whitespace_function-call_leading punctuation_whitespace_function-call_leading_c">        </span><span class="support support_function support_function_any-method support_function_any-method_c">SetSystemUIMode</span>(</span>outMode, outOptions);
    }</span>
    <span class="keyword keyword_control keyword_control_c">else</span>
    <span class="meta meta_block meta_block_c">{
<span class="meta meta_function-call meta_function-call_c"><span class="punctuation punctuation_whitespace punctuation_whitespace_function-call punctuation_whitespace_function-call_leading punctuation_whitespace_function-call_leading_c">        </span><span class="support support_function support_function_any-method support_function_any-method_c">GetSystemUIMode</span>(</span>&amp;outMode, &amp;outOptions);
<span class="meta meta_function-call meta_function-call_c"><span class="punctuation punctuation_whitespace punctuation_whitespace_function-call punctuation_whitespace_function-call_leading punctuation_whitespace_function-call_leading_c">        </span><span class="support support_function support_function_any-method support_function_any-method_c">SetSystemUIMode</span>(</span><span class="constant constant_other constant_other_variable constant_other_variable_mac-classic constant_other_variable_mac-classic_c">kUIModeAllHidden</span>, <span class="constant constant_other constant_other_variable constant_other_variable_mac-classic constant_other_variable_mac-classic_c">kUIOptionAutoShowMenuBar</span>);

        <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="variable variable_language variable_language_objc">self</span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">setFullScreenWindow<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span><span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="support support_class support_class_cocoa">NSWindow</span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">alloc</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>
           <span class="support support_function support_function_any-method support_function_any-method_objc">initWithContentRect:</span><span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span>window <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">contentRectForFrameRect<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span><span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span>window <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">frame</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>
                     <span class="support support_function support_function_any-method support_function_any-method_objc">styleMask:</span><span class="support support_constant support_constant_cocoa">NSBorderlessWindowMask</span>
                       <span class="support support_function support_function_any-method support_function_any-method_objc">backing:</span><span class="support support_constant support_constant_cocoa">NSBackingStoreBuffered</span>
                         <span class="support support_function support_function_any-method support_function_any-method_objc">defer:</span><span class="constant constant_language constant_language_objc">YES</span>
                        <span class="support support_function support_function_any-method support_function_any-method_objc">screen:</span><span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span>window <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">screen</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>;

        <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="variable variable_language variable_language_objc">self</span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">fullScreenWindow</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">setContentView<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span><span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span>window <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">contentView</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>;
        <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="variable variable_language variable_language_objc">self</span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">fullScreenWindow</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">makeKeyAndOrderFront<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span><span class="constant constant_language constant_language_objc">nil</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>;
        <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="variable variable_language variable_language_objc">self</span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">fullScreenWindow</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">setFrame<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span><span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="variable variable_language variable_language_objc">self</span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">fullScreenWindow</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>
           <span class="support support_function support_function_any-method support_function_any-method_objc">frameRectForContentRect:</span><span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span>window <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">screen</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">frame</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>
                                  <span class="support support_function support_function_any-method support_function_any-method_name-of-parameter support_function_any-method_name-of-parameter_objc">display<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span><span class="constant constant_language constant_language_objc">YES</span>
                                  <span class="support support_function support_function_any-method support_function_any-method_name-of-parameter support_function_any-method_name-of-parameter_objc">animate<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span><span class="constant constant_language constant_language_objc">NO</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>;
    }</span> <span class="commentt comment_block comment_block_c"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">/*</span> end if <span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">*/</span></span>

    <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="variable variable_language variable_language_objc">self</span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">fadeInDisplay<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span><span class="meta meta_function-call meta_function-call_c"><span class="support support_function support_function_any-method support_function_any-method_c">CGMainDisplayID</span>(</span>)
               <span class="support support_function support_function_any-method support_function_any-method_name-of-parameter support_function_any-method_name-of-parameter_objc">fadeTime<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span><span class="constant constant_numeric constant_numeric_c">1.0</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>;
}</span> <span class="commentt comment_block comment_block_c"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">/*</span> end toggleFullscreen <span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">*/</span></span></span></pre>
<p></body>
</p>
<h2>Fading one screen only</h2>
<p>Apple realized that fading all screens at once might not be desirable to everyone and presents a workaround for this which can be found at the same <a href="http://developer.apple.com/mac/library/documentation/GraphicsImaging/Conceptual/QuartzDisplayServicesConceptual/Articles/FadeEffects.html#//apple_ref/doc/uid/TP40004232-SW1">URL</a> (in the &#8220;Fading a single display&#8221; section).</p>
<p>The workaround involves finding the gamma formula of the display that you want to fade and adjust it in small steps during the fading period. The code for this is shown here:</p>
<style type="text/css">
	@import "/blog/wp-content/themes/wp-andreas01/coloring-halloween.css";
</style>
<p>
<body>
<pre class="textmate-source coloring"><span class="source source_objc++">- (<span class="storage storage_type storage_type_c">void</span>)fadeOutDisplay:(CGDirectDisplayID)display
              fadeTime:(<span class="storage storage_type storage_type_c">double</span>)fadeTime
<span class="meta meta_block meta_block_c">{
    <span class="storage storage_type storage_type_c">int</span>     fadeSteps       = <span class="constant constant_numeric constant_numeric_c">100</span>;
    <span class="storage storage_type storage_type_c">double</span>  fadeInterval    = (fadeTime / (<span class="storage storage_type storage_type_c">double</span>) fadeSteps);

    <span class="storage storage_type storage_type_c">int</span>             step;
    <span class="storage storage_type storage_type_c">double</span>          fade;
    CGGammaValue    redMin,   redMax,   redGamma,
                    greenMin, greenMax, greenGamma,
                    blueMin,  blueMax,  blueGamma;

<span class="meta meta_function-call meta_function-call_c"><span class="punctuation punctuation_whitespace punctuation_whitespace_function-call punctuation_whitespace_function-call_leading punctuation_whitespace_function-call_leading_c">    </span><span class="support support_function support_function_any-method support_function_any-method_c">CGGetDisplayTransferByFormula</span>(</span>display,
                                  &amp;redMin,   &amp;redMax,   &amp;redGamma,
                                  &amp;greenMin, &amp;greenMax, &amp;greenGamma,
                                  &amp;blueMin,  &amp;blueMax,  &amp;blueGamma);
    <span class="keyword keyword_control keyword_control_c">for</span><span class="meta meta_initialization meta_initialization_c"> <span class="punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_c">(</span></span>step = <span class="constant constant_numeric constant_numeric_c">0</span>; step &lt; fadeSteps; step++)
    <span class="meta meta_block meta_block_c">{
        fade = <span class="constant constant_numeric constant_numeric_c">1.0</span> - (step * fadeInterval);
<span class="meta meta_function-call meta_function-call_c"><span class="punctuation punctuation_whitespace punctuation_whitespace_function-call punctuation_whitespace_function-call_leading punctuation_whitespace_function-call_leading_c">        </span><span class="support support_function support_function_any-method support_function_any-method_c">CGSetDisplayTransferByFormula</span>(</span>display,
                                      redMin,   fade*redMax,   redGamma,
                                      greenMin, fade*greenMax, greenGamma,
                                      blueMin,  fade*blueMax,  blueGamma);

        <span class="support support_class support_class_cocoa">NSDate</span> *nextDate = <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="support support_class support_class_cocoa">NSDate</span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">dateWithTimeIntervalSinceNow<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span>fadeInterval</span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>;
        <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="support support_class support_class_cocoa">NSRunLoop</span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">currentRunLoop</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">runUntilDate<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span>nextDate</span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>;
    }</span> <span class="commentt comment_block comment_block_c"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">/*</span> end for <span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">*/</span></span>
}</span> <span class="commentt comment_block comment_block_c"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">/*</span> fadeOutDisplay <span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">*/</span></span>

- (<span class="storage storage_type storage_type_c">void</span>)fadeInDisplay:(CGDirectDisplayID)display
             fadeTime:(<span class="storage storage_type storage_type_c">double</span>)fadeTime
<span class="meta meta_block meta_block_c">{
    <span class="storage storage_type storage_type_c">int</span>     fadeSteps       = <span class="constant constant_numeric constant_numeric_c">100</span>;
    <span class="storage storage_type storage_type_c">double</span>  fadeInterval    = (fadeTime / (<span class="storage storage_type storage_type_c">double</span>) fadeSteps);

    <span class="storage storage_type storage_type_c">int</span>             step;
    <span class="storage storage_type storage_type_c">double</span>          fade;
    CGGammaValue    redMin,   redMax,   redGamma,
                    greenMin, greenMax, greenGamma,
                    blueMin,  blueMax,  blueGamma;

<span class="meta meta_function-call meta_function-call_c"><span class="punctuation punctuation_whitespace punctuation_whitespace_function-call punctuation_whitespace_function-call_leading punctuation_whitespace_function-call_leading_c">    </span><span class="support support_function support_function_any-method support_function_any-method_c">CGGetDisplayTransferByFormula</span>(</span>display,
                                  &amp;redMin,   &amp;redMax,   &amp;redGamma,
                                  &amp;greenMin, &amp;greenMax, &amp;greenGamma,
                                  &amp;blueMin,  &amp;blueMax,  &amp;blueGamma);
    <span class="keyword keyword_control keyword_control_c">for</span><span class="meta meta_initialization meta_initialization_c"> <span class="punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_c">(</span></span>step = <span class="constant constant_numeric constant_numeric_c">0</span>; step &lt; fadeSteps; step++)
    <span class="meta meta_block meta_block_c">{
        fade = (step * fadeInterval);
<span class="meta meta_function-call meta_function-call_c"><span class="punctuation punctuation_whitespace punctuation_whitespace_function-call punctuation_whitespace_function-call_leading punctuation_whitespace_function-call_leading_c">        </span><span class="support support_function support_function_any-method support_function_any-method_c">CGSetDisplayTransferByFormula</span>(</span>display,
                                      redMin,   fade*redMax,  redGamma,
                                      greenMin, fade*greenMax, greenGamma,
                                      blueMin,  fade*blueMax,  blueGamma);

        <span class="support support_class support_class_cocoa">NSDate</span> *nextDate = <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="support support_class support_class_cocoa">NSDate</span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">dateWithTimeIntervalSinceNow<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span>fadeInterval</span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>;
        <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="support support_class support_class_cocoa">NSRunLoop</span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">currentRunLoop</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">runUntilDate<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span>nextDate</span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>;
    }</span> <span class="commentt comment_block comment_block_c"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">/*</span> end for <span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">*/</span></span>
}</span> <span class="commentt comment_block comment_block_c"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">/*</span> end fadeInDisplay <span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">*/</span></span></span></pre>
<p></body>
</p>
<p>Compared to the code Apple presented, I don&#8217;t use usleep() to halt the application until it&#8217;s time to change the gamma table with the next values in the for loop. The simple reason is that using usleep() blocks your application making it unresponsive to any GUI updates that might be needed (e.g. redrawing a view during the fading). Instead, I used the runUntilDate: method on the currentRunLoop so that the view can e.g. be redrawn while the screen is fading (with some changes the fade in and out methods could be made fully asynchronous and might be neater approach).</p>
<p>However, the least I can say is that I&#8217;m not happy with the results.</p>
<ul>
First of all, it doesn&#8217;t seem to work reliably. It might work on one Mac but not on another. E.g. on my MBP it will happily fade to black but never return back to the original state. However, if I connect my external 23 inch ACD and use that as my main screen, I get the desired effect.</p>
<p>Sharp eyes may notice that there are no error checks on the returned error codes of CGGetDisplayTransferByFormula(). Depending on the Mac you use, this function can return an kCGErrorNoneAvailable error. Weird enough you will get usable CGGammaValue values even when a kCGErrorNoneAvailable is returned. I wrote <em>usable values</em>, because they seem to be somewhat off. In my case, when I fade to black the screen starts a bit brighter before it gradually fades to black giving a kind of a flash effect. Not nice.
</ul>
<p>In part III I&#8217;ll present a different solution on how to obtain the desired fading effect.</p>
<p>Here is a link to the small test project I used: <a href="http://www.cocoacrumbs.com/blog/wp-content/uploads/2009/10/gofullscreen-part-ii-viawindow.zip" title="goFullScreen_part_II_viaWindow.zip">goFullScreen_part_II_viaWindow.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.cocoacrumbs.com/blog/?feed=rss2&amp;p=124</wfw:commentRss>
		</item>
		<item>
		<title>Going fullscreen in Cocoa - Part I</title>
		<link>http://www.cocoacrumbs.com/blog/?p=116</link>
		<comments>http://www.cocoacrumbs.com/blog/?p=116#comments</comments>
		<pubDate>Mon, 26 Oct 2009 20:12:42 +0000</pubDate>
		<dc:creator>kvnieuwe</dc:creator>
		
		<category><![CDATA[CoCoa]]></category>

		<guid isPermaLink="false">http://www.cocoacrumbs.com/blog/?p=116</guid>
		<description><![CDATA[For a project I&#8217;m working on I thought it would be nice to give the user the possibility to use the full screen (e.g. full screen editing in iPhoto, slideshow in Preview, &#8230;). As usual this turned out to be a bit less evident than I thought it would be.
The effect I wanted to achieve [...]]]></description>
			<content:encoded><![CDATA[<p>For a project I&#8217;m working on I thought it would be nice to give the user the possibility to use the full screen (e.g. full screen editing in iPhoto, slideshow in Preview, &#8230;). As usual this turned out to be a bit less evident than I thought it would be.</p>
<p>The effect I wanted to achieve is as follows. When the user selects the &#8220;Go Fullscreen&#8221; menu item, the screen would fade out to black and then fade in with the key window now occupying the full screen. Selecting &#8220;Go Fullscreen&#8221; again would fade out the screen to black and then fade in with the key window having its original size again. A small sample project with the solution presented in part I can be found at the end of this blog post.</p>
<h2>First approach:</h2>
<p>The NSView class has the following two methods which look very promising:</p>
<pre>- (BOOL)enterFullScreenMode:(NSScreen *)screen withOptions:(NSDictionary *)options</pre>
<p></p>
<p>and</p>
<pre>- (void)exitFullScreenModeWithOptions:(NSDictionary *)options</pre>
<p></p>
<p>The possible values that can be given to the options parameter is unfortunately somewhat limited (especially in Leopard 10.5). The biggest drawback in my opinion is that you can&#8217;t animate how the view takes over the full screen (e.g. through a fading effect like I wanted to achieve, growing/shrinking the view to/from fullscreen, &#8230;). So I need some extra code to fade in and out.<br />
The following code snippet presents the &#8216;core&#8217; of going full screen and returning back.</p>
<style type="text/css">
	@import "/blog/wp-content/themes/wp-andreas01/coloring-halloween.css";
</style>
<pre class="textmate-source coloring"><span class="source source_objc"><span class="keyword keyword_control keyword_control_c">if</span> (<span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span>aView <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">isInFullScreenMode</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span> == <span class="constant constant_language constant_language_objc">NO</span>)
<span class="meta meta_block meta_block_c">{
    <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="variable variable_language variable_language_objc">self</span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">fadeOut</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>;
    <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span>aView <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">enterFullScreenMode<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span><span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="support support_class support_class_cocoa">NSScreen</span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">mainScreen</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>
                   <span class="support support_function support_function_any-method support_function_any-method_name-of-parameter support_function_any-method_name-of-parameter_objc">withOptions<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span><span class="constant constant_language constant_language_objc">nil</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>;
    <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="variable variable_language variable_language_objc">self</span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">fadeIn</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>;
}</span>
<span class="keyword keyword_control keyword_control_c">else</span>
<span class="meta meta_block meta_block_c">{
    <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="variable variable_language variable_language_objc">self</span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">fadeOut</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>;
    <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span>aView <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">exitFullScreenModeWithOptions<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span><span class="constant constant_language constant_language_objc">nil</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>;
    <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="variable variable_language variable_language_objc">self</span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">fadeIn</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>;
}</span> <span class="commentt comment_block comment_block_c"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">/*</span> end if <span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">*/</span></span></span></pre>
<p></p>
<p>Apple calls this the kiosk mode and has recently released some extra info which might be useful if you&#8217;re using Snow Leopard. This documentation can be found <a href="http://developer.apple.com/mac/library/technotes/KioskMode/Introduction/Introduction.html">here</a>.</p>
<h3>Fading the screen</h3>
<p>Apple has some documentation on how to achieve the fading effect I wanted and it can be found at this <a href="http://developer.apple.com/mac/library/documentation/GraphicsImaging/Conceptual/QuartzDisplayServicesConceptual/Articles/FadeEffects.html#//apple_ref/doc/uid/TP40004232-SW1">URL</a>. The code is quite simple as can be seen here.</p>
<p><!-- 	@import "/blog/wp-content/themes/wp-andreas01/coloring-cocoacrumbs.css"; --></p>
<pre class="textmate-source coloring"><span class="source source_objc">CGDisplayFadeReservationToken    token;  <span class="commentt comment_block comment_block_c"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">/*</span> Fade out/in token <span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">*/</span></span>

...

- (<span class="storage storage_type storage_type_c">void</span>)fadeOut
<span class="meta meta_block meta_block_c">{
    CGDisplayErr    err;

    err =<span class="meta meta_function-call meta_function-call_c"><span class="punctuation punctuation_whitespace punctuation_whitespace_function-call punctuation_whitespace_function-call_leading punctuation_whitespace_function-call_leading_c"> </span><span class="support support_function support_function_any-method support_function_any-method_c">CGAcquireDisplayFadeReservation</span>(</span><span class="constant constant_other constant_other_variable constant_other_variable_mac-classic constant_other_variable_mac-classic_c">kCGMaxDisplayReservationInterval</span>,
                                          &amp;token);
    <span class="keyword keyword_control keyword_control_c">if</span><span class="meta meta_initialization meta_initialization_c"> <span class="punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_c">(</span></span>err == <span class="constant constant_other constant_other_variable constant_other_variable_mac-classic constant_other_variable_mac-classic_c">kCGErrorSuccess</span>)
    <span class="meta meta_block meta_block_c">{
<span class="meta meta_function-call meta_function-call_c"><span class="punctuation punctuation_whitespace punctuation_whitespace_function-call punctuation_whitespace_function-call_leading punctuation_whitespace_function-call_leading_c">        </span><span class="support support_function support_function_any-method support_function_any-method_c">CGDisplayFade</span>(</span>token,
                      <span class="constant constant_numeric constant_numeric_c">1.5</span>,
                      <span class="constant constant_other constant_other_variable constant_other_variable_mac-classic constant_other_variable_mac-classic_c">kCGDisplayBlendNormal</span>,
                      <span class="constant constant_other constant_other_variable constant_other_variable_mac-classic constant_other_variable_mac-classic_c">kCGDisplayBlendSolidColor</span>,
                      <span class="constant constant_numeric constant_numeric_c">0</span>,
                      <span class="constant constant_numeric constant_numeric_c">0</span>,
                      <span class="constant constant_numeric constant_numeric_c">0</span>,
                      <span class="constant constant_language constant_language_c">TRUE</span>);
    }</span> <span class="commentt comment_block comment_block_c"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">/*</span> end if <span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">*/</span></span>
}</span> <span class="commentt comment_block comment_block_c"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">/*</span> end fadeOut <span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">*/</span></span>

- (<span class="storage storage_type storage_type_c">void</span>)fadeIn
<span class="meta meta_block meta_block_c">{
    CGDisplayErr    err;

    err =<span class="meta meta_function-call meta_function-call_c"><span class="punctuation punctuation_whitespace punctuation_whitespace_function-call punctuation_whitespace_function-call_leading punctuation_whitespace_function-call_leading_c"> </span><span class="support support_function support_function_any-method support_function_any-method_c">CGDisplayFade</span>(</span>token,
                        <span class="constant constant_numeric constant_numeric_c">1.5</span>,
                        <span class="constant constant_other constant_other_variable constant_other_variable_mac-classic constant_other_variable_mac-classic_c">kCGDisplayBlendSolidColor</span>,
                        <span class="constant constant_other constant_other_variable constant_other_variable_mac-classic constant_other_variable_mac-classic_c">kCGDisplayBlendNormal</span>,
                        <span class="constant constant_numeric constant_numeric_c">0</span>,
                        <span class="constant constant_numeric constant_numeric_c">0</span>,
                        <span class="constant constant_numeric constant_numeric_c">0</span>,
                        <span class="constant constant_language constant_language_c">TRUE</span>);
    <span class="keyword keyword_control keyword_control_c">if</span><span class="meta meta_initialization meta_initialization_c"> <span class="punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_c">(</span></span>err == <span class="constant constant_other constant_other_variable constant_other_variable_mac-classic constant_other_variable_mac-classic_c">kCGErrorSuccess</span>)
    <span class="meta meta_block meta_block_c">{
<span class="meta meta_function-call meta_function-call_c"><span class="punctuation punctuation_whitespace punctuation_whitespace_function-call punctuation_whitespace_function-call_leading punctuation_whitespace_function-call_leading_c">        </span><span class="support support_function support_function_any-method support_function_any-method_c">CGReleaseDisplayFadeReservation</span>(</span>token);
    }</span> <span class="commentt comment_block comment_block_c"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">/*</span> end if <span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">*/</span></span>
}</span> <span class="commentt comment_block comment_block_c"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">/*</span> end fadeIn <span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">*/</span></span></span></pre>
<p></p>
<h3>Drawbacks of this approach</h3>
<p>As it turns out, there are a few drawbacks with the combination of both techniques which made this a less than perfect solution for me:</p>
<ul> The enterFullScreenMode and enterFullScreenMode methods as they are implemented in Leopard (OS X 10.5) hide the dock and menubar for you but no means to show the menubar again when the mouse hits the top of the screen (Snow Leopard fixes this).</p>
<p>CGDisplayFade() unfortunately fades all displays connected to your Mac, which isn&#8217;t what I wanted (only the screen where the window is located should go through the fade in/out cycle).</ul>
<p>I made a small project that displays a photo of Monument Valley I took the week after WWDC &#8216;09. Using command-F you can toggle back and forth to full screen mode via a fade out to black and fade in again.</p>
<p>In part II, I&#8217;ll present another approach on how to achieve the wanted effect in an attempt to avoid the above mentioned drawbacks.</p>
<p>Here is project using the above code: <a href='http://www.cocoacrumbs.com/blog/wp-content/uploads/2009/10/gofullscreen-part-i.zip'>gofullscreen-part-i.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.cocoacrumbs.com/blog/?feed=rss2&amp;p=116</wfw:commentRss>
		</item>
		<item>
		<title>Yellow or Orange breakpoints in Xcode</title>
		<link>http://www.cocoacrumbs.com/blog/?p=114</link>
		<comments>http://www.cocoacrumbs.com/blog/?p=114#comments</comments>
		<pubDate>Wed, 20 May 2009 19:10:22 +0000</pubDate>
		<dc:creator>kvnieuwe</dc:creator>
		
		<category><![CDATA[Development tools]]></category>

		<guid isPermaLink="false">http://www.cocoacrumbs.com/blog/?p=114</guid>
		<description><![CDATA[Way too often when I start debugging, the breakpoints I&#8217;d set suddenly change from their normal bright blue into orange (like in the screenshot below) and the debugger never stopped at all where I wanted making debugging a frustrating experience.

Sometimes cleaning all targets and rebuilding helped to bring back my breakpoints but that workaround didn&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>Way too often when I start debugging, the breakpoints I&#8217;d set suddenly change from their normal bright blue into orange (like in the screenshot below) and the debugger never stopped at all where I wanted making debugging a frustrating experience.</p>
<div style="text-align:center;"><img src="http://www.cocoacrumbs.com/blog/wp-content/uploads/2009/05/orangebreakpoints.png" alt="OrangeBreakpoints.png" border="0" width="573" height="361" /></div>
<p>Sometimes cleaning all targets and rebuilding helped to bring back my breakpoints but that workaround didn&#8217;t always work for me and after a while they turned back into orange. Searching around a bit there seems to be a workaround that actually works (at least for me). Go into the Xcode preferences, select the debugging tab and remove the check on &#8220;Load symbols lazily&#8221;.</p>
<div style="text-align:center;"><img src="http://www.cocoacrumbs.com/blog/wp-content/uploads/2009/05/loadlazily.png" alt="LoadLazily.png" border="0" width="580" height="404" /></div>
<p>That did it for me.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cocoacrumbs.com/blog/?feed=rss2&amp;p=114</wfw:commentRss>
		</item>
		<item>
		<title>Layer Backed Views and improving drawing speed</title>
		<link>http://www.cocoacrumbs.com/blog/?p=106</link>
		<comments>http://www.cocoacrumbs.com/blog/?p=106#comments</comments>
		<pubDate>Sat, 28 Feb 2009 22:30:18 +0000</pubDate>
		<dc:creator>kvnieuwe</dc:creator>
		
		<category><![CDATA[CoCoa]]></category>

		<guid isPermaLink="false">http://www.cocoacrumbs.com/blog/?p=106</guid>
		<description><![CDATA[A few evenings ago I watched the &#8220;Session 401 - Leveraging Cocoa&#8217;s Layer-Backed Views&#8221; from WWDC 2008 again. Watching it, I concluded that just adding this line of code for every NSView could give a nice speed boost in drawing the content of the NSView.

	@import "/blog/wp-content/themes/wp-andreas01/coloring-halloween.css";


[self setWantsLayer:YES];

To find out, I wrote a simple test application [...]]]></description>
			<content:encoded><![CDATA[<p>A few evenings ago I watched the &#8220;Session 401 - Leveraging Cocoa&#8217;s Layer-Backed Views&#8221; from WWDC 2008 again. Watching it, I concluded that just adding this line of code for every NSView could give a nice speed boost in drawing the content of the NSView.</p>
<style type="text/css">
	@import "/blog/wp-content/themes/wp-andreas01/coloring-halloween.css";
</style>
<p><body>
<pre class="textmate-source coloring"><span class="source source_objc"><span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="variable variable_language variable_language_objc">self</span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">setWantsLayer<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span><span class="constant constant_language constant_language_objc">YES</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>;</span></pre>
<p></body></p>
<p>To find out, I wrote a simple test application with 2 NSView&#8217;s overlaying each other. The view in the back would show a random NSBezierPath while the view on top would simply move a cursor line from left to right (very similar to what you would find in an audio editing application).</p>
<div style="text-align:center;"><img src="http://www.cocoacrumbs.com/blog/wp-content/uploads/2009/02/layerbackedviewapp1.png" alt="layerbackedviewapp1.png" border="0" width="580" height="480" /></div>
<p>A simple checkbox allows to switch on and off the layers for the NSView. A simple CPU load measurement is part of the application (simply the ratio between the cpu time spend in the application and the real time itself).</p>
<p>To let the CPU sweat, the cursor line is updated every 10 milliseconds. As a result the underlaying NSView representing the &#8216;wavefile&#8217; is forced to be redrawn also. Since I don&#8217;t take care of the rectangle which needs to be updated, the full view is simply redrawn which puts a huge burden on the CPU.</p>
<p>On my MBP, dual core 2.5 GHz with a GeForce 8600M GT GPU this results in an average of 30% CPU load. When I now switch on the layer for every view, this is halved to 15%. This seems a nice speed boost for just one line of code to me.</p>
<p>Now the caveat. This only seems to work well on Mac&#8217;s which have a real GPU. Weird enough, testing the same application on a Mac Mini (dual Core 2Ghz but using the GMA950 Intel integrated graphics chip), the CPU load on the Mac Mini was only 10% <strong>without</strong> the layer, rising to 15% when I switched the layer on. So your mileage may vary&#8230;</p>
<p>And here is the small test project: <a href="http://www.cocoacrumbs.com/blog/wp-content/uploads/2009/02/layeredbackviews.zip" title="layeredBackViews.zip">layeredBackViews.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.cocoacrumbs.com/blog/?feed=rss2&amp;p=106</wfw:commentRss>
		</item>
		<item>
		<title>Switching spelling languages</title>
		<link>http://www.cocoacrumbs.com/blog/?p=96</link>
		<comments>http://www.cocoacrumbs.com/blog/?p=96#comments</comments>
		<pubDate>Sat, 27 Dec 2008 22:09:49 +0000</pubDate>
		<dc:creator>kvnieuwe</dc:creator>
		
		<category><![CDATA[CoCoa]]></category>

		<guid isPermaLink="false">http://www.cocoacrumbs.com/blog/?p=96</guid>
		<description><![CDATA[If you&#8217;re like me, then you probably write one email in language X and another one in language Y and you&#8217;re getting tired of always switching the spell checker language to stop every word being underlined in red. That means pressing command + shift + &#8220;:&#8221;, selecting the correct language and then close the spell [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re like me, then you probably write one email in language X and another one in language Y and you&#8217;re getting tired of always switching the spell checker language to stop every word being underlined in red. That means pressing command + shift + &#8220;:&#8221;, selecting the correct language and then close the spell check window since it consumes precious screen real estate.</p>
<p>So of to Google to find a simple utility which could switch languages faster and a bit more user friendly. Disappointingly, I couldn&#8217;t find any. The closest I found (although I have to admit I didn&#8217;t search very long) was using a <a href="http://forums.macosxhints.com/showthread.php?t=26835">applescript on MacOSXhints</a>.</p>
<p>Having a bit of free time during the Christmas festive season, I decided to make such a utility myself. This shouldn&#8217;t be hard.</p>
<p>I first tried if I could achieve something by using the <strong>NSSpellChecker</strong> API. I had some hopes that I could set my preferred language system wide by using this API. However it quickly became clear that making any changes using the NSSpellChecker API stayed local to my own application and that I couldn&#8217;t use this API to change the language of e.g. mail.app. Bummer.</p>
<p>So I took a look again at the applescript solution and decided to make a standalone CoCoa application around it. As it turned out, this introduced some new problems.</p>
<p>The applescript solution as presented in the MacOSXhints forum hardcodes the 2 languages you want to switch to and you always need run the applescript which seemed hardly a user improvement to me. What I wanted was a small utility that nested itself in the status bar allowing to quickly switch to another language using a drop down menu. To make it a bit more user friendly, the last 2 languages I switched to, would automatically become the first 2 entries in the menu.</p>
<p><img src="http://www.cocoacrumbs.com/blog/wp-content/uploads/2008/12/spellswitcherutility.png" alt="spellSwitcherUtility.png" border="0" width="580" height="383" /></p>
<p>The first problem I encountered was the strange difference between the display names of the languages as they were returned by OS X and the shown languages in the spelling window.</p>
<p><img src="http://www.cocoacrumbs.com/blog/wp-content/uploads/2008/12/displaynames.png" alt="displayNames.png" border="0" width="580" height="284" /></p>
<p>For the applescript to work correctly, you really need to tell the popup menu to select e.g. &#8220;Australian English&#8221; instead of &#8220;English (Australia)&#8221;. A simple solution could be to use a simple lookup table. However that would open another can of worms. Depending on the language you are using OS X, the name of language in use will be localized to your preferred language. E.g &#8220;Australian English&#8221; would become &#8220;Australisch Engels&#8221; in Dutch. To make it even more fun. Suppose you&#8217;re writing an email using the Dutch language setting of OS X then you would indeed see the Dutch localized display name (&#8221;Australisch Engels&#8221;). However, open the spelling window in e.g. Xcode and you will see the English display name (&#8221;Australian English&#8221;) simply because Xcode hasn&#8217;t been localized for Dutch. Trying to solve this becomes a small nightmare if you want to support a lot of languages.</p>
<p>I found a rather simple workaround for this. Looking more closely to the menu in the above screenshot, you&#8217;ll see that the order of the languages stays the same. If I select item 1, I will always select &#8220;Australian English&#8221; no matter what language my OS X is running at that moment.</p>
<p>Another [related] problem then pops up. The applescript looked for a window with the title &#8220;Spelling and Grammar&#8221;. This is fine when you only use the English version of OS X, but in other languages, this window gets a localized name and the applescript doesn&#8217;t work anymore. Below you can see the same window for Dutch, English, French and German (the 4 most used languages in Belgium, in alphabetical order).</p>
<p><img src="http://www.cocoacrumbs.com/blog/wp-content/uploads/2008/12/spelling-en-grammatica.png" alt="Spelling en grammatica.png" border="0" width="580" height="294" /></p>
<p><img src="http://www.cocoacrumbs.com/blog/wp-content/uploads/2008/12/spelling-and-grammar.png" alt="Spelling and Grammar.png" border="0" width="580" height="294" /></p>
<p><img src="http://www.cocoacrumbs.com/blog/wp-content/uploads/2008/12/orthographe-et-grammaire.png" alt="Orthographe et grammaire.png" border="0" width="580" height="294" /></p>
<p><img src="http://www.cocoacrumbs.com/blog/wp-content/uploads/2008/12/rechtschreibung-und-grammatik.png" alt="Rechtschreibung und Grammatik.png" border="0" width="580" height="294" /></p>
<p>So I modified the applescript to look for one of those windows and if one of them exist to perform the click on the popup menu, select the wanted language and close the window again.</p>
<p><strong>Important:</strong> If the application doesn&#8217;t work, check in System Preferences -> Universal Access if support for assistive devices is allowed. Make sure that the checkbox for &#8220;Enable access for assistive devices&#8221; is checked.</p>
<p><img src="http://www.cocoacrumbs.com/blog/wp-content/uploads/2008/12/assistivedevice.png" alt="AssistiveDevice.png" border="0" width="580" height="524" /></p>
<p>You can download a small Xcode project (Leopard only) which should work fine for Dutch, English, French and German localized versions of OS X. It should be straightforward to add any language you want.</p>
<p>This small tool is certainly not going to win any beauty contests (using applescript means that you will see the spell checker window open and close again which is a bit annoying) but it does get the job done for me.</p>
<p>Xcode project can be downloaded here: <a href="http://www.cocoacrumbs.com/blog/wp-content/uploads/2008/12/spellingswitcherproject.zip" title="spellingSwitcherProject.zip">spellingSwitcherProject.zip</a><br />
A prebuilt application can be downloaded here: <a href="http://www.cocoacrumbs.com/blog/wp-content/uploads/2008/12/spellingswitcherapplication.zip" title="spellingSwitcherApplication.zip">spellingSwitcherApplication.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.cocoacrumbs.com/blog/?feed=rss2&amp;p=96</wfw:commentRss>
		</item>
		<item>
		<title>Shared/Dynamic libraries in OS X</title>
		<link>http://www.cocoacrumbs.com/blog/?p=83</link>
		<comments>http://www.cocoacrumbs.com/blog/?p=83#comments</comments>
		<pubDate>Thu, 11 Dec 2008 20:42:54 +0000</pubDate>
		<dc:creator>kvnieuwe</dc:creator>
		
		<category><![CDATA[CoCoa]]></category>

		<category><![CDATA[OS X]]></category>

		<guid isPermaLink="false">http://www.cocoacrumbs.com/blog/?p=83</guid>
		<description><![CDATA[A while ago I struggled with the problem of building a shared library (also known as dynamic library), let it link to a GUI build on top of it and let it be part of a clickable application. There doesn&#8217;t seems to be much information on the Internet, so here&#8217;s my story on how I [...]]]></description>
			<content:encoded><![CDATA[<p>A while ago I struggled with the problem of building a shared library (also known as dynamic library), let it link to a GUI build on top of it and let it be part of a clickable application. There doesn&#8217;t seems to be much information on the Internet, so here&#8217;s my story on how I achieved this using a very simple example.</p>
<h3>The completed application</h3>
<p>The final application will be a very simple GUI converter where you enter an angle in degrees (instead of the more usual radian) and let it calculate the sine and cosine of that angle. Calculating the sine and cosine will be done by code in a minimal mathematical shared library (note that the sin and cos functions provided by the C math library expects input in radian not in degrees, thats why I make my own small mathematical library).</p>
<p><img src="http://www.cocoacrumbs.com/blog/wp-content/uploads/2008/12/sharedlibexamplefinishedapplication.png" alt="sharedLibExampleFinishedApplication.png" border="0" width="580" height="307" /></p>
<h3>My Mathematical library</h3>
<p>Well, as you can guess, the code is straightforward. For the CoCoa project, we&#8217;ll have to keep the header file so that we can distribute it together with our library. The actual source code doesn&#8217;t have to be present in your project since you&#8217;re going to link against the library.<br />
So, here&#8217;s the header file:</p>
<style type="text/css">
	@import "/blog/wp-content/themes/wp-andreas01/coloring-halloween.css";
</style>
<p><body>
<pre class="textmate-source coloring"><span class="source source_objc"><span class="commentt comment_line comment_line_double-slash comment_line_double-slash_c++"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">//</span>
</span><span class="commentt comment_line comment_line_double-slash comment_line_double-slash_c++"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">//</span>  myMathLibrary.h
</span><span class="commentt comment_line comment_line_double-slash comment_line_double-slash_c++"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">//</span>  sharedLibsExample
</span><span class="commentt comment_line comment_line_double-slash comment_line_double-slash_c++"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">//</span>
</span><span class="commentt comment_line comment_line_double-slash comment_line_double-slash_c++"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">//</span>  Created by Koenraad Van Nieuwenhove on 06/12/08.
</span><span class="commentt comment_line comment_line_double-slash comment_line_double-slash_c++"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">//</span>  Copyright 2008 CoCoa Crumbs. All rights reserved.
</span><span class="commentt comment_line comment_line_double-slash comment_line_double-slash_c++"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">//</span>
</span>
<span class="storage storage_type storage_type_c">float</span><span class="meta meta_function meta_function_c"><span class="punctuation punctuation_whitespace punctuation_whitespace_function punctuation_whitespace_function_leading punctuation_whitespace_function_leading_c"> </span><span class="entity entity_name entity_name_function entity_name_function_c">sine</span><span class="meta meta_parens meta_parens_c">(<span class="storage storage_type storage_type_c">float</span> angleInDegrees)</span>;</span>
<span class="storage storage_type storage_type_c">float</span><span class="meta meta_function meta_function_c"><span class="punctuation punctuation_whitespace punctuation_whitespace_function punctuation_whitespace_function_leading punctuation_whitespace_function_leading_c"> </span><span class="entity entity_name entity_name_function entity_name_function_c">cosine</span><span class="meta meta_parens meta_parens_c">(<span class="storage storage_type storage_type_c">float</span> angleInDegrees)</span>;</span>
</span></pre>
<p></body></p>
<p>And here&#8217;s the implementation:</p>
<style type="text/css">
	@import "/blog/wp-content/themes/wp-andreas01/coloring-halloween.css";
</style>
<p><body>
<pre class="textmate-source coloring"><span class="source source_c"><span class="commentt comment_line comment_line_double-slash comment_line_double-slash_c++"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">//</span>
</span><span class="commentt comment_line comment_line_double-slash comment_line_double-slash_c++"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">//</span>  myMathLibrary.c
</span><span class="commentt comment_line comment_line_double-slash comment_line_double-slash_c++"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">//</span>  sharedLibsExample
</span><span class="commentt comment_line comment_line_double-slash comment_line_double-slash_c++"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">//</span>
</span><span class="commentt comment_line comment_line_double-slash comment_line_double-slash_c++"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">//</span>  Created by Koenraad Van Nieuwenhove on 06/12/08.
</span><span class="commentt comment_line comment_line_double-slash comment_line_double-slash_c++"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">//</span>  Copyright 2008 CoCoa Crumbs. All rights reserved.
</span><span class="commentt comment_line comment_line_double-slash comment_line_double-slash_c++"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">//</span>
</span><span class="meta meta_preprocessor meta_preprocessor_c meta_preprocessor_c_include">#<span class="keyword keyword_control keyword_control_import keyword_control_import_include keyword_control_import_include_c">include</span> <span class="string string_quoted string_quoted_double string_quoted_double_include string_quoted_double_include_c"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_c">"</span>myMathLibrary.h<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_c">"</span></span></span>
<span class="meta meta_preprocessor meta_preprocessor_c meta_preprocessor_c_include">#<span class="keyword keyword_control keyword_control_import keyword_control_import_include keyword_control_import_include_c">include</span> <span class="string string_quoted string_quoted_other string_quoted_other_lt-gt string_quoted_other_lt-gt_include string_quoted_other_lt-gt_include_c"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_c">&lt;</span>math.h<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_c">&gt;</span></span></span>

<span class="storage storage_type storage_type_c">float</span><span class="meta meta_function meta_function_c"><span class="punctuation punctuation_whitespace punctuation_whitespace_function punctuation_whitespace_function_leading punctuation_whitespace_function_leading_c"> </span><span class="entity entity_name entity_name_function entity_name_function_c">convertToRadian</span><span class="meta meta_parens meta_parens_c">(<span class="storage storage_type storage_type_c">float</span> angleInDegrees)</span>
<span class="meta meta_block meta_block_c">{
    <span class="keyword keyword_control keyword_control_c">return</span> (angleInDegrees*<span class="constant constant_numeric constant_numeric_c">3.14159265</span>)/<span class="constant constant_numeric constant_numeric_c">180</span>;
}</span></span> <span class="commentt comment_block comment_block_c"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">/*</span> end convertToRadian <span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">*/</span></span>

<span class="storage storage_type storage_type_c">float</span><span class="meta meta_function meta_function_c"><span class="punctuation punctuation_whitespace punctuation_whitespace_function punctuation_whitespace_function_leading punctuation_whitespace_function_leading_c"> </span><span class="entity entity_name entity_name_function entity_name_function_c">sine</span><span class="meta meta_parens meta_parens_c">(<span class="storage storage_type storage_type_c">float</span> angleInDegrees)</span>
<span class="meta meta_block meta_block_c">{
    <span class="keyword keyword_control keyword_control_c">return</span><span class="punctuation punctuation_whitespace punctuation_whitespace_support punctuation_whitespace_support_function punctuation_whitespace_support_function_leading punctuation_whitespace_support_function_leading_c"> </span><span class="support support_function support_function_C99 support_function_C99_c">sin</span>(<span class="meta meta_function-call meta_function-call_c"><span class="support support_function support_function_any-method support_function_any-method_c">convertToRadian</span>(</span>angleInDegrees));
}</span></span> <span class="commentt comment_block comment_block_c"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">/*</span> end sine <span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">*/</span></span>

<span class="storage storage_type storage_type_c">float</span><span class="meta meta_function meta_function_c"><span class="punctuation punctuation_whitespace punctuation_whitespace_function punctuation_whitespace_function_leading punctuation_whitespace_function_leading_c"> </span><span class="entity entity_name entity_name_function entity_name_function_c">cosine</span><span class="meta meta_parens meta_parens_c">(<span class="storage storage_type storage_type_c">float</span> angleInDegrees)</span>
<span class="meta meta_block meta_block_c">{
    <span class="keyword keyword_control keyword_control_c">return</span><span class="punctuation punctuation_whitespace punctuation_whitespace_support punctuation_whitespace_support_function punctuation_whitespace_support_function_leading punctuation_whitespace_support_function_leading_c"> </span><span class="support support_function support_function_C99 support_function_C99_c">cos</span>(<span class="meta meta_function-call meta_function-call_c"><span class="support support_function support_function_any-method support_function_any-method_c">convertToRadian</span>(</span>angleInDegrees));
}</span></span> <span class="commentt comment_block comment_block_c"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">/*</span> end cosine <span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">*/</span></span>
</span></pre>
<p></body></p>
<h3>Building the library</h3>
<p>Instead of using the Xcode IDE, I simply compile and build the library from the command line in a terminal (as is often the case when you would compile an open source library from e.g. MacPorts). To do this, I placed the following commands in a [bash] shell script. Lets call this script <strong>buildSharedLibrary.sh</strong> To execute the bash shell script you&#8217;ll need to open a terminal, navigate to the directory containing the source code and the shell script. You then run the shell script like this:<br />
    <strong>. ./buildSharedLibrary.sh</strong><br />
(Note that the dots really need to be there!!!)</p>
<style type="text/css">
	@import "/blog/wp-content/themes/wp-andreas01/coloring-halloween.css";
</style>
<p><body>
<pre class="textmate-source coloring"><span class='linenum'>    1</span> <span class="source source_shell">gcc -arch i386 -arch ppc -c myMathLibrary.c
<span class='linenum'>    2</span>
<span class='linenum'>    3</span> gcc -arch i386 -arch ppc \
<span class='linenum'>    4</span>     -dynamiclib \
<span class='linenum'>    5</span>     -o myMathLibrary.dylib \
<span class='linenum'>    6</span>     myMathLibrary.o \
<span class='linenum'>    7</span>     -install_name @executable_path/myLibs/myMathLibrary.dylib
</span><span class='linenum'>    8</span> </pre>
<p></body></p>
<p><strong>Line 1</strong> simply compiles and assembles the <strong>myMathLibrary.c</strong> file into an object file. Because I used the <strong>-c</strong> command line option it stops there and it doesn&#8217;t try to link (if this command line option wasn&#8217;t there you would see an error complaining that the main function is missing). So next to our source code files, you&#8217;ll now find a new file named <strong>myMathLibrary.o</strong><br />
The <strong>-arch i386</strong> and <strong>-arch ppc</strong> command line options are there to tell the compiler to build for both the Intel and PowerPC architectures. The GCC tool chain is smart enough to mix both architectures in one object file. If you want to build for PowerPC only then you can drop the <strong>-arch 386</strong> switch of course.</p>
<p><strong>Lines 3 to 7</strong> are actually one line but I split it over several lines (using the \ character) for better readability. Lets go over it line by line.<br />
<strong>Line 3</strong> just says again that the GCC tool chain has to do its magic for both Intel and PowerPC architectures.<br />
<strong>Line 4</strong> instructs the GCC tool chain that we want a dynamic library (confusingly also [and maybe better] known as a shared library).<br />
<strong>Line 5</strong> tells the GCC tool chain that the resulting output filename has to be <strong>myMathLibrary.dylib</strong><br />
<strong>Line 6</strong> is our object file that resulted from the compilation on line 1. For this simple example I only have one object file. However, you can specify plenty of object files here. All of them will then end up in the shared library.<br />
<strong>Line 7</strong> was the tricky one and the main reason why I write this blog entry. We&#8217;ll see why this is needed later.</p>
<p>So, if everything went well, you should now have your shared library ready to be used in your application.</p>
<h3>The Xcode project</h3>
<p><img src="http://www.cocoacrumbs.com/blog/wp-content/uploads/2008/12/sharedlibexampleproject.png" alt="sharedLibExampleProject.png" border="0" width="580" height="368" /></p>
<p>As can be seen in the above screenshot, the project doesn&#8217;t look that much different compared to what you are used to. Instead of the <strong>myMathLibrary.c</strong> source code you add your compiled library to the project. Compiling and linking your application will go fine.</p>
<h3>Running the application</h3>
<p>When you try to run the application, you will be unpleasantly surprised by this:</p>
<p><img src="http://www.cocoacrumbs.com/blog/wp-content/uploads/2008/12/sharedlibexamplerunningerror.png" alt="sharedLibExampleRunningError.png" border="0" width="580" height="247" /></p>
<p>Clearly, the application had trouble to find our library. The reason for this is quite simple. We build the library ourselves without Xcode, so we need to instruct Xcode what to do with it, which in this case means copying the library to a suitable place so that the application can find it. If we would have stayed with our source code file, Xcode would have compiled it and taken care that the resulting object code ends up in the application. Which leaves us with the question, where do we want to copy our library to?</p>
<p>For this small application I prefer to put the shared library inside the application itself (another option could have been to put it somewhere in the frameworks directory). If you control click on the application icon, you can see it&#8217;s contents as shown below.</p>
<p><img src="http://www.cocoacrumbs.com/blog/wp-content/uploads/2008/12/sharedlibexampleshowpackage.png" alt="sharedLibExampleShowPackage.png" border="0" width="580" height="168" /></p>
<p><img src="http://www.cocoacrumbs.com/blog/wp-content/uploads/2008/12/sharedlibexamplepackage01.png" alt="sharedLibExamplePackage01.png" border="0" width="580" height="200" /></p>
<p>As you might already know, an application is nothing more than a directory with an application icon and with a different behavior when you double click on it.<br />
As you can see, the raw executable is located in the path <strong>/Users/koen/Desktop/sharedLibsExample.app/Contents/MacOS/</strong>.<br />
We can now use Xcode to copy our library inside the application bundle by simply adding a new build phase. So we go back to our Xcode project and click on the <strong>Targets</strong> line where we see our <strong>sharedLibsExample</strong>. Which we double click also. Now we see the 3 build phases which Xcode already made for itself.</p>
<p><img src="http://www.cocoacrumbs.com/blog/wp-content/uploads/2008/12/sharedlibexampleaddbuildphase.png" alt="sharedLibExampleAddBuildPhase.png" border="0" width="580" height="135" /></p>
<p>So, we now simply add a new Copy Files Build Phase:</p>
<p><img src="http://www.cocoacrumbs.com/blog/wp-content/uploads/2008/12/sharedlibexampleaddbuildphasemylibs.png" alt="sharedLibExampleAddBuildPhaseMyLibs.png" border="0" width="580" height="206" /></p>
<p>By default, the <strong>Destination</strong> popup will show <strong>Resources</strong>. I selected <strong>Executables</strong> for this project. Secondly, I added an [optional] path, name <strong>myLibs</strong>.<br />
What&#8217;s going to happen now, is that, when Xcode fires this build phase, it will copy all the files which I dragged into this build phase into a folder called <strong>myLibs</strong> which will be next to my executable (that&#8217;s why I selected the <strong>Executables</strong> option from the popup menu, if I stayed with the default, the folder would have been created in the <strong>Resources</strong> folder of the bundle instead).<br />
The only thing that remains is dragging my library to this build phase:</p>
<p><img src="http://www.cocoacrumbs.com/blog/wp-content/uploads/2008/12/sharedlibexampleaddmylib.png" alt="sharedLibExampleAddMyLib.png" border="0" width="580" height="308" /></p>
<p>When you now build the application, Xcode will create a <strong>myLibs</strong> directory next to the executable and copy our shared library in that directory.<br />
Try running the application this time and you&#8217;ll see it now runs as expected.</p>
<h3>But why this install_name option?</h3>
<p>Remember that line 7 that I didn&#8217;t explain yet? Well, rebuild our library without the <strong>-install_name @executable_path/myLibs/myMathLibrary.dylib</strong> part and run it again. Strange enough, we get a very similar error.</p>
<p><img src="http://www.cocoacrumbs.com/blog/wp-content/uploads/2008/12/sharedlibexamplerunningagainerror.png" alt="sharedLibExampleRunningAgainError.png" border="0" width="580" height="202" /></p>
<p>If we look inside the application bundle, we see that the library is actually there. So what went wrong this time?</p>
<p><img src="http://www.cocoacrumbs.com/blog/wp-content/uploads/2008/12/sharedlibexamplepackage02.png" alt="sharedLibExamplePackage02.png" border="0" width="580" height="172" /></p>
<p>As it turns out, our library needs to specify some extra info for the linker. Basically it needs to tell the linker where it can be found by the main application. It&#8217;s the application who loads the shared library in RAM so that it can be executed. For this, the application needs to know where it can search for this library. To make matters a bit more difficult, our application can be located everywhere on your hard disk, so specifying a fixed path at build time is impossible. Let&#8217;s take a look again to line 7:</p>
<style type="text/css">
	@import "/blog/wp-content/themes/wp-andreas01/coloring-halloween.css";
</style>
<p><body>
<pre class="textmate-source coloring"<span class='linenum'>    7</span>     -install_name @executable_path/myLibs/myMathLibrary.dylib
</span></pre>
<p></body></p>
<p>On that line we see the mention of <strong>@executable_path/</strong> At runtime, this part will be translated to the path from root up to the executable inside the application bundle. In my case this would be <strong>/Users/koen/Desktop/sharedLibsExample.app/Contents/MacOS/</strong> To that path, we then add <strong>myLibs/myMathLibrary.dylib</strong>, so the resulting path is <strong>/Users/koen/Desktop/sharedLibsExample.app/Contents/MacOS/myLibs/myMathLibrary.dylib</strong> which is exactly the full path name where my library is located. If I would move my application to another place, the <strong>@executable_path/</strong> takes care that the path is adapted accordingly.<br />
When I now double click on my application icon, the application will search for my library (to be loaded in RAM) at <strong>/Users/koen/Desktop/sharedLibsExample.app/Contents/MacOS/myLibs/</strong>. Since I used <strong>@executable_path/myLibs/myMathLibrary.dylib</strong> when I build my library and Xcode copied my library in the <strong>myLibs</strong> directory, the application will find it there, load it RAM and execute my code.</p>
<h3>Problem solved.</h3>
<p>A sample project can be downloaded here: <a href='http://www.cocoacrumbs.com/blog/wp-content/uploads/2008/12/sharedlibsexample.zip'>sharedlibsexample</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.cocoacrumbs.com/blog/?feed=rss2&amp;p=83</wfw:commentRss>
		</item>
		<item>
		<title>A variation on NSLog()</title>
		<link>http://www.cocoacrumbs.com/blog/?p=69</link>
		<comments>http://www.cocoacrumbs.com/blog/?p=69#comments</comments>
		<pubDate>Thu, 13 Nov 2008 19:40:30 +0000</pubDate>
		<dc:creator>kvnieuwe</dc:creator>
		
		<category><![CDATA[CoCoa]]></category>

		<guid isPermaLink="false">http://www.cocoacrumbs.com/blog/?p=69</guid>
		<description><![CDATA[Using NSLog() is probably the easiest and most used [first line] debuggingtool. However, the output of NSLog() was not really to my liking and I thought it could be made more useful. The output of:

NSLog(@"%s : generated = %d", _cmd, generated);
looks typically like this:
2008-11-09 19:00:41.223 CCLog[219:10b] generate: : generated = 88
It shows the date and [...]]]></description>
			<content:encoded><![CDATA[<p>Using NSLog() is probably the easiest and most used [first line] debuggingtool. However, the output of NSLog() was not really to my liking and I thought it could be made more useful. The output of:</p>
<p><!-- 	@import "/blog/wp-content/themes/wp-andreas01/coloring-halloween.css"; --></p>
<pre class="textmate-source coloring"><span class="source source_objc"><span class="support support_function support_function_cocoa">NSLog</span>(<span class="string string_quoted string_quoted_double string_quoted_double_objc"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_objc">@"</span>%s : generated = %d<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_objc">"</span></span>, _cmd, generated);</span></pre>
<p>looks typically like this:</p>
<pre class="textmate-source coloring"><span class="text text_plain"><span class="meta meta_paragraph meta_paragraph_text">2008-11-09 19:00:41.223 CCLog[219:10b] generate: : generated = 88</span></span></pre>
<p>It shows the date and time (with milliseconds precision) and the name of the project before it shows the text I want to print out. In this case the called method and the value of an int.</p>
<p>My preferred output would be capable of doing this:<br />
1) Show on which thread CCLog() was called from.<br />
2) Show from which sourcecode file CCLog() was called from.<br />
3) Show the linenumber in the sourcecode file CCLog was called from.</p>
<p>My first preference might seem a bit weird but as a beginning developer I found it useful to have the possibility to quickly check if my code was running in the thread I intended to. CoCoa has the capability of giving a NSThread a name [on top of its threadnumber]. This can very easily be done like this:</p>
<p><!-- 	@import "/blog/wp-content/themes/wp-andreas01/coloring-halloween.css"; --></p>
<pre class="textmate-source coloring"><span class="source source_objc"><span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="support support_class support_class_cocoa">NSThread</span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">currentThread</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">name</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">];</span></span>
</span></pre>
<p>A bit of searching brought me to a blog-entry of  <a href="http://www.borkware.com/rants/agentm/mlog/">agentM</a> which describes his own implementation of a better NSLog(). In short, his implementation is a very nice example on the usage of variadic macros and the C preprocessor. Using the C preprocessor, It&#8217;s possible to write the CCLog() class method like this:</p>
<p><!-- 	@import "/blog/wp-content/themes/wp-andreas01/coloring-halloween.css"; --></p>
<pre class="textmate-source coloring"><span class="source source_objc"><span class="meta meta_preprocessor meta_preprocessor_macro meta_preprocessor_macro_c">#<span class="keyword keyword_control keyword_control_import keyword_control_import_define keyword_control_import_define_c">define</span> <span class="entity entity_name entity_name_function entity_name_function_preprocessor entity_name_function_preprocessor_c">CCLog</span>(s,...)                           <span class="punctuation punctuation_separator punctuation_separator_continuation punctuation_separator_continuation_c">\
</span>    <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span>CCLog <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">myLog<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span>__FILE__                      \
      <span class="support support_function support_function_any-method support_function_any-method_name-of-parameter support_function_any-method_name-of-parameter_objc">lineNumber<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span>__LINE__                      \
          <span class="support support_function support_function_any-method support_function_any-method_name-of-parameter support_function_any-method_name-of-parameter_objc">format<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span>(s), ##__VA_ARGS__</span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span></span></span></pre>
<p>The above CCLog macro expands to a class method call:</p>
<p><!-- 	@import "/blog/wp-content/themes/wp-andreas01/coloring-halloween.css"; --></p>
<pre class="textmate-source coloring"><span class="source source_objc"><span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span>CCLog <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">mylog<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span>__FILE__ <span class="support support_function support_function_any-method support_function_any-method_name-of-parameter support_function_any-method_name-of-parameter_objc">lineNumber<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span>__LINE__ <span class="support support_function support_function_any-method support_function_any-method_name-of-parameter support_function_any-method_name-of-parameter_objc">format<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span>...</span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>;</span></pre>
<p>At compile-time, the __FILE__ and __LINE__ arguments would be expanded to the filename and linenumber where CCLog() was called from just like I wanted. For those classes that have a methodname like &#8216;init&#8217; which appear quite often, having the filename in the log makes it easy to follow which &#8216;init&#8217; method from which implementation was called. The last argument is the string with our own text. Using the variadic macro (__VA_ARGS__) we can still format strings as we are used to for formating a NSString. E.g. the following is perfectly possible:</p>
<p><!-- 	@import "/blog/wp-content/themes/wp-andreas01/coloring-halloween.css"; --></p>
<pre class="textmate-source coloring"><span class="source source_objc"><span class="meta meta_function meta_function_c"><span class="entity entity_name entity_name_function entity_name_function_c">CCLog</span><span class="punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_c">(</span></span><span class="string string_quoted string_quoted_double string_quoted_double_objc"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_objc">@"</span>%s : generated = %d<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_objc">"</span></span>, _cmd, generated);</span></pre>
<p>As you can see, we can specify any number of parameters to format our textstring like we want. The processing of the variadic macro then happens like this:</p>
<p><!-- 	@import "/blog/wp-content/themes/wp-andreas01/coloring-halloween.css"; --></p>
<pre class="textmate-source coloring"><span class="source source_objc"><span class="meta meta_function meta_function_c"><span class="entity entity_name entity_name_function entity_name_function_c">va_start</span><span class="punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_c">(</span></span>listOfArguments, format);
formattedString = <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="support support_class support_class_cocoa">NSString</span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">alloc</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">initWithFormat<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span>format
                                         <span class="support support_function support_function_any-method support_function_any-method_name-of-parameter support_function_any-method_name-of-parameter_objc">arguments<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span>listOfArguments</span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>;
<span class="meta meta_function meta_function_c"><span class="entity entity_name entity_name_function entity_name_function_c">va_end</span><span class="punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_c">(</span></span>listOfArguments);</span></pre>
<p>The only other remaining problem is printing out the threadname. If the threadname is not set, then the threadnumber should be logged. Getting the threadname is pretty simple and can be done like this:</p>
<p><!-- 	@import "/blog/wp-content/themes/wp-andreas01/coloring-halloween.css"; --></p>
<pre class="textmate-source coloring"><span class="source source_objc"><span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="support support_class support_class_cocoa">NSThread</span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">currentThread</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">name</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">];</span></span>
</span></pre>
<p>Getting to show the threadnumber was less easy. NSThread provides a method to get its name but not its number. This can be bit problematic in those cases a thread doesn&#8217;t have a name. Asking the threadname of a thread which is not named simply returns nil. In that case I simply send the output of the currentThread class message of NSThread to a NSString. That output contains the threadnumber and can be extracted with a bit of string manipulation.</p>
<p>The output of CCLog() now looks like this with a threadnumber:</p>
<p><!-- 	@import "/blog/wp-content/themes/wp-andreas01/coloring-halloween.css"; --></p>
<pre class="textmate-source coloring"><span class="text text_plain"><span class="meta meta_paragraph meta_paragraph_text">Thread 1 | Foo.m[20] generate: : generated = 84</span></span></pre>
<p>The output of CCLog() now looks like this with a named thread:</p>
<p><!-- 	@import "/blog/wp-content/themes/wp-andreas01/coloring-halloween.css"; --></p>
<pre class="textmate-source coloring"><span class="text text_plain"><span class="meta meta_paragraph meta_paragraph_text">Foo Thread | Foo.m[22] generate: : generated = 84</span></span></pre>
<p>The full implementation of CCLog() can be found below and a small Xcode project can be downloaded at the end of this blogentry.</p>
<p>As a last remark, when you define the USE_NSLOG preprocessor macro, then the familiar NSLog() will be used instead of printf() to print out the message. This means that the date, time and project name will be added in front of the threadname, filename, linenumber and the content of the logstring. The output of the same CCLog() calls as above becomes:</p>
<p><!-- 	@import "/blog/wp-content/themes/wp-andreas01/coloring-halloween.css"; --></p>
<pre class="textmate-source coloring"><span class="text text_plain"><span class="meta meta_paragraph meta_paragraph_text">2008-11-09 20:37:59.177 CCLog[424:10b] Thread 1 | Foo.m[20] generate: : generated = 84
2008-11-09 20:37:59.178 CCLog[424:10b] Foo Thread | Foo.m[22] generate: : generated = 84</span></span></pre>
<p>The header file:</p>
<p><!-- 	@import "/blog/wp-content/themes/wp-andreas01/coloring-halloween.css"; --></p>
<pre class="textmate-source coloring"><span class="source source_objc"><span class="commentt comment_line comment_line_double-slash comment_line_double-slash_c++"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">//</span>
</span><span class="commentt comment_line comment_line_double-slash comment_line_double-slash_c++"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">//</span>  CCLog.h
</span><span class="commentt comment_line comment_line_double-slash comment_line_double-slash_c++"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">//</span>  gitVersions
</span><span class="commentt comment_line comment_line_double-slash comment_line_double-slash_c++"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">//</span>
</span><span class="commentt comment_line comment_line_double-slash comment_line_double-slash_c++"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">//</span>  Created by Koenraad Van Nieuwenhove on 26/08/08.
</span><span class="commentt comment_line comment_line_double-slash comment_line_double-slash_c++"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">//</span>  Copyright 2008 CoCoa Crumbs. All rights reserved.
</span><span class="commentt comment_line comment_line_double-slash comment_line_double-slash_c++"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">//</span>
</span><span class="meta meta_preprocessor meta_preprocessor_c meta_preprocessor_c_include">#<span class="keyword keyword_control keyword_control_import keyword_control_import_include keyword_control_import_include_c">import</span> <span class="string string_quoted string_quoted_other string_quoted_other_lt-gt string_quoted_other_lt-gt_include string_quoted_other_lt-gt_include_c"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_c">&lt;</span>Cocoa/Cocoa.h<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_c">&gt;</span></span></span>

<span class="commentt comment_line comment_line_double-slash comment_line_double-slash_c++"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">//</span> idea from http://www.borkware.com/rants/agentm/mlog/
</span>
<span class="meta meta_preprocessor meta_preprocessor_macro meta_preprocessor_macro_c">#<span class="keyword keyword_control keyword_control_import keyword_control_import_define keyword_control_import_define_c">define</span> <span class="entity entity_name entity_name_function entity_name_function_preprocessor entity_name_function_preprocessor_c">CCLog</span>(s,...)                           <span class="punctuation punctuation_separator punctuation_separator_continuation punctuation_separator_continuation_c">\
</span>    <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span>CCLog <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">myLog<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span>__FILE__                      \
      <span class="support support_function support_function_any-method support_function_any-method_name-of-parameter support_function_any-method_name-of-parameter_objc">lineNumber<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span>__LINE__                      \
          <span class="support support_function support_function_any-method support_function_any-method_name-of-parameter support_function_any-method_name-of-parameter_objc">format<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span>(s), ##__VA_ARGS__</span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span></span>

<span class="meta meta_interface-or-protocol meta_interface-or-protocol_objc"><span class="storage storage_type storage_type_objc"><span class="punctuation punctuation_definition punctuation_definition_storage punctuation_definition_storage_type punctuation_definition_storage_type_objc">@</span>interface</span> <span class="entity entity_name entity_name_type entity_name_type_objc">CCLog</span> <span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_other punctuation_definition_entity_other_inherited-class punctuation_definition_entity_other_inherited-class_objc">:</span> <span class="entity entity_other entity_other_inherited-class entity_other_inherited-class_objc">NSObject</span><span class="meta meta_divider meta_divider_objc">
</span><span class="meta meta_scope meta_scope_interface meta_scope_interface_objc"><span class="meta meta_block meta_block_c">{
}</span> 

<span class="meta meta_function meta_function_objc">+ <span class="meta meta_return-type meta_return-type_objc"><span class="punctuation punctuation_definition punctuation_definition_type punctuation_definition_type_objc">(</span><span class="storage storage_type storage_type_c">void</span><span class="punctuation punctuation_definition punctuation_definition_type punctuation_definition_type_objc">)</span><span class="entity entity_name entity_name_function entity_name_function_objc">myLog</span></span><span class="meta meta_argument-type meta_argument-type_objc"><span class="entity entity_name entity_name_function entity_name_function_name-of-parameter entity_name_function_name-of-parameter_objc"><span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span><span class="punctuation punctuation_definition punctuation_definition_type punctuation_definition_type_objc">(</span><span class="storage storage_type storage_type_c">char</span>*<span class="punctuation punctuation_definition punctuation_definition_type punctuation_definition_type_objc">)</span><span class="variable variable_parameter variable_parameter_function variable_parameter_function_objc">file</span></span>
   <span class="entity entity_name entity_name_function entity_name_function_name-of-parameter entity_name_function_name-of-parameter_objc">lineNumber</span><span class="meta meta_argument-type meta_argument-type_objc"><span class="entity entity_name entity_name_function entity_name_function_name-of-parameter entity_name_function_name-of-parameter_objc"><span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span><span class="punctuation punctuation_definition punctuation_definition_type punctuation_definition_type_objc">(</span><span class="storage storage_type storage_type_c">int</span><span class="punctuation punctuation_definition punctuation_definition_type punctuation_definition_type_objc">)</span><span class="variable variable_parameter variable_parameter_function variable_parameter_function_objc">lineNumber</span></span>
       <span class="entity entity_name entity_name_function entity_name_function_name-of-parameter entity_name_function_name-of-parameter_objc">format</span><span class="meta meta_argument-type meta_argument-type_objc"><span class="entity entity_name entity_name_function entity_name_function_name-of-parameter entity_name_function_name-of-parameter_objc"><span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span><span class="punctuation punctuation_definition punctuation_definition_type punctuation_definition_type_objc">(</span><span class="support support_class support_class_cocoa">NSString</span>*<span class="punctuation punctuation_definition punctuation_definition_type punctuation_definition_type_objc">)</span><span class="variable variable_parameter variable_parameter_function variable_parameter_function_objc">format</span></span>, ...;</span>

</span><span class="storage storage_type storage_type_objc"><span class="punctuation punctuation_definition punctuation_definition_storage punctuation_definition_storage_type punctuation_definition_storage_type_objc">@</span>end</span></span> <span class="commentt comment_block comment_block_c"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">/*</span> interface CCLog <span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">*/</span></span>
</span></pre>
<p>The implementation:</p>
<p><!-- 	@import "/blog/wp-content/themes/wp-andreas01/coloring-halloween.css"; --></p>
<pre class="textmate-source coloring"><span class="source source_objc"><span class="commentt comment_line comment_line_double-slash comment_line_double-slash_c++"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">//</span>
</span><span class="commentt comment_line comment_line_double-slash comment_line_double-slash_c++"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">//</span>  CCLog.m
</span><span class="commentt comment_line comment_line_double-slash comment_line_double-slash_c++"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">//</span>  gitVersions
</span><span class="commentt comment_line comment_line_double-slash comment_line_double-slash_c++"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">//</span>
</span><span class="commentt comment_line comment_line_double-slash comment_line_double-slash_c++"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">//</span>  Created by Koenraad Van Nieuwenhove on 26/08/08.
</span><span class="commentt comment_line comment_line_double-slash comment_line_double-slash_c++"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">//</span>  Copyright 2008 CoCoa Crumbs. All rights reserved.
</span><span class="commentt comment_line comment_line_double-slash comment_line_double-slash_c++"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">//</span>
</span><span class="meta meta_preprocessor meta_preprocessor_c meta_preprocessor_c_include">#<span class="keyword keyword_control keyword_control_import keyword_control_import_include keyword_control_import_include_c">import</span> <span class="string string_quoted string_quoted_double string_quoted_double_include string_quoted_double_include_c"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_c">"</span>CCLog.h<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_c">"</span></span></span>

<span class="meta meta_preprocessor meta_preprocessor_macro meta_preprocessor_macro_c">#<span class="keyword keyword_control keyword_control_import keyword_control_import_define keyword_control_import_define_c">define</span> <span class="entity entity_name entity_name_function entity_name_function_preprocessor entity_name_function_preprocessor_c">USE_NSLOG</span></span>

<span class="meta meta_implementation meta_implementation_objc"><span class="storage storage_type storage_type_objc"><span class="punctuation punctuation_definition punctuation_definition_storage punctuation_definition_storage_type punctuation_definition_storage_type_objc">@</span>implementation</span> <span class="entity entity_name entity_name_type entity_name_type_objc">CCLog</span>
<span class="meta meta_scope meta_scope_implementation meta_scope_implementation_objc">
<span class="meta meta_function-with-body meta_function-with-body_objc"><span class="meta meta_function meta_function_objc">+ <span class="meta meta_return-type meta_return-type_objc"><span class="punctuation punctuation_definition punctuation_definition_type punctuation_definition_type_objc">(</span><span class="support support_type support_type_cocoa support_type_cocoa_leopard">NSInteger</span><span class="punctuation punctuation_definition punctuation_definition_type punctuation_definition_type_objc">)</span><span class="entity entity_name entity_name_function entity_name_function_objc">currentThreadNumber</span></span>
</span><span class="meta meta_block meta_block_c">{
    <span class="support support_class support_class_cocoa">NSString</span>    *threadString;
    <span class="support support_type support_type_cocoa">NSRange</span>      numRange;
    <span class="support support_type support_type_cocoa support_type_cocoa_leopard">NSUInteger</span>   numLength;

    <span class="commentt comment_line comment_line_double-slash comment_line_double-slash_c++"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">//</span> Somehow there doesn't seem to be an listOfArgumentsI call to return the
</span>    <span class="commentt comment_line comment_line_double-slash comment_line_double-slash_c++"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">//</span> threadnumber only the name of the thread can be returned but this is NULL
</span>    <span class="commentt comment_line comment_line_double-slash comment_line_double-slash_c++"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">//</span> if it is not set first!
</span>    <span class="commentt comment_line comment_line_double-slash comment_line_double-slash_c++"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">//</span> Here is a bit of code to extract the thread number out of the string
</span>    <span class="commentt comment_line comment_line_double-slash comment_line_double-slash_c++"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">//</span> an NSThread returns when you ask its description to be printed out
</span>    <span class="commentt comment_line comment_line_double-slash comment_line_double-slash_c++"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">//</span> by NSLog. The format looks like:
</span>    <span class="commentt comment_line comment_line_double-slash comment_line_double-slash_c++"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">//</span>     &lt;NSThread: 0x10113a0&gt;{name = (null), num = 1}
</span>    <span class="commentt comment_line comment_line_double-slash comment_line_double-slash_c++"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">//</span> Basically I search for the "num = " substring, copy the remainder
</span>    <span class="commentt comment_line comment_line_double-slash comment_line_double-slash_c++"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">//</span> excluding the '}' which gives me the threadnumber.
</span>    threadString = <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="support support_class support_class_cocoa">NSString</span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">stringWithFormat<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span><span class="string string_quoted string_quoted_double string_quoted_double_objc"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_objc">@"</span>%@<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_objc">"</span></span>, <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="support support_class support_class_cocoa">NSThread</span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">currentThread</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>;

    numRange = <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span>threadString <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">rangeOfString<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span><span class="string string_quoted string_quoted_double string_quoted_double_objc"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_objc">@"</span>num = <span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_objc">"</span></span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>;

    numLength = <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span>threadString <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">length</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span> - numRange<span class="variable variable_other variable_other_dot-access variable_other_dot-access_c">.location</span> - numRange<span class="variable variable_other variable_other_dot-access variable_other_dot-access_c">.length</span>;
    numRange<span class="variable variable_other variable_other_dot-access variable_other_dot-access_c">.location</span> = numRange<span class="variable variable_other variable_other_dot-access variable_other_dot-access_c">.location</span> + numRange<span class="variable variable_other variable_other_dot-access variable_other_dot-access_c">.length</span>;
    numRange<span class="variable variable_other variable_other_dot-access variable_other_dot-access_c">.length</span>   = numLength - <span class="constant constant_numeric constant_numeric_c">1</span>;

    threadString = <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span>threadString <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">substringWithRange<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span>numRange</span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>;
    <span class="keyword keyword_control keyword_control_c">return</span> <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span>threadString <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">integerValue</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>;
}</span></span> <span class="commentt comment_block comment_block_c"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">/*</span> end currentThreadNumber <span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">*/</span></span>

<span class="meta meta_function-with-body meta_function-with-body_objc"><span class="meta meta_function meta_function_objc">+ <span class="meta meta_return-type meta_return-type_objc"><span class="punctuation punctuation_definition punctuation_definition_type punctuation_definition_type_objc">(</span><span class="storage storage_type storage_type_c">void</span><span class="punctuation punctuation_definition punctuation_definition_type punctuation_definition_type_objc">)</span><span class="entity entity_name entity_name_function entity_name_function_objc">myLog</span></span><span class="meta meta_argument-type meta_argument-type_objc"><span class="entity entity_name entity_name_function entity_name_function_name-of-parameter entity_name_function_name-of-parameter_objc"><span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span><span class="punctuation punctuation_definition punctuation_definition_type punctuation_definition_type_objc">(</span><span class="storage storage_type storage_type_c">char</span>*<span class="punctuation punctuation_definition punctuation_definition_type punctuation_definition_type_objc">)</span><span class="variable variable_parameter variable_parameter_function variable_parameter_function_objc">file</span></span>
   <span class="entity entity_name entity_name_function entity_name_function_name-of-parameter entity_name_function_name-of-parameter_objc">lineNumber</span><span class="meta meta_argument-type meta_argument-type_objc"><span class="entity entity_name entity_name_function entity_name_function_name-of-parameter entity_name_function_name-of-parameter_objc"><span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span><span class="punctuation punctuation_definition punctuation_definition_type punctuation_definition_type_objc">(</span><span class="storage storage_type storage_type_c">int</span><span class="punctuation punctuation_definition punctuation_definition_type punctuation_definition_type_objc">)</span><span class="variable variable_parameter variable_parameter_function variable_parameter_function_objc">lineNumber</span></span>
       <span class="entity entity_name entity_name_function entity_name_function_name-of-parameter entity_name_function_name-of-parameter_objc">format</span><span class="meta meta_argument-type meta_argument-type_objc"><span class="entity entity_name entity_name_function entity_name_function_name-of-parameter entity_name_function_name-of-parameter_objc"><span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span><span class="punctuation punctuation_definition punctuation_definition_type punctuation_definition_type_objc">(</span><span class="support support_class support_class_cocoa">NSString</span>*<span class="punctuation punctuation_definition punctuation_definition_type punctuation_definition_type_objc">)</span><span class="variable variable_parameter variable_parameter_function variable_parameter_function_objc">format</span></span>, ...
</span><span class="meta meta_block meta_block_c">{
    va_list      listOfArguments;
    <span class="support support_class support_class_cocoa">NSString</span>    *formattedString;
    <span class="support support_class support_class_cocoa">NSString</span>    *sourceFile;
    <span class="support support_class support_class_cocoa">NSString</span>    *logString;

<span class="punctuation punctuation_whitespace punctuation_whitespace_support punctuation_whitespace_support_function punctuation_whitespace_support_function_leading punctuation_whitespace_support_function_leading_c">    </span><span class="support support_function support_function_C99 support_function_C99_c">va_start</span>(listOfArguments, format);
    formattedString = <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="support support_class support_class_cocoa">NSString</span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">alloc</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">initWithFormat<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span>format
                                             <span class="support support_function support_function_any-method support_function_any-method_name-of-parameter support_function_any-method_name-of-parameter_objc">arguments<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span>listOfArguments</span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>;
<span class="punctuation punctuation_whitespace punctuation_whitespace_support punctuation_whitespace_support_function punctuation_whitespace_support_function_leading punctuation_whitespace_support_function_leading_c">    </span><span class="support support_function support_function_C99 support_function_C99_c">va_end</span>(listOfArguments);

    sourceFile = <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="support support_class support_class_cocoa">NSString</span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">alloc</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">initWithBytes<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span>file
                                          <span class="support support_function support_function_any-method support_function_any-method_name-of-parameter support_function_any-method_name-of-parameter_objc">length<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span>strlen(file)
                                        <span class="support support_function support_function_any-method support_function_any-method_name-of-parameter support_function_any-method_name-of-parameter_objc">encoding<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span><span class="support support_constant support_constant_cocoa">NSUTF8StringEncoding</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>;

    <span class="keyword keyword_control keyword_control_c">if</span>(<span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="support support_class support_class_cocoa">NSThread</span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">currentThread</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">name</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span> == <span class="constant constant_language constant_language_objc">nil</span>)
    <span class="meta meta_block meta_block_c">{
        <span class="commentt comment_line comment_line_double-slash comment_line_double-slash_c++"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">//</span> The thread has no name, try to find the threadnumber instead.
</span>        logString = <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="support support_class support_class_cocoa">NSString</span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">stringWithFormat<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span><span class="string string_quoted string_quoted_double string_quoted_double_objc"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_objc">@"</span>Thread %d | %s[%d] %@<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_objc">"</span></span>,
                    <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="variable variable_language variable_language_objc">self</span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">currentThreadNumber</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>,
                    <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span>sourceFile <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">lastPathComponent</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">UTF8String</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>,
                    lineNumber,
                    formattedString</span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>;
    }</span>
    <span class="keyword keyword_control keyword_control_c">else</span>
    <span class="meta meta_block meta_block_c">{
        logString = <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="support support_class support_class_cocoa">NSString</span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">stringWithFormat<span class="punctuation punctuation_separator punctuation_separator_arguments punctuation_separator_arguments_objc">:</span></span><span class="string string_quoted string_quoted_double string_quoted_double_objc"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_objc">@"</span>%@ | %s[%d] %@<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_objc">"</span></span>,
                    <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="support support_class support_class_cocoa">NSThread</span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">currentThread</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">name</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>,
                    <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span><span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span>sourceFile <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">lastPathComponent</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span> <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">UTF8String</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>,
                    lineNumber,
                    formattedString</span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>;
    }</span> <span class="commentt comment_block comment_block_c"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">/*</span> end if <span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">*/</span></span>

<span class="meta meta_preprocessor meta_preprocessor_c">#<span class="keyword keyword_control keyword_control_import keyword_control_import_c">ifdef</span>  USE_NSLOG</span>
<span class="punctuation punctuation_whitespace punctuation_whitespace_support punctuation_whitespace_support_function punctuation_whitespace_support_function_leading punctuation_whitespace_support_function_leading_cocoa">    </span><span class="support support_function support_function_cocoa">NSLog</span>(<span class="string string_quoted string_quoted_double string_quoted_double_objc"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_objc">@"</span>%@<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_objc">"</span></span>, logString);
<span class="meta meta_preprocessor meta_preprocessor_c">#<span class="keyword keyword_control keyword_control_import keyword_control_import_c">else</span></span>
<span class="punctuation punctuation_whitespace punctuation_whitespace_support punctuation_whitespace_support_function punctuation_whitespace_support_function_leading punctuation_whitespace_support_function_leading_c">    </span><span class="support support_function support_function_C99 support_function_C99_c">printf</span>(<span class="string string_quoted string_quoted_double string_quoted_double_c"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_c">"</span><span class="constant constant_other constant_other_placeholder constant_other_placeholder_c">%s</span><span class="constant constant_character constant_character_escape constant_character_escape_c">\n</span><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_c">"</span></span>, <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span>logString <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">UTF8String</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>);
<span class="meta meta_preprocessor meta_preprocessor_c">#<span class="keyword keyword_control keyword_control_import keyword_control_import_c">endif</span></span> /* USE_NSLOG */

    <span class="commentt comment_line comment_line_double-slash comment_line_double-slash_c++"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">//</span> cleanup
</span>    <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span>formattedString <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">release</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>;
    <span class="meta meta_bracketed meta_bracketed_objc"><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_begin punctuation_section_scope_begin_objc">[</span>sourceFile <span class="meta meta_function-call meta_function-call_objc"><span class="support support_function support_function_any-method support_function_any-method_objc">release</span></span><span class="punctuation punctuation_section punctuation_section_scope punctuation_section_scope_end punctuation_section_scope_end_objc">]</span></span>;
}</span></span> <span class="commentt comment_block comment_block_c"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">/*</span> end myLog <span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">*/</span></span>

</span><span class="storage storage_type storage_type_objc"><span class="punctuation punctuation_definition punctuation_definition_storage punctuation_definition_storage_type punctuation_definition_storage_type_objc">@</span>end</span></span> <span class="commentt comment_block comment_block_c"><span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">/*</span> implementation CCLog <span class="punctuation punctuation_definition punctuation_definition_commentt punctuation_definition_comment_c">*/</span></span></span></pre>
<p>A sample project can be downloaded here: <a href="http://www.cocoacrumbs.com/blog/wp-content/uploads/2008/11/cclog.zip">CCLog sample project</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.cocoacrumbs.com/blog/?feed=rss2&amp;p=69</wfw:commentRss>
		</item>
		<item>
		<title>Cocoa pronunciation</title>
		<link>http://www.cocoacrumbs.com/blog/?p=5</link>
		<comments>http://www.cocoacrumbs.com/blog/?p=5#comments</comments>
		<pubDate>Sun, 02 Nov 2008 18:03:52 +0000</pubDate>
		<dc:creator>kvnieuwe</dc:creator>
		
		<category><![CDATA[CoCoa]]></category>

		<category><![CDATA[Humor]]></category>

		<guid isPermaLink="false">http://www.cocoacrumbs.com/blog/?p=5</guid>
		<description><![CDATA[Probably a weird post to start this blog with, but during my visit to WWDC &#8216;08 and listening to a few cocoa related podcasts it dawned to me that I always wrongly pronounced cocoa (probably due to my native language which seems to prefer to speak out both the &#8216;o&#8217; and &#8216;a&#8217; vowels). Thanks to [...]]]></description>
			<content:encoded><![CDATA[<p>Probably a weird post to start this blog with, but during my visit to WWDC &#8216;08 and listening to a few cocoa related podcasts it dawned to me that I always wrongly pronounced cocoa (probably due to my native language which seems to prefer to speak out both the &#8216;o&#8217; and &#8216;a&#8217; vowels). Thanks to the wonders of speech synthesis I can easily let you hear my wrong pronunciation (by feeding it a bad transcription of cocoa) and how I should have pronounced &#8216;cocoa&#8217;.</p>
<p>This is how I used to pronounce it:<a href="http://www.cocoacrumbs.com/blog/wp-content/uploads/2008/11/cocoa.wav">cocoa - bad pronunciation</a></p>
<p>While this is the correct pronunciation:<a href="http://www.cocoacrumbs.com/blog/wp-content/uploads/2008/11/coco.wav">cocoa - correct pronunciation</a></p>
<p>[No, I didn't have a gender change, I preferred the female synthesis voice because the pronunciation was better.]</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cocoacrumbs.com/blog/?feed=rss2&amp;p=5</wfw:commentRss>
<enclosure url="http://www.cocoacrumbs.com/blog/wp-content/uploads/2008/11/cocoa.wav" length="40084" type="audio/x-wav" />
<enclosure url="http://www.cocoacrumbs.com/blog/wp-content/uploads/2008/11/coco.wav" length="32604" type="audio/x-wav" />
		</item>
	</channel>
</rss>
