<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.seiji.me/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom">

  <title><![CDATA[no more than a memo]]></title>
  
  <link href="http://blog.seiji.me/" />
  <updated>2012-02-04T13:19:23+09:00</updated>
  <id>http://blog.seiji.me/</id>
  <author>
    <name><![CDATA[Seiji Toyama]]></name>
    
  </author>
  <generator uri="http://octopress.org/">Octopress</generator>

  
  <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.seiji.me/seiji" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="seiji" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry>
    <title type="html"><![CDATA[build for ios using Unity Editor command line]]></title>
    <link href="http://blog.seiji.me/blog/2012/02/04/build-for-ios-using-unity-editor-command-line/" />
    <updated>2012-02-04T13:09:00+09:00</updated>
    <id>http://blog.seiji.me/blog/2012/02/04/build-for-ios-using-unity-editor-command-line</id>
    <content type="html"><![CDATA[<div><script src='https://gist.github.com/1735284.js?file='></script>
<noscript><pre><code>;; This buffer is for notes you don't want to save, and for Lisp evaluation.
;; If you want to create a file, visit that file with C-x C-f,
;; then enter the text in that file's own buffer.


/Applications/Unity/Unity.app/Contents/MacOS/Unity \
  -batchmode \
  -quit \
  -projectPath $PROJECT_PATH \
  -executeMethod CommandBuild.BuildiOS


using UnityEngine;
using UnityEditor;

public class CommandBuild
{
    public static void BuildiOS
    {
        BuildOptions opt = BuildOptions.SymlinkLibraries| BuildOptions.Development|BuildOptions.ConnectWithProfiler|BuildOptions.AllowDebugging;
        BuildPipeline.BuildPlayer({&quot;Assets/Scenes/Main.unity&quot;},&quot;iOS&quot;,BuildTarget.iPhone,opt); 
    }
}


</code></pre></noscript></div>


<p>referrel<br/>
<a href="http://unity3d.com/support/documentation/Manual/Command%20Line%20Arguments.html">Unity/documentation/Manual/Command Line Arguments</a></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Unity wrap Debug class]]></title>
    <link href="http://blog.seiji.me/blog/2012/01/25/unity-wrap-debug-class/" />
    <updated>2012-01-25T12:34:00+09:00</updated>
    <id>http://blog.seiji.me/blog/2012/01/25/unity-wrap-debug-class</id>
    <content type="html"><![CDATA[<h3>Debug.cs</h3>

<p>I just wanted to clear other &#8220;Debug.Log&#8221;</p>

<div><script src='https://gist.github.com/1674536.js?file=Debug.cs'></script>
<noscript><pre><code>using UnityEngine;
using System.Collections;
using System;
using System.IO;
using System.Text.RegularExpressions;
using UnityEngineInternal;

public static class Debug 
{
    public static bool isDebugBuild = true;

    public static void Log (object message)
    {
        if (isDebugBuild)
            UnityEngine.Debug.Log (message + hr);

    }
    public static void Log (object message, UnityEngine.Object context)
    {
        if (isDebugBuild)
            UnityEngine.Debug.Log (message, context);
    }

    public static void LogError (object message)
    {
        if (isDebugBuild)
            UnityEngine.Debug.LogError (message);
    }

    public static void LogError (object message, UnityEngine.Object context)
    {
        if (isDebugBuild)
            UnityEngine.Debug.LogError (message, context);
    }

    public static void LogWarning (object message)
    {
        if (isDebugBuild)
            UnityEngine.Debug.LogWarning (message.ToString ());
    }

    public static void LogWarning (object message, UnityEngine.Object context)
    {
        if (isDebugBuild)
            UnityEngine.Debug.LogWarning (message.ToString (), context);
    }
}
</code></pre></noscript></div>


<p>referrel<br/>
<a href="http://forum.unity3d.com/threads/38720-Debug.Log-and-needless-spam">http://forum.unity3d.com/threads/38720-Debug.Log-and-needless-spam</a></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[markdown-insert-headers and gist.el]]></title>
    <link href="http://blog.seiji.me/blog/2012/01/15/markdown-mode-markdown-insert-header/" />
    <updated>2012-01-15T15:21:00+09:00</updated>
    <id>http://blog.seiji.me/blog/2012/01/15/markdown-mode-markdown-insert-header</id>
    <content type="html"><![CDATA[<h3>~/.emacs.d/init/markdown-mode.el</h3>

<p>I&#8217;ve changed keybinds/markdown-insert-header for using the ^T command prefix in tmux</p>

<div><script src='https://gist.github.com/1614694.js?file=init-markdown.el'></script>
<noscript><pre><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
  &lt;head&gt;
    &lt;meta charset='utf-8'&gt;
    &lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;chrome=1&quot;&gt;
        &lt;title&gt;404 - GitHub&lt;/title&gt;
    &lt;link rel=&quot;search&quot; type=&quot;application/opensearchdescription+xml&quot; href=&quot;/opensearch.xml&quot; title=&quot;GitHub&quot; /&gt;
    &lt;link rel=&quot;fluid-icon&quot; href=&quot;https://github.com/fluidicon.png&quot; title=&quot;GitHub&quot; /&gt;

    
    

    

    &lt;link href=&quot;https://a248.e.akamai.net/assets.github.com/stylesheets/bundles/github-182944099c59274f5fb79ea97c47f923a5864f79.css&quot; media=&quot;screen&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;
    

    &lt;script src=&quot;https://a248.e.akamai.net/assets.github.com/javascripts/bundles/jquery-2bdf48207f435863de9c5786265d27d992c7f6c0.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;https://a248.e.akamai.net/assets.github.com/javascripts/bundles/github-68d680d89cf702cc67c2ebb0b261548622d05ce3.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
    

    
  &lt;/head&gt;


  &lt;body class=&quot;logged_out    env-production &quot;&gt;
    


    

      &lt;div id=&quot;header&quot; class=&quot;true clearfix&quot;&gt;
        &lt;div class=&quot;container clearfix&quot;&gt;
          &lt;a class=&quot;site-logo&quot; href=&quot;https://github.com&quot;&gt;
            &lt;!--[if IE]&gt;
            &lt;img alt=&quot;GitHub&quot; class=&quot;github-logo&quot; src=&quot;https://a248.e.akamai.net/assets.github.com/images/modules/header/logov7.png?1323882770&quot; /&gt;
            &lt;img alt=&quot;GitHub&quot; class=&quot;github-logo-hover&quot; src=&quot;https://a248.e.akamai.net/assets.github.com/images/modules/header/logov7-hover.png?1324325405&quot; /&gt;
            &lt;![endif]--&gt;
            &lt;img alt=&quot;GitHub&quot; class=&quot;github-logo-4x&quot; height=&quot;30&quot; src=&quot;https://a248.e.akamai.net/assets.github.com/images/modules/header/logov7@4x.png?1323882770&quot; /&gt;
            &lt;img alt=&quot;GitHub&quot; class=&quot;github-logo-4x-hover&quot; height=&quot;30&quot; src=&quot;https://a248.e.akamai.net/assets.github.com/images/modules/header/logov7@4x-hover.png?1324325405&quot; /&gt;
          &lt;/a&gt;

                  &lt;!--
      make sure to use fully qualified URLs here since this nav
      is used on error pages on other domains
    --&gt;
    &lt;ul class=&quot;top-nav logged_out&quot;&gt;
        &lt;li class=&quot;pricing&quot;&gt;&lt;a href=&quot;https://github.com/plans&quot;&gt;Signup and Pricing&lt;/a&gt;&lt;/li&gt;
        &lt;li class=&quot;explore&quot;&gt;&lt;a href=&quot;https://github.com/explore&quot;&gt;Explore GitHub&lt;/a&gt;&lt;/li&gt;
      &lt;li class=&quot;features&quot;&gt;&lt;a href=&quot;https://github.com/features&quot;&gt;Features&lt;/a&gt;&lt;/li&gt;
        &lt;li class=&quot;blog&quot;&gt;&lt;a href=&quot;https://github.com/blog&quot;&gt;Blog&lt;/a&gt;&lt;/li&gt;
      &lt;li class=&quot;login&quot;&gt;&lt;a href=&quot;https://github.com/login?return_to=%2Fgist%2F1614694%2Finit-markdown.el&quot;&gt;Login&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;



          
        &lt;/div&gt;
      &lt;/div&gt;

      

        &lt;div class=&quot;site&quot;&gt;
          &lt;div class=&quot;container&quot;&gt;
            

&lt;style type=&quot;text/css&quot;&gt;
    #header{
        border-bottom: 0;
    }
    .site{
        padding: 0;
        margin-top: -20px;
    }
    * {
        margin: 0px;
        padding: 0px;
    }
    #parallax_field{
        overflow: hidden;
        position: absolute;
        left: 0;
        top: 0;
        height: 370px;
        width: 100%;
    }
    #parallax_field #parallax_bg {
        position: absolute;
        top: -20px;
        left: -20px;
        width: 110%;
        height: 425px;
        z-index: 1;
    }
    #parallax_illustration {
        display:block;
        width: 940px;
        height: 370px;
        position: relative;
        overflow: hidden;
    }
    #parallax_illustration #parallax_error_text {
        position: absolute;
        top: 72px;
        left: 72px;
        z-index: 10;
    }
    #parallax_illustration #parallax_octocat {
        position: absolute;
        top: 94px;
        left: 356px;
        z-index: 9;
    }
    #parallax_illustration #parallax_speeder {
        position: absolute;
        top: 150px;
        left: 432px;
        z-index: 8;
    }
    #parallax_illustration #parallax_octocatshadow {
        position: absolute;
        top: 297px;
        left: 371px;
        z-index: 7;
    }
    #parallax_illustration #parallax_speedershadow {
        position: absolute;
        top: 263px;
        left: 442px;
        z-index: 6;
    }
    #parallax_illustration #parallax_building_1 {
        position: absolute;
        top: 73px;
        left: 467px;
        z-index: 5;
    }
    #parallax_illustration #parallax_building_2 {
        position: absolute;
        top: 113px;
        left: 762px;
        z-index: 4;
    }
    #footer {
        margin-top: 0px;
        z-index: 12;
    }
&lt;/style&gt;


&lt;div id=&quot;parallax_field&quot;&gt;
    &lt;img alt=&quot;building&quot; class=&quot;js-plaxify&quot; data-invert=&quot;true&quot; data-xrange=&quot;0&quot; data-yrange=&quot;20&quot; height=&quot;415&quot; id=&quot;parallax_bg&quot; src=&quot;https://a248.e.akamai.net/assets.github.com/images/modules/404/parallax_bg.jpg?1302750674&quot; width=&quot;940&quot; /&gt;
&lt;/div&gt;
&lt;div id=&quot;parallax_illustration&quot;&gt;
  &lt;img alt=&quot;404 | &amp;ldquo;This is not the web page you are looking for&amp;rdquo;&quot; class=&quot;js-plaxify&quot; data-xrange=&quot;20&quot; data-yrange=&quot;10&quot; height=&quot;249&quot; id=&quot;parallax_error_text&quot; src=&quot;https://a248.e.akamai.net/assets.github.com/images/modules/404/parallax_errortext.png?1302750674&quot; width=&quot;271&quot; /&gt;
  &lt;img alt=&quot;Octobi Wan Catnobi&quot; class=&quot;js-plaxify&quot; data-xrange=&quot;10&quot; data-yrange=&quot;10&quot; height=&quot;230&quot; id=&quot;parallax_octocat&quot; src=&quot;https://a248.e.akamai.net/assets.github.com/images/modules/404/parallax_octocat.png?1302750674&quot; width=&quot;188&quot; /&gt;
  &lt;img alt=&quot;land speeder&quot; class=&quot;js-plaxify&quot; data-xrange=&quot;10&quot; data-yrange=&quot;10&quot; height=&quot;156&quot; id=&quot;parallax_speeder&quot; src=&quot;https://a248.e.akamai.net/assets.github.com/images/modules/404/parallax_speeder.png?1302750674&quot; width=&quot;440&quot; /&gt;
  &lt;img alt=&quot;Octobi Wan Catnobi's shadow&quot; class=&quot;js-plaxify&quot; data-xrange=&quot;10&quot; data-yrange=&quot;10&quot; height=&quot;49&quot; id=&quot;parallax_octocatshadow&quot; src=&quot;https://a248.e.akamai.net/assets.github.com/images/modules/404/parallax_octocatshadow.png?1302750674&quot; width=&quot;166&quot; /&gt;
  &lt;img alt=&quot;land speeder's shadow&quot; class=&quot;js-plaxify&quot; data-xrange=&quot;10&quot; data-yrange=&quot;10&quot; height=&quot;75&quot; id=&quot;parallax_speedershadow&quot; src=&quot;https://a248.e.akamai.net/assets.github.com/images/modules/404/parallax_speedershadow.png?1302750674&quot; width=&quot;430&quot; /&gt;
  &lt;img alt=&quot;building&quot; class=&quot;js-plaxify&quot; data-invert=&quot;true&quot; data-xrange=&quot;50&quot; data-yrange=&quot;20&quot; height=&quot;123&quot; id=&quot;parallax_building_1&quot; src=&quot;https://a248.e.akamai.net/assets.github.com/images/modules/404/parallax_building_1.png?1302750674&quot; width=&quot;304&quot; /&gt;
  &lt;img alt=&quot;building&quot; class=&quot;js-plaxify&quot; data-invert=&quot;true&quot; data-xrange=&quot;75&quot; data-yrange=&quot;30&quot; height=&quot;50&quot; id=&quot;parallax_building_2&quot; src=&quot;https://a248.e.akamai.net/assets.github.com/images/modules/404/parallax_building_2.png?1302750674&quot; width=&quot;116&quot; /&gt;
&lt;/div&gt;

          &lt;/div&gt;
          &lt;div class=&quot;context-overlay&quot;&gt;&lt;/div&gt;
        &lt;/div&gt;

      &lt;!-- footer --&gt;
      &lt;div id=&quot;footer&quot; &gt;
        
  &lt;div class=&quot;upper_footer&quot;&gt;
     &lt;div class=&quot;container clearfix&quot;&gt;

       &lt;!--[if IE]&gt;&lt;h4 id=&quot;blacktocat_ie&quot;&gt;GitHub Links&lt;/h4&gt;&lt;![endif]--&gt;
       &lt;![if !IE]&gt;&lt;h4 id=&quot;blacktocat&quot;&gt;GitHub Links&lt;/h4&gt;&lt;![endif]&gt;

       &lt;ul class=&quot;footer_nav&quot;&gt;
         &lt;h4&gt;GitHub&lt;/h4&gt;
         &lt;li&gt;&lt;a href=&quot;https://github.com/about&quot;&gt;About&lt;/a&gt;&lt;/li&gt;
         &lt;li&gt;&lt;a href=&quot;https://github.com/blog&quot;&gt;Blog&lt;/a&gt;&lt;/li&gt;
         &lt;li&gt;&lt;a href=&quot;https://github.com/features&quot;&gt;Features&lt;/a&gt;&lt;/li&gt;
         &lt;li&gt;&lt;a href=&quot;https://github.com/contact&quot;&gt;Contact &amp;amp; Support&lt;/a&gt;&lt;/li&gt;
         &lt;li&gt;&lt;a href=&quot;https://github.com/training&quot;&gt;Training&lt;/a&gt;&lt;/li&gt;
         &lt;li&gt;&lt;a href=&quot;http://enterprise.github.com/&quot;&gt;GitHub Enterprise&lt;/a&gt;&lt;/li&gt;
         &lt;li&gt;&lt;a href=&quot;http://status.github.com/&quot;&gt;Site Status&lt;/a&gt;&lt;/li&gt;
       &lt;/ul&gt;

       &lt;ul class=&quot;footer_nav&quot;&gt;
         &lt;h4&gt;Tools&lt;/h4&gt;
         &lt;li&gt;&lt;a href=&quot;http://get.gaug.es/&quot;&gt;Gauges: Analyze web traffic&lt;/a&gt;&lt;/li&gt;
         &lt;li&gt;&lt;a href=&quot;http://speakerdeck.com&quot;&gt;Speaker Deck: Presentations&lt;/a&gt;&lt;/li&gt;
         &lt;li&gt;&lt;a href=&quot;https://gist.github.com&quot;&gt;Gist: Code snippets&lt;/a&gt;&lt;/li&gt;
         &lt;li&gt;&lt;a href=&quot;http://mac.github.com/&quot;&gt;GitHub for Mac&lt;/a&gt;&lt;/li&gt;
         &lt;li&gt;&lt;a href=&quot;http://mobile.github.com/&quot;&gt;Issues for iPhone&lt;/a&gt;&lt;/li&gt;
         &lt;li&gt;&lt;a href=&quot;http://jobs.github.com/&quot;&gt;Job Board&lt;/a&gt;&lt;/li&gt;
       &lt;/ul&gt;

       &lt;ul class=&quot;footer_nav&quot;&gt;
         &lt;h4&gt;Extras&lt;/h4&gt;
         &lt;li&gt;&lt;a href=&quot;http://shop.github.com/&quot;&gt;GitHub Shop&lt;/a&gt;&lt;/li&gt;
         &lt;li&gt;&lt;a href=&quot;http://octodex.github.com/&quot;&gt;The Octodex&lt;/a&gt;&lt;/li&gt;
       &lt;/ul&gt;

       &lt;ul class=&quot;footer_nav&quot;&gt;
         &lt;h4&gt;Documentation&lt;/h4&gt;
         &lt;li&gt;&lt;a href=&quot;http://help.github.com/&quot;&gt;GitHub Help&lt;/a&gt;&lt;/li&gt;
         &lt;li&gt;&lt;a href=&quot;http://developer.github.com/&quot;&gt;Developer API&lt;/a&gt;&lt;/li&gt;
         &lt;li&gt;&lt;a href=&quot;http://github.github.com/github-flavored-markdown/&quot;&gt;GitHub Flavored Markdown&lt;/a&gt;&lt;/li&gt;
         &lt;li&gt;&lt;a href=&quot;http://pages.github.com/&quot;&gt;GitHub Pages&lt;/a&gt;&lt;/li&gt;
       &lt;/ul&gt;

     &lt;/div&gt;&lt;!-- /.site --&gt;
  &lt;/div&gt;&lt;!-- /.upper_footer --&gt;

&lt;div class=&quot;lower_footer&quot;&gt;
  &lt;div class=&quot;container clearfix&quot;&gt;
    &lt;!--[if IE]&gt;&lt;div id=&quot;legal_ie&quot;&gt;&lt;![endif]--&gt;
    &lt;![if !IE]&gt;&lt;div id=&quot;legal&quot;&gt;&lt;![endif]&gt;
      &lt;ul&gt;
          &lt;li&gt;&lt;a href=&quot;https://github.com/site/terms&quot;&gt;Terms of Service&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;https://github.com/site/privacy&quot;&gt;Privacy&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;https://github.com/security&quot;&gt;Security&lt;/a&gt;&lt;/li&gt;
      &lt;/ul&gt;

      &lt;p&gt;&amp;copy; 2012 &lt;span id=&quot;_rrt&quot; title=&quot;0.01583s from fe5.rs.github.com&quot;&gt;GitHub&lt;/span&gt; Inc. All rights reserved.&lt;/p&gt;
    &lt;/div&gt;&lt;!-- /#legal or /#legal_ie--&gt;

      &lt;div class=&quot;sponsor&quot;&gt;
        &lt;a href=&quot;http://www.rackspace.com&quot; class=&quot;logo&quot;&gt;
          &lt;img alt=&quot;Dedicated Server&quot; height=&quot;36&quot; src=&quot;https://a248.e.akamai.net/assets.github.com/images/modules/footer/rackspace_logo.png?v2&quot; width=&quot;38&quot; /&gt;
        &lt;/a&gt;
        Powered by the &lt;a href=&quot;http://www.rackspace.com &quot;&gt;Dedicated
        Servers&lt;/a&gt; and&lt;br/&gt; &lt;a href=&quot;http://www.rackspacecloud.com&quot;&gt;Cloud
        Computing&lt;/a&gt; of Rackspace Hosting&lt;span&gt;&amp;reg;&lt;/span&gt;
      &lt;/div&gt;
  &lt;/div&gt;&lt;!-- /.site --&gt;
&lt;/div&gt;&lt;!-- /.lower_footer --&gt;

      &lt;/div&gt;&lt;!-- /#footer --&gt;

    

&lt;div id=&quot;keyboard_shortcuts_pane&quot; class=&quot;instapaper_ignore readability-extra&quot; style=&quot;display:none&quot;&gt;
  &lt;h2&gt;Keyboard Shortcuts &lt;small&gt;&lt;a href=&quot;#&quot; class=&quot;js-see-all-keyboard-shortcuts&quot;&gt;(see all)&lt;/a&gt;&lt;/small&gt;&lt;/h2&gt;

  &lt;div class=&quot;columns threecols&quot;&gt;
    &lt;div class=&quot;column first&quot;&gt;
      &lt;h3&gt;Site wide shortcuts&lt;/h3&gt;
      &lt;dl class=&quot;keyboard-mappings&quot;&gt;
        &lt;dt&gt;s&lt;/dt&gt;
        &lt;dd&gt;Focus site search&lt;/dd&gt;
      &lt;/dl&gt;
      &lt;dl class=&quot;keyboard-mappings&quot;&gt;
        &lt;dt&gt;?&lt;/dt&gt;
        &lt;dd&gt;Bring up this help dialog&lt;/dd&gt;
      &lt;/dl&gt;
    &lt;/div&gt;&lt;!-- /.column.first --&gt;

    &lt;div class=&quot;column middle&quot; style='display:none'&gt;
      &lt;h3&gt;Commit list&lt;/h3&gt;
      &lt;dl class=&quot;keyboard-mappings&quot;&gt;
        &lt;dt&gt;j&lt;/dt&gt;
        &lt;dd&gt;Move selection down&lt;/dd&gt;
      &lt;/dl&gt;
      &lt;dl class=&quot;keyboard-mappings&quot;&gt;
        &lt;dt&gt;k&lt;/dt&gt;
        &lt;dd&gt;Move selection up&lt;/dd&gt;
      &lt;/dl&gt;
      &lt;dl class=&quot;keyboard-mappings&quot;&gt;
        &lt;dt&gt;c &lt;em&gt;or&lt;/em&gt; o &lt;em&gt;or&lt;/em&gt; enter&lt;/dt&gt;
        &lt;dd&gt;Open commit&lt;/dd&gt;
      &lt;/dl&gt;
      &lt;dl class=&quot;keyboard-mappings&quot;&gt;
        &lt;dt&gt;y&lt;/dt&gt;
        &lt;dd&gt;Expand URL to its canonical form&lt;/dd&gt;
      &lt;/dl&gt;
    &lt;/div&gt;&lt;!-- /.column.first --&gt;

    &lt;div class=&quot;column last&quot; style='display:none'&gt;
      &lt;h3&gt;Pull request list&lt;/h3&gt;
      &lt;dl class=&quot;keyboard-mappings&quot;&gt;
        &lt;dt&gt;j&lt;/dt&gt;
        &lt;dd&gt;Move selection down&lt;/dd&gt;
      &lt;/dl&gt;
      &lt;dl class=&quot;keyboard-mappings&quot;&gt;
        &lt;dt&gt;k&lt;/dt&gt;
        &lt;dd&gt;Move selection up&lt;/dd&gt;
      &lt;/dl&gt;
      &lt;dl class=&quot;keyboard-mappings&quot;&gt;
        &lt;dt&gt;o &lt;em&gt;or&lt;/em&gt; enter&lt;/dt&gt;
        &lt;dd&gt;Open issue&lt;/dd&gt;
      &lt;/dl&gt;
    &lt;/div&gt;&lt;!-- /.columns.last --&gt;

  &lt;/div&gt;&lt;!-- /.columns.equacols --&gt;

  &lt;div style='display:none'&gt;
    &lt;div class=&quot;rule&quot;&gt;&lt;/div&gt;

    &lt;h3&gt;Issues&lt;/h3&gt;

    &lt;div class=&quot;columns threecols&quot;&gt;
      &lt;div class=&quot;column first&quot;&gt;
        &lt;dl class=&quot;keyboard-mappings&quot;&gt;
          &lt;dt&gt;j&lt;/dt&gt;
          &lt;dd&gt;Move selection down&lt;/dd&gt;
        &lt;/dl&gt;
        &lt;dl class=&quot;keyboard-mappings&quot;&gt;
          &lt;dt&gt;k&lt;/dt&gt;
          &lt;dd&gt;Move selection up&lt;/dd&gt;
        &lt;/dl&gt;
        &lt;dl class=&quot;keyboard-mappings&quot;&gt;
          &lt;dt&gt;x&lt;/dt&gt;
          &lt;dd&gt;Toggle selection&lt;/dd&gt;
        &lt;/dl&gt;
        &lt;dl class=&quot;keyboard-mappings&quot;&gt;
          &lt;dt&gt;o &lt;em&gt;or&lt;/em&gt; enter&lt;/dt&gt;
          &lt;dd&gt;Open issue&lt;/dd&gt;
        &lt;/dl&gt;
      &lt;/div&gt;&lt;!-- /.column.first --&gt;
      &lt;div class=&quot;column middle&quot;&gt;
        &lt;dl class=&quot;keyboard-mappings&quot;&gt;
          &lt;dt&gt;I&lt;/dt&gt;
          &lt;dd&gt;Mark selection as read&lt;/dd&gt;
        &lt;/dl&gt;
        &lt;dl class=&quot;keyboard-mappings&quot;&gt;
          &lt;dt&gt;U&lt;/dt&gt;
          &lt;dd&gt;Mark selection as unread&lt;/dd&gt;
        &lt;/dl&gt;
        &lt;dl class=&quot;keyboard-mappings&quot;&gt;
          &lt;dt&gt;e&lt;/dt&gt;
          &lt;dd&gt;Close selection&lt;/dd&gt;
        &lt;/dl&gt;
        &lt;dl class=&quot;keyboard-mappings&quot;&gt;
          &lt;dt&gt;y&lt;/dt&gt;
          &lt;dd&gt;Remove selection from view&lt;/dd&gt;
        &lt;/dl&gt;
      &lt;/div&gt;&lt;!-- /.column.middle --&gt;
      &lt;div class=&quot;column last&quot;&gt;
        &lt;dl class=&quot;keyboard-mappings&quot;&gt;
          &lt;dt&gt;c&lt;/dt&gt;
          &lt;dd&gt;Create issue&lt;/dd&gt;
        &lt;/dl&gt;
        &lt;dl class=&quot;keyboard-mappings&quot;&gt;
          &lt;dt&gt;l&lt;/dt&gt;
          &lt;dd&gt;Create label&lt;/dd&gt;
        &lt;/dl&gt;
        &lt;dl class=&quot;keyboard-mappings&quot;&gt;
          &lt;dt&gt;i&lt;/dt&gt;
          &lt;dd&gt;Back to inbox&lt;/dd&gt;
        &lt;/dl&gt;
        &lt;dl class=&quot;keyboard-mappings&quot;&gt;
          &lt;dt&gt;u&lt;/dt&gt;
          &lt;dd&gt;Back to issues&lt;/dd&gt;
        &lt;/dl&gt;
        &lt;dl class=&quot;keyboard-mappings&quot;&gt;
          &lt;dt&gt;/&lt;/dt&gt;
          &lt;dd&gt;Focus issues search&lt;/dd&gt;
        &lt;/dl&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;

  &lt;div style='display:none'&gt;
    &lt;div class=&quot;rule&quot;&gt;&lt;/div&gt;

    &lt;h3&gt;Issues Dashboard&lt;/h3&gt;

    &lt;div class=&quot;columns threecols&quot;&gt;
      &lt;div class=&quot;column first&quot;&gt;
        &lt;dl class=&quot;keyboard-mappings&quot;&gt;
          &lt;dt&gt;j&lt;/dt&gt;
          &lt;dd&gt;Move selection down&lt;/dd&gt;
        &lt;/dl&gt;
        &lt;dl class=&quot;keyboard-mappings&quot;&gt;
          &lt;dt&gt;k&lt;/dt&gt;
          &lt;dd&gt;Move selection up&lt;/dd&gt;
        &lt;/dl&gt;
        &lt;dl class=&quot;keyboard-mappings&quot;&gt;
          &lt;dt&gt;o &lt;em&gt;or&lt;/em&gt; enter&lt;/dt&gt;
          &lt;dd&gt;Open issue&lt;/dd&gt;
        &lt;/dl&gt;
      &lt;/div&gt;&lt;!-- /.column.first --&gt;
    &lt;/div&gt;
  &lt;/div&gt;

  &lt;div style='display:none'&gt;
    &lt;div class=&quot;rule&quot;&gt;&lt;/div&gt;

    &lt;h3&gt;Network Graph&lt;/h3&gt;
    &lt;div class=&quot;columns equacols&quot;&gt;
      &lt;div class=&quot;column first&quot;&gt;
        &lt;dl class=&quot;keyboard-mappings&quot;&gt;
          &lt;dt&gt;&lt;span class=&quot;badmono&quot;&gt;←&lt;/span&gt; &lt;em&gt;or&lt;/em&gt; h&lt;/dt&gt;
          &lt;dd&gt;Scroll left&lt;/dd&gt;
        &lt;/dl&gt;
        &lt;dl class=&quot;keyboard-mappings&quot;&gt;
          &lt;dt&gt;&lt;span class=&quot;badmono&quot;&gt;→&lt;/span&gt; &lt;em&gt;or&lt;/em&gt; l&lt;/dt&gt;
          &lt;dd&gt;Scroll right&lt;/dd&gt;
        &lt;/dl&gt;
        &lt;dl class=&quot;keyboard-mappings&quot;&gt;
          &lt;dt&gt;&lt;span class=&quot;badmono&quot;&gt;↑&lt;/span&gt; &lt;em&gt;or&lt;/em&gt; k&lt;/dt&gt;
          &lt;dd&gt;Scroll up&lt;/dd&gt;
        &lt;/dl&gt;
        &lt;dl class=&quot;keyboard-mappings&quot;&gt;
          &lt;dt&gt;&lt;span class=&quot;badmono&quot;&gt;↓&lt;/span&gt; &lt;em&gt;or&lt;/em&gt; j&lt;/dt&gt;
          &lt;dd&gt;Scroll down&lt;/dd&gt;
        &lt;/dl&gt;
        &lt;dl class=&quot;keyboard-mappings&quot;&gt;
          &lt;dt&gt;t&lt;/dt&gt;
          &lt;dd&gt;Toggle visibility of head labels&lt;/dd&gt;
        &lt;/dl&gt;
      &lt;/div&gt;&lt;!-- /.column.first --&gt;
      &lt;div class=&quot;column last&quot;&gt;
        &lt;dl class=&quot;keyboard-mappings&quot;&gt;
          &lt;dt&gt;shift &lt;span class=&quot;badmono&quot;&gt;←&lt;/span&gt; &lt;em&gt;or&lt;/em&gt; shift h&lt;/dt&gt;
          &lt;dd&gt;Scroll all the way left&lt;/dd&gt;
        &lt;/dl&gt;
        &lt;dl class=&quot;keyboard-mappings&quot;&gt;
          &lt;dt&gt;shift &lt;span class=&quot;badmono&quot;&gt;→&lt;/span&gt; &lt;em&gt;or&lt;/em&gt; shift l&lt;/dt&gt;
          &lt;dd&gt;Scroll all the way right&lt;/dd&gt;
        &lt;/dl&gt;
        &lt;dl class=&quot;keyboard-mappings&quot;&gt;
          &lt;dt&gt;shift &lt;span class=&quot;badmono&quot;&gt;↑&lt;/span&gt; &lt;em&gt;or&lt;/em&gt; shift k&lt;/dt&gt;
          &lt;dd&gt;Scroll all the way up&lt;/dd&gt;
        &lt;/dl&gt;
        &lt;dl class=&quot;keyboard-mappings&quot;&gt;
          &lt;dt&gt;shift &lt;span class=&quot;badmono&quot;&gt;↓&lt;/span&gt; &lt;em&gt;or&lt;/em&gt; shift j&lt;/dt&gt;
          &lt;dd&gt;Scroll all the way down&lt;/dd&gt;
        &lt;/dl&gt;
      &lt;/div&gt;&lt;!-- /.column.last --&gt;
    &lt;/div&gt;
  &lt;/div&gt;

  &lt;div style='display:none'&gt;
    &lt;div class=&quot;rule&quot;&gt;&lt;/div&gt;
    &lt;div class=&quot;columns threecols&quot;&gt;
      &lt;div class=&quot;column first&quot; style='display:none'&gt;
        &lt;h3&gt;Source Code Browsing&lt;/h3&gt;
        &lt;dl class=&quot;keyboard-mappings&quot;&gt;
          &lt;dt&gt;t&lt;/dt&gt;
          &lt;dd&gt;Activates the file finder&lt;/dd&gt;
        &lt;/dl&gt;
        &lt;dl class=&quot;keyboard-mappings&quot;&gt;
          &lt;dt&gt;l&lt;/dt&gt;
          &lt;dd&gt;Jump to line&lt;/dd&gt;
        &lt;/dl&gt;
        &lt;dl class=&quot;keyboard-mappings&quot;&gt;
          &lt;dt&gt;w&lt;/dt&gt;
          &lt;dd&gt;Switch branch/tag&lt;/dd&gt;
        &lt;/dl&gt;
        &lt;dl class=&quot;keyboard-mappings&quot;&gt;
          &lt;dt&gt;y&lt;/dt&gt;
          &lt;dd&gt;Expand URL to its canonical form&lt;/dd&gt;
        &lt;/dl&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

    &lt;div id=&quot;markdown-help&quot; class=&quot;instapaper_ignore readability-extra&quot;&gt;
  &lt;h2&gt;Markdown Cheat Sheet&lt;/h2&gt;

  &lt;div class=&quot;cheatsheet-content&quot;&gt;

  &lt;div class=&quot;mod&quot;&gt;
    &lt;div class=&quot;col&quot;&gt;
      &lt;h3&gt;Format Text&lt;/h3&gt;
      &lt;p&gt;Headers&lt;/p&gt;
      &lt;pre&gt;
# This is an &amp;lt;h1&amp;gt; tag
## This is an &amp;lt;h2&amp;gt; tag
###### This is an &amp;lt;h6&amp;gt; tag&lt;/pre&gt;
     &lt;p&gt;Text styles&lt;/p&gt;
     &lt;pre&gt;
*This text will be italic*
_This will also be italic_
**This text will be bold**
__This will also be bold__

*You **can** combine them*
&lt;/pre&gt;
    &lt;/div&gt;
    &lt;div class=&quot;col&quot;&gt;
      &lt;h3&gt;Lists&lt;/h3&gt;
      &lt;p&gt;Unordered&lt;/p&gt;
      &lt;pre&gt;
* Item 1
* Item 2
  * Item 2a
  * Item 2b&lt;/pre&gt;
     &lt;p&gt;Ordered&lt;/p&gt;
     &lt;pre&gt;
1. Item 1
2. Item 2
3. Item 3
   * Item 3a
   * Item 3b&lt;/pre&gt;
    &lt;/div&gt;
    &lt;div class=&quot;col&quot;&gt;
      &lt;h3&gt;Miscellaneous&lt;/h3&gt;
      &lt;p&gt;Images&lt;/p&gt;
      &lt;pre&gt;
![GitHub Logo](/images/logo.png)
Format: ![Alt Text](url)
&lt;/pre&gt;
     &lt;p&gt;Links&lt;/p&gt;
     &lt;pre&gt;
http://github.com - automatic!
[GitHub](http://github.com)&lt;/pre&gt;
&lt;p&gt;Blockquotes&lt;/p&gt;
     &lt;pre&gt;
As Kanye West said:

&gt; We're living the future so
&gt; the present is our past.
&lt;/pre&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div class=&quot;rule&quot;&gt;&lt;/div&gt;

  &lt;h3&gt;Code Examples in Markdown&lt;/h3&gt;
  &lt;div class=&quot;col&quot;&gt;
      &lt;p&gt;Syntax highlighting with &lt;a href=&quot;http://github.github.com/github-flavored-markdown/&quot; title=&quot;GitHub Flavored Markdown&quot; target=&quot;_blank&quot;&gt;GFM&lt;/a&gt;&lt;/p&gt;
      &lt;pre&gt;
```javascript
function fancyAlert(arg) {
  if(arg) {
    $.facebox({div:'#foo'})
  }
}
```&lt;/pre&gt;
    &lt;/div&gt;
    &lt;div class=&quot;col&quot;&gt;
      &lt;p&gt;Or, indent your code 4 spaces&lt;/p&gt;
      &lt;pre&gt;
Here is a Python code example
without syntax highlighting:

    def foo:
      if not bar:
        return true&lt;/pre&gt;
    &lt;/div&gt;
    &lt;div class=&quot;col&quot;&gt;
      &lt;p&gt;Inline code for comments&lt;/p&gt;
      &lt;pre&gt;
I think you should use an
`&amp;lt;addr&amp;gt;` element here instead.&lt;/pre&gt;
    &lt;/div&gt;
  &lt;/div&gt;

  &lt;/div&gt;
&lt;/div&gt;


    &lt;div class=&quot;ajax-error-message&quot;&gt;
      &lt;p&gt;&lt;span class=&quot;icon&quot;&gt;&lt;/span&gt; Something went wrong with that request. Please try again. &lt;a href=&quot;javascript:;&quot; class=&quot;ajax-error-dismiss&quot;&gt;Dismiss&lt;/a&gt;&lt;/p&gt;
    &lt;/div&gt;

    
    
    
  &lt;/body&gt;
&lt;/html&gt;
</code></pre></noscript></div>


<h3>post using gist.el</h3>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>$ git config --global github.user  #{github-user}
</span><span class='line'>$ git config --global github.token #{github-api-token}
</span><span class='line'># emacs
</span><span class='line'>M-x gist-region(-private)</span></code></pre></td></tr></table></div></figure>



]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[test]]></title>
    <link href="http://blog.seiji.me/blog/2012/01/15/test/" />
    <updated>2012-01-15T01:52:00+09:00</updated>
    <id>http://blog.seiji.me/blog/2012/01/15/test</id>
    <content type="html"><![CDATA[<p>test is test</p>

<figure class='code'><figcaption><span>Add to_fraction for floats (test.rb)</span> <a href='http://blog.seiji.me/downloads/code/ruby/test.rb'>download</a></figcaption>
 <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
</pre></td><td class='code'><pre><code class='rb'><span class='line'><span class="k">class</span> <span class="nc">Float</span>
</span><span class='line'>  <span class="k">def</span> <span class="nf">number_decimal_places</span>
</span><span class='line'>    <span class="nb">self</span><span class="o">.</span><span class="n">to_s</span><span class="o">.</span><span class="n">length</span><span class="o">-</span><span class="mi">2</span>
</span><span class='line'>  <span class="k">end</span>
</span><span class='line'>  <span class="k">def</span> <span class="nf">to_fraction</span>
</span><span class='line'>    <span class="n">higher</span> <span class="o">=</span> <span class="mi">10</span><span class="o">**</span><span class="nb">self</span><span class="o">.</span><span class="n">number_decimal_places</span>
</span><span class='line'>    <span class="n">lower</span> <span class="o">=</span> <span class="nb">self</span><span class="o">*</span><span class="n">higher</span>
</span><span class='line'>    <span class="n">gcden</span> <span class="o">=</span> <span class="n">greatest_common_divisor</span><span class="p">(</span><span class="n">higher</span><span class="p">,</span> <span class="n">lower</span><span class="p">)</span>
</span><span class='line'>
</span><span class='line'>    <span class="k">return</span> <span class="p">(</span><span class="n">lower</span><span class="o">/</span><span class="n">gcden</span><span class="p">)</span><span class="o">.</span><span class="n">round</span><span class="p">,</span> <span class="p">(</span><span class="n">higher</span><span class="o">/</span><span class="n">gcden</span><span class="p">)</span><span class="o">.</span><span class="n">round</span>
</span><span class='line'>  <span class="k">end</span>
</span><span class='line'>
</span><span class='line'>  <span class="kp">private</span>
</span><span class='line'>  <span class="k">def</span> <span class="nf">greatest_common_divisor</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">)</span>
</span><span class='line'>    <span class="k">while</span> <span class="n">a</span><span class="o">%</span><span class="n">b</span> <span class="o">!=</span> <span class="mi">0</span>
</span><span class='line'>      <span class="n">a</span><span class="p">,</span><span class="n">b</span> <span class="o">=</span> <span class="n">b</span><span class="o">.</span><span class="n">round</span><span class="p">,(</span><span class="n">a</span><span class="o">%</span><span class="n">b</span><span class="p">)</span><span class="o">.</span><span class="n">round</span>
</span><span class='line'>    <span class="k">end</span>
</span><span class='line'>    <span class="k">return</span> <span class="n">b</span>
</span><span class='line'>  <span class="k">end</span>
</span><span class='line'><span class="k">end</span>
</span></code></pre></td></tr></table></div></figure>


<p>open with Google Chrome</p>

<div><script src='https://gist.github.com/1209261.js?file='></script>
<noscript><pre><code>-- open_url: open with Google Chrome 
on run argv
  tell application &quot;Google Chrome&quot;
    tell window 1
      set newTab to make new tab with properties {URL:item 1 of argv}
    end tell
  end tell
end run</code></pre></noscript></div>



]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[4ビットマイコン (大人の科学マガジンvol24)]]></title>
    <link href="http://blog.seiji.me/blog/2009/10/02/460/" />
    <updated>2009-10-02T00:00:00+09:00</updated>
    <id>http://blog.seiji.me/blog/2009/10/02/460</id>
    <content type="html"><![CDATA[<p>4ビットマイコン (大人の科学マガジンvol24)を買った。</p>


<p>
    <br />
<a href="http://www.flickr.com/photos/31821868@N05/3974639920" title="View 'photo' on Flickr.com"><img src="http://farm3.static.flickr.com/2547/3974639920_20c26c4388.jpg" alt="photo" border="0" width="375" height="500" /></a>
    <br />
</p>


<!--more-->


<p>
    <br />
    <a href="http://www.flickr.com/photos/31821868@N05/3974634926" title="View 'photo' on Flickr.com"><img src="http://farm3.static.flickr.com/2472/3974634926_d853a3f064.jpg" alt="photo" border="0" width="500" height="375" /></a><br />
こんな感じで入ってる。
</p>


<p>
    <br />
    <a href="http://www.flickr.com/photos/31821868@N05/3974804984" title="View 'photo' on Flickr.com"><img src="http://farm3.static.flickr.com/2449/3974804984_dba5c064aa.jpg" alt="photo" border="0" width="500" height="375" /></a><br />
簡単に組み立てできる。
</p>


<ul>
    <li>プログラムメモリ:40byte</li>
    <li>データメモリ:8byte</li>
    <li>レジスタ: 8個</li>
    <li>入力: キーパッド</li>
    <li>出力: 2進LED, 数字LED, スピーカー</li>
</ul>


<p>各アドレスに値を入れたり、プログラムを実行したり、電子音を鳴らしたりできる。なかなかおもしろい。</p>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[MacBookのHD交換]]></title>
    <link href="http://blog.seiji.me/blog/2008/12/28/437/" />
    <updated>2008-12-28T00:00:00+09:00</updated>
    <id>http://blog.seiji.me/blog/2008/12/28/437</id>
    <content type="html"><![CDATA[<p>HDの残り容量が少なくなってきたので、120Gのものから500Gのものに交換しました。</p>


<p>
    <br />
    <img src="http://img.seiji.me/blog/2008/12/img-0023.jpg" alt="IMG_0023.JPG" border="0" width="200" height="266" />
    <br />
</p>


<!--more-->


<p>
秋葉原のドスパラでWestern Digitalの<a href="http://www.wdc.com/jp/products/Products.asp?DriveID=506">WD5000BEVT</a>が8,980円で売っていたので買ってきました。
</p>




<p>ディスクユーティリティで復元を行い、HDを付け替え。
起動に時間がかかりましたが、問題なく交換できました。</p>




<h4>Before</h4>


<p>

<br />
<img src="http://img.seiji.me/blog/2008/12/before.jpg" alt="before.jpg" border="0" width="380" height="189" />
<br />

</p>




<h4>After</h4>


<p>
<br />
<img src="http://img.seiji.me/blog/2008/12/smb-1.jpg" alt="smb-1.jpg" border="0" width="380" height="206" />
<br />

</p>




<p>MacBookのHD交換はすぐ交換できるので楽です。</p>


<p>これでしばらくは容量を気にしなくてもよさそうです。</p>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Making a CGRect]]></title>
    <link href="http://blog.seiji.me/blog/2008/12/26/421/" />
    <updated>2008-12-26T00:00:00+09:00</updated>
    <id>http://blog.seiji.me/blog/2008/12/26/421</id>
    <content type="html"><![CDATA[<p>
    <br />
<img src="http://img.seiji.me/blog/2008/12/making-cgrect1.png" alt="Making CGRect.png" border="0" width="210" height="181" />
    <br />

</p>


<p>CGRectには様々な作成方法があります。それをまとめておきます。
</p>


<p>下のようなCGRectを作成したいと思います。
</p>


<h4>出力</h4>


<pre class="console"><code>HelloWorld[52159:20b] {{0, 0}, {320, 480}}
</code></pre>


<br />




<!--more-->


<h4>作成方法1</h4>


<pre><code>CGRect rect = CGRectMake(0, 0, 320, 480);
</code></pre>




<h4>作成方法2</h4>


<pre><code>CGRect rect = {{0,0}, {320, 480}};
</code></pre>




<h4>作成方法3</h4>


<pre><code>CGSize size = CGSizeMake(320, 480);
CGRect rect = {{0,0}, size};
</code></pre>




<h4>作成方法4</h4>


<pre><code>CGPoint point = CGPointMake(0, 0);
CGSize size = CGSizeMake(320, 480);
CGRect rect = {point, size};
</code></pre>




<h4>作成方法5</h4>


<pre><code>CGSize size = CGSizeMake(320, 480);
CGRect rect = {{0}, size};
</code></pre>




<h4>作成方法6</h4>


<pre><code>CGSize size = CGSizeMake(320, 480);
CGRect rect = {{}, size};
</code></pre>




<p>他にもいろいろあるかとは思いますが、構造で定義できるのは便利ですね。</p>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[^NSStringFrom.* functions]]></title>
    <link href="http://blog.seiji.me/blog/2008/12/25/405/" />
    <updated>2008-12-25T00:00:00+09:00</updated>
    <id>http://blog.seiji.me/blog/2008/12/25/405</id>
    <content type="html"><![CDATA[<p>NSStringFromから続くFunctionは非常に便利です。特にCGRect, CGPoint, CGSizeを出力したい場合も展開して出力するのは面倒です。</p>


<p>
    <br />
<img src="http://img.seiji.me/blog/2008/12/uikit-function-reference.jpg" alt="UIKit Function Reference — デベロッパドキュメント.jpg" border="0" width="224" height="193" />
    <br />

</p>




<!--more-->


<p> NSStringFromCGRect, NSStringFromClassを使い次のように出力してみます。</p>


<pre><code>// CGRect
NSLog(@"%@", NSStringFromCGRect([self.view bounds]));
// Class
NSLog(@"%@", NSStringFromClass([[[UIApplication sharedApplication] delegate] class]));
</code></pre>


<h4>出力</h4>


<pre class="console"><code>2008-12-25 19:44:29.628 HelloWorld[39711:20b] {{0, 0}, {320, 460}}
2008-12-25 19:44:29.629 HelloWorld[39711:20b] HelloWorldAppDelegate</code></pre>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[UINavigationBarを見えなくする-iPhone App]]></title>
    <link href="http://blog.seiji.me/blog/2008/12/25/399/" />
    <updated>2008-12-25T00:00:00+09:00</updated>
    <id>http://blog.seiji.me/blog/2008/12/25/399</id>
    <content type="html"><![CDATA[<p>UINavigationBarを見えなくする。</p>


<p>
    <br />
<img src="http://img.seiji.me/blog/2008/12/iphone-2.png" alt="iPhone シミュレータ-2.png" border="0" width="230" height="183" />
    <br />
</p>




<p>UINavigationControllerを使いたいんだけど、UINavigationBarが邪魔な時。下の一行を追加すればよいです。</p>


<pre>`self.navigationController.navigationBar.frame = CGRectZero;`</pre>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[OCUnitのTestCase作成]]></title>
    <link href="http://blog.seiji.me/blog/2008/12/18/389/" />
    <updated>2008-12-18T00:00:00+09:00</updated>
    <id>http://blog.seiji.me/blog/2008/12/18/389</id>
    <content type="html"><![CDATA[<p>OCUnitとはObjective-C用のUnitTest用Frameworkです。
</p>


<p>今回はこのOCUnitを試してみたいと思います。-setUp, -tearDownなどJUnitなどのxUnitを使用した経験がある方なら非常に親しみやすいと言えます。</p>




<!--more-->


<p>以下は全てX-Code上で行います。</p>


<h3>UnitTest対象</h3>

<p>UnitTestの対象として例えば以下のようなクラスを作成します。</p>


<h4>Person.h</h4>


<pre><code>#import <foundation/Foundation.h>

@interface Person : NSObject {
    NSString *displayName;
}
@property (copy) NSString *displayName;

- (id)initWithName:(NSString *)displayName;

@end
</code></pre>


<h4>Person.m</h4>


<pre><code>#import "Person.h"

@implementation Person

@synthesize displayName;

- (id)initWithName:(NSString *)aName {
    if ((self = [super init])!= nil) {
        self.displayName = aName;
    }
    return self;
}

- (void) dealloc {
    [displayName release];
    [super dealloc];
}

@end</code></pre>


<h3>新規ターゲットの作成</h3>

<ol>
    <li>ターゲットを選択し、新規ターゲットの作成を選択</li>
    <li>Cocoa &gt;&gt; Unit Test Bundleを選択し、次へ</li>
    <li>名前を例えばUnitTestsにして完了</li>
</ol>


<h3>ターゲットUnitTestsの情報の変更</h3>

<ol>
    <li>ビルド &gt;&gt; リンク &gt;&gt;他のリンクフラグのCocoaをFoundationに変更する</li>
    <li>ビルド &gt;&gt; ユーザー定義 で以下の項目以外を削除する。
        <ul>
            <li>GCC_C_LANGUAGE_STANDARD</li>
            <li>GCC_WARN_ABOUT_RETURN_TYPE</li>
            <li>GCC_WARN_UNUSED_VARIABLE</li>
        </ul>
    </li>
</ol>


<h3>Person.mのターゲット修正</h3>

<ol>
    <li>Person.mのターゲットの中にUnitTestsを追加する</li>
</ol>


<h3>新規TestCaseの作成</h3>

<ol>
    <li>ファイル &gt;&gt 新規ファイルを選択</li>
    <li>Cocoa Touch Classes &gt;&gt; NSObject subclassを選択し、次へ</li>
    <li>名前を例えばPersonTest、ターゲットをUnitTestsにして完了</li>
</ol>


<h3>TestCaseの実装</h3>

<h4>PersonTest.h</h4>


<pre><code>#import <senTestingKit/SenTestingKit.h>

@class Person;
@interface PersonTest : SenTestCase {
    Person *person;
}

@end</code></pre>


<h4>PersonTest.m</h4>


<pre><code>#import "PersonTest.h"
#import "Person.h"

@implementation PersonTest

- (void)setUp {
    person = [[Person alloc] init];
}

- (void)testCreatePerson {
    STAssertNotNil(person, @"Couldn't create Person");
}

- (void)testSetDisplayName {
    NSString *displayName = @"Seiji";
    person.displayName = displayName;
    STAssertEqualObjects(displayName, person.displayName, @"Couldn't set person.displayName");
}

- (void)tearDown {
    [person release];
}

@end</code></pre>


<h3>TestCaseの実行</h3>

<p>UnitTestsを選択し、Buildを行うことでTestCaseが実行される。想定結果が違うものであればBuildの時点でErrorが表示されることになります。</p>


<h6>References</h6>


<ul>
    <li><a href="http://developer.apple.com/tools/unittest.html">Test Driving Your Code with OCUnit</a></li>
    <li><a href="http://www.stanford.edu/class/cs193p/cgi-bin/index.php">Lecture 19 - Unit Testing, Objective-C Runtime Fun and Localization</a></li>
</ul>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[NSInvocationOperation,delegatePattern-CS193P]]></title>
    <link href="http://blog.seiji.me/blog/2008/12/13/387/" />
    <updated>2008-12-13T00:00:00+09:00</updated>
    <id>http://blog.seiji.me/blog/2008/12/13/387</id>
    <content type="html"><![CDATA[<h3>NSInvocationOperation,delegatePattern</h3>

<p>Lecture12迄の内容を基に&#8221;Presence&#8221;アプリケーションを拡張していきます。
AssignmentPresence3になります。
<br />
<img src="http://img.seiji.me/blog/2008/11/cs193p-cocoa-programming-announcements.jpg" alt="CS193P - Cocoa Programming | Announcements.jpg" border="0" width="430" height="89" />
    <br />
    <q>
        <cite><a href="http://www.stanford.edu/class/cs193p/cgi-bin/index.php">iPhone Application Programming</a></cite>
    </q>
</p>


<!--more-->


<p>
今迄、作成したソースは<a href="http://public.me.com/seijit/iPhone/CS193P">http://public.me.com/seijit/iPhone/CS193P</a>から
</p>


<h3>今回の目標</h3>

<p>前回迄は全てMainThreadで通信を行っていました。その為、待ち時間が長く感じられ、ストレスを受けていたのではないかと思います。今回はそのストレスを軽減する為に別Threadで通信を行い、最後にMainThreadの処理を返すように実装を行います。アプリケーションとしては下の図のように自分のStatusをUpdateする画面を用意し、そこからSendできるようにします。
<br /><br />
<img src="http://img.seiji.me/blog/2008/12/presence-part3-1-1.jpg" alt="Presence-Part3-1-1.jpg" border="0" width="400" />
</p>


<p>
今回は全てを記述するのは大変なので、要点を絞って記載します。
</p>


<h3><img src="http://img.seiji.me/blog/2008/11/xcode.png" alt="picture.png" border="0" width="30" height="30" />NSInvocationOperationの作成</h3>


<p>ViewがLoadされる際にSelector(synchronousLoadsTwitterUsers)を指定してNSInvocationOperationを作成し、それをNSInvocationOperationQueueにAddします。その中で通信部分の処理を行っています。</p>


<p>また、作成時に指定したSelector内部ではSelector(didFinishLoadingTwitterUsersWithResults)を指定してMainThreadに返しています。
</p>


<pre><code>- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    if ([myData count] == 0) {
        [self showLoadingIndicators];
        [self beginLoadingTwitterUsers];
    }
}
- (void)beginLoadingTwitterUsers {
    [myData removeAllObjects];

    NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(synchronousLoadsTwitterUsers) object:nil];
    [operationQueue addOperation:operation];
    [operation release];
}
- (void)synchronousLoadsTwitterUsers {
    NSBundle *bundle = [NSBundle mainBundle];
    NSArray *twitterUsers = [NSArray arrayWithContentsOfFile:[bundle pathForResource:@"TwitterUsers" ofType:@"plist"]];

    for (NSString *userName in twitterUsers){
        Person *person = [[Person alloc] initWithPersonName:userName];
        if (person)
            [myData addObject:person];
        [person release];
    }
    [self performSelectorOnMainThread:@selector(didFinishLoadingTwitterUsersWithResults) withObject:nil waitUntilDone:NO];
}
- (void)didFinishLoadingTwitterUsersWithResults {
    [self hideLoadingIndicators];
    [self.tableView reloadData];
    [self.tableView flashScrollIndicators];
}</code></pre>




<h3><img src="http://img.seiji.me/blog/2008/11/xcode.png" alt="picture.png" border="0" width="30" height="30" />delegete Patternの使用</h3>


<p>NavigationItemのRightBarButtonItemをクリックするとStatusComposeする画面をModallyに出すようにしています。</p>


<pre><code>
- (void)viewDidLoad {
    [super viewDidLoad];
    UIBarButtonItem *addButton = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemCompose target:self action:@selector(presentModally) ];
    self.navigationItem.rightBarButtonItem = addButton;
    [addButton release];
}
- (void)presentModally {
    StatusComposeViewController *statusController = [[StatusComposeViewController alloc]initWithNibName:@"StatusCompose" bundle:nil];
    statusController.delegate = self;
    [self presentModalViewController:statusController animated:YES];
    [statusController release];
}
</code></pre>


<p>この場合、このActionは今回で言うとPersonListViewControllerに実装するわけです。ではこの画面を消すActionはどこに書けばいいのでしょうか？</p>




<p>単純にStatusComposeViewControllerに下のように実装しても消すことはできます。</p>


<pre><code>
[self.navigationController dismissModalViewControllerAnimated:YES];
</code></pre>


<p>しかし、PresentとDismissするのは同じContorollerからするのが望ましいと言われています。別の操作を行うのにもこの方が操作をしやすいでしょう。</p>


<p>ここでdelegatePatternを使用します。</p>


<h4>Protocolの作成</h4>


<pre><code>@class StatusComposeViewController;

@protocol StatusComposeViewDelegate <nsobject>
@optional
- (void)statusComposeViewControllerDidFinish:(StatusComposeViewController *)controller;
- (void)statusComposeViewControllerDidCancel:(StatusComposeViewController *)controller;
@end</code></pre>


<p>今回のdelegateの為のProtocolを作成します。</p>


<h4>Propertyの追加</h4>


<pre><code>
@interface StatusComposeViewController : UIViewController <uitextFieldDelegate> {
    // 略
    id <statusComposeViewDelegate> delegate;
}
    // 略
@property (nonatomic, assign) id <statusComposeViewDelegate> delegate;
    // 略
@end
</code></pre>


<p>StatusComposeViewControllerにStatusComposeViewDelegateを満たしたid型の属性を追加します。</p>




<h4>StatusComposeViewDelegateの実装</h4>


<p> StatusComposeViewDelegateのメソッド(statusComposeViewControllerDidFinish:, statusComposeViewControllerDidCancel: )を実装します。</p>




<p>これでStatusComposeViewController側でStatusComposeViewDelegateで実装されたPersonListViewControllerのメソッド(i.e [self.delegate statusComposeViewControllerDidFinish:])を呼べばよいわけです。</p>




<p>これでAssignmentPresence3を終了としたいと思います。<br /><br />
今回作成したソースは<a href="http://public.me.com/seijit/iPhone/CS193P/Lecture12">http://public.me.com/seijit/iPhone/CS193P/Lecture12</a>のPresence5.tar.gzです
</p>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[UITableViewDelegate, UITableViewDataSource-CS193P]]></title>
    <link href="http://blog.seiji.me/blog/2008/12/11/384/" />
    <updated>2008-12-11T00:00:00+09:00</updated>
    <id>http://blog.seiji.me/blog/2008/12/11/384</id>
    <content type="html"><![CDATA[<h3>UITableViewDelegate, UITableViewDataSource</h3>

<p>前回<a href="http://blog.seiji.me/374.html">plistの読込み、UITableViewCellAccessory-CS193P</a>の続きになります。
AssignmentPresence2の後半にあたります。
<br />
<img src="http://img.seiji.me/blog/2008/11/cs193p-cocoa-programming-announcements.jpg" alt="CS193P - Cocoa Programming | Announcements.jpg" border="0" width="430" height="89" />
    <br />
    <q>
        <cite><a href="http://www.stanford.edu/class/cs193p/cgi-bin/index.php">iPhone Application Programming</a></cite>
    </q>
</p>


<!--more-->


<p>
今迄、作成したソースは<a href="http://public.me.com/seijit/iPhone/CS193P">http://public.me.com/seijit/iPhone/CS193P</a>から
</p>


<h3>今回の目標</h3>

<p>PersonDetailViewControllerを修正し、下のアプリケーションを完成させるのが目的です。List,Detail共にTableViewを使用しています。ListがUITableViewStylePlain, Detailの方がUITableViewStyleGroupedとStyleを変えて表示をしています。
<br />
<br />
<img src="http://img.seiji.me/blog/2008/12/app-11.png" alt="app-1.png" border="0" width="400" height="391" />
</p>


<h3><img src="http://img.seiji.me/blog/2008/11/picture.png" alt="picture.png" border="0" width="30" height="30" />PersonDetail.xibの変更</h3>


<p>PersonDetail.xibをWクリックし、InterfaceBuilderを起動します。ここではViewを大幅に変更します。</p>


<p>View上にUITableViewのみを配置し、AttributesInspectorでTableViewのStyleを&#8221;Grouped&#8221;にします。
<br />
<br />
<a href="http://img.seiji.me/blog/2008/12/1-2.png"><img src="http://img.seiji.me/blog/2008/12/1-2.png" alt="ピクチャ 1-2.png" border="0" width="400" /></a>
</p>


<p>ConnectionsInspectorでPersonDetailViewControllerのviewをTableViewに、TableViewのdataSource,delegateをPersonDetailViewControllerに接続します。
<br /><br />
<img src="http://img.seiji.me/blog/2008/12/table-view-connections-1.png" alt="Table View Connections-1.png" border="0" width="316" height="186" />
</p>


<p>
PersonList.xibでは同じTableViewを使っているのにdataSource,delegateの接続は行いませんでした。この違いはPersonLisrViewControllerはTableViewControllerのSubClassに対して、PersonDetailViewControllerはUIViewControllerのSubClassだからです。</p>


<h3><img src="http://img.seiji.me/blog/2008/11/xcode.png" alt="xcode.png" border="0" width="30" height="30" />PersonDetailViewControllerの修正</h3>


<p>
PersonDetailViewControllerはPersonListViewControllerとは違った形でTableViewを表示させます。ProtocolであるUITableViewDelegate, UITableViewDataSourceの実装を行います。</p>


<h4>PersonDetailViewController</h4>


<h5>PersonDetailViewController.h</h5>


<pre><code>#import &lt;UIKit/UIKit.h&gt;

@class Person;
@interface PersonDetailViewController : UIViewController &lt;UITableViewDelegate, UITableViewDataSource&gt;  {
    Person* person;
}
@property (nonatomic, assign) Person* person;

@end
</code></pre>


<p>
ProtocolであるUITableViewDelegate, UITableViewDataSourceの宣言をしています。</p>


<h5>PersonDetailViewController.m</h5>


<pre><code>#import "PersonDetailViewController.h"
#import "Person.h"
#import "PersonText.h"

@implementation PersonDetailViewController
@synthesize person;

// 略
@end
</code></pre>


<p>
UITableViewDelegate, UITableViewDataSourceのメソッドを実装します。
</p>


<pre><code>- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section {
    return [person.textArray count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"MyIdentifer";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
    }
    // Set up the cell...
    PersonText *personText = [person.textArray objectAtIndex:indexPath.row];
    UILabel *textField = [[UILabel alloc] initWithFrame:CGRectMake(20, 6, personText.size.width, personText.size.height)];
    [textField setText:[NSString stringWithCString:[personText.textString UTF8String] encoding:NSUTF8StringEncoding]];
    [textField setBackgroundColor:[UIColor clearColor]];
    [textField setLineBreakMode:UILineBreakModeWordWrap];
    [textField setFont:personText.font];
    [textField setHighlightedTextColor:[UIColor whiteColor]];
    [textField setNumberOfLines:0];
    [cell addSubview:textField];
    [textField release];

    return cell;
}</code></pre>


<p>行の数とUITableViewCellの中身の表示を行うメソッドです。UILabelを作成し、UITableViewCellのSubViewとして追加しています。</p>


<pre><code>
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    // Return the displayed title for the specified section.
    return @"Statuses";
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    PersonText *personText = [person.textArray objectAtIndex:indexPath.row];
    int padding = 10;
    return personText.size.height + padding;
}
</code></pre>


<p>Sectionのヘッダ名を返すメソッドと、各UITableViewCellの高さを返すメソッドです。ここで動的にUITabelViewCellの高さを変化させています。</p>




<h4>PersonListViewController</h4>


<p>最後にPersonListのUITableViewCellをクリックした際のメソッドを変更しておきます。ここでPersonDetailViewControllerを作成し、UINavigationContollerのStackに追加しています。</p>


<h5>PersonListViewController.m</h5>


<pre><code>- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    // Navigation logic may go here. Create and push another view controller.
    PersonDetailViewController *detailViewController = [[PersonDetailViewController alloc] initWithNibName:@"PersonDetail" bundle:nil];
    int personIndex = [indexPath indexAtPosition: [indexPath length] - 1];
    detailViewController.person = [myData objectAtIndex:personIndex];
    [self.navigationController pushViewController:detailViewController animated:YES];
    [detailViewController release];
}</code></pre>


<p>これでAssignmentPresence2ができました。<br /><br />
今回作成したソースは<a href="http://public.me.com/seijit/iPhone/CS193P/Lecture9">http://public.me.com/seijit/iPhone/CS193P/Lecture9</a>のPresence4.tar.gzです。
</p>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[plistの読込み、UITableViewCellAccessory-CS193P]]></title>
    <link href="http://blog.seiji.me/blog/2008/12/11/374/" />
    <updated>2008-12-11T00:00:00+09:00</updated>
    <id>http://blog.seiji.me/blog/2008/12/11/374</id>
    <content type="html"><![CDATA[<h3>plistの読込み、UITableViewCellAccessory</h3>

<p>Lecture9迄の内容を基に&#8221;Presence&#8221;アプリケーションを拡張していきます。
AssignmentPresence2の前半になります。
<br />
<img src="http://img.seiji.me/blog/2008/11/cs193p-cocoa-programming-announcements.jpg" alt="CS193P - Cocoa Programming | Announcements.jpg" border="0" width="430" height="89" />
    <br />
    <q>
        <cite><a href="http://www.stanford.edu/class/cs193p/cgi-bin/index.php">iPhone Application Programming</a></cite>
    </q>
</p>


<!--more-->


<p>
今迄、作成したソースは<a href="http://public.me.com/seijit/iPhone/CS193P">http://public.me.com/seijit/iPhone/CS193P</a>から
</p>


<h3>今回の目標</h3>

<p>前回のPersonListViewControllerを修正し、下のアプリケーションの内、左側を表示できるようになるのが目的です。<br />
<br /><img src="http://img.seiji.me/blog/2008/12/app-1.png" alt="app-1.png" border="0" width="400" height="331" /></p>


<p>Performanceは今は考えてなくてよいとのことなので、Performanceは一切考慮していません。</p>


<h3><img src="http://img.seiji.me/blog/2008/11/xcode.png" alt="xcode.png" border="0" width="30" height="30" /> 前準備</h3>


<h4>プロジェクトへの追加</h4>


<p>Presence2Files.zipに含まれていますTwitterAPI部分のソース、TwitterUsers.plistを追加します。TwitterUsers.plistは好きなUserに変更します。
<br />
<br />
<img src="http://img.seiji.me/blog/2008/12/init-presence.png" alt="init — Presence.png" border="0" width="268" height="528" />
</p>


<h4>TwitterHelperの修正</h4>


<p>
TwitterAPIはデフォルトで20件を返します。そんなに必要ないので5件にします。また、encodingが指定されてないので、指定します。その結果、下のようになります。
</p>


<h5>TwitterHelper.m</h5>


<pre><code>+ (NSArray *)fetchTimelineForUsername:(NSString *)username
{
    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://twitter.com/statuses/user_timeline/%@.json?count=5", username]];
    NSString *string = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
    return [string JSONValue];
}
</code></pre>


<h3><img src="http://img.seiji.me/blog/2008/11/xcode.png" alt="xcode.png" border="0" width="30" height="30" /> Modelの作成</h3>


<p>
起動時にTwiiterにアクセスし、必要な情報をメモリ上に格納します。その為のModelを作成します。例えば、Userの情報を格納するPersonクラス、Userのつぶやきを格納するPersonTextクラスを作成します。
</p>


<h4>Personクラス</h4>


<h5>Person.h</h5>


<pre><code>import &lt;Foundation/Foundation.h&gt;

@interface Person : NSObject {
    NSString *name;
    NSString *screenName;
    NSString *profileImageURL;
    NSMutableArray *textArray;
}
@property (nonatomic, retain) NSString *name;
@property (nonatomic, retain) NSString *screenName;
@property (nonatomic, retain) NSString *profileImageURL;
@property (nonatomic, retain) NSMutableArray *textArray;

- (id)initWithPersonName:(NSString *)name;
- (id)createPerson:(NSString *)personName;
- (NSString *)description;
- (void)dealloc;

@end
</code></pre>


<h5>Person.m</h5>


<pre><code>#import "Person.h"
#import "PersonText.h"
#import "TwitterHelper.h"

@implementation Person
@synthesize name, screenName, profileImageURL, textArray;

- (id)initWithPersonName:(NSString *)personName {
    if ( (self =[super init])!= nil ) {
        self = [self createPerson:personName];
    }
    return self;
}

- (id)createPerson:(NSString *)personName {
    // name
    self.screenName = personName;
    // Twitter API
    NSArray *array = [TwitterHelper fetchTimelineForUsername:personName];
    if([array count]==0) {
        return nil;
    }
    NSDictionary *user = [[array objectAtIndex:0] objectForKey:@"user"];
    self.profileImageURL = [user objectForKey:@"profile_image_url"];
    self.name = [user objectForKey:@"name"];

    self.textArray = [NSMutableArray array];
    NSDictionary *dic;
    for (dic in array) {
        NSString *text = [dic objectForKey:@"text"];
        if (text) {
            PersonText *personText = [[PersonText alloc] initWithText:text font:[UIFont systemFontOfSize:[UIFont systemFontSize]]];
            [self.textArray addObject:personText];
            [personText release];
        }
    }

    return self;
}
// 略
@end
</code></pre>


<h4>PersonTextクラス</h4>


<h5>PersonText.h</h5>


<pre><code>#import &lt;Foundation/Foundation.h&gt;

@interface PersonText : NSObject
{
    NSString *textString;
    UIFont *font;
    CGSize size;
}
@property (nonatomic, retain)NSString *textString;
@property (nonatomic, retain)UIFont *font;
@property (nonatomic)CGSize size;

- (id)initWithText:(NSString *)text font:(UIFont *)fontObj;
- (void)dealloc;

@end
</code></pre>


<h5>PersonText.m</h5>


<pre><code>#import "PersonText.h"

@implementation PersonText

@synthesize textString;
@synthesize font;
@synthesize size;

- (id)initWithText:(NSString *)txt font:(UIFont *)fontObj;{
    if ((self = [super init])!= nil) {
        self.textString = txt;
        self.font = fontObj;
        CGSize withinSize = CGSizeMake(280, 1000);
        self.size = [textString sizeWithFont:font constrainedToSize:withinSize lineBreakMode:UILineBreakModeWordWrap];
    }
    return self;
}

// 略
@end
</code></pre>


<p>PersonTextの方は初期化の際にwidth280pxをした際に高さを計算する為にサイズを求めています。
</p>




<h3><img src="http://img.seiji.me/blog/2008/11/xcode.png" alt="xcode.png" border="0" width="30" height="30" /> PersonListViewControllerの修正</h3>


<p>PersonListViewController.mを修正していきます。
</p>


<h4>plistの読込み</h4>


<pre><code>- (void)viewDidLoad {
    [super viewDidLoad];
    // load data
    self.myData = [NSMutableArray array];
    NSBundle *bundle = [NSBundle mainBundle];

    // Load plist
    NSArray *twitterUsers = [NSArray arrayWithContentsOfFile:[bundle pathForResource:@"TwitterUsers" ofType:@"plist"]];
    NSString *userName;

    for (userName in twitterUsers){
        Person *person = [[Person alloc] initWithPersonName:userName];
        if (person)
            [myData addObject:person];
        [person release];
    }
}</code></pre>


<p>viewDidLoadの際にTwitterへアクセスし、Personインスタンスが要素のNSMutableArrayを作成しています。</p>


<h4>List表示</h4>


<pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
    }

    // Set up the cell...
    int personIndex = [indexPath indexAtPosition: [indexPath length] - 1];
    Person *person = [myData objectAtIndex:personIndex];
    NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:person.profileImageURL]];
    UIImage *image= [UIImage imageWithData:imageData];

    [cell setImage:image];
    [cell setText:person.name];
    return cell;
}</code></pre>


<p>各Personインスタンスを展開しています。ここでも画像へのアクセスを行っています。</p>


<h4>UITableViewCellAccessory</h4>


<pre><code>- (UITableViewCellAccessoryType)tableView:(UITableView *)table accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath {
    return UITableViewCellAccessoryDisclosureIndicator;
    //return UITableViewCellAccessoryDetailDisclosureButton;
    //return UITableViewCellAccessoryCheckmark;
}</code></pre>


<p>最後にCellの右側に表示されるUITableViewCellAccessoryを表示させる為にメソッドを実装しています。</p>




<p>これでplistから読み込んだPersonListが表示されるはずです。<br /><br />
今回作成したソースは<a href="http://public.me.com/seijit/iPhone/CS193P/Lecture9">http://public.me.com/seijit/iPhone/CS193P/Lecture9</a>のPresence3.tar.gzです。
</p>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[navigation stackへの追加-CS193P]]></title>
    <link href="http://blog.seiji.me/blog/2008/12/06/363/" />
    <updated>2008-12-06T00:00:00+09:00</updated>
    <id>http://blog.seiji.me/blog/2008/12/06/363</id>
    <content type="html"><![CDATA[<h3>navigation stackへの追加</h3>

<p>前回<a href="http://blog.seiji.me/354.html">UINavigationController, TableViewControllerの作成-CS193P</a>の続きになります。ViewControllerインスタンスをnavigation stackへと追加するところが中心となります。
<br />
<img src="http://img.seiji.me/blog/2008/11/cs193p-cocoa-programming-announcements.jpg" alt="CS193P - Cocoa Programming | Announcements.jpg" border="0" width="430" height="89" />
    <br />
    <q>
        <cite><a href="http://www.stanford.edu/class/cs193p/cgi-bin/index.php">iPhone Application Programming</a></cite>
    </q>
</p>


<!--more-->


<p>
今迄、作成したソースは<a href="http://public.me.com/seijit/iPhone/CS193P">http://public.me.com/seijit/iPhone/CS193P</a>から
</p>


<h3>今回の目標</h3>

<p>下の図のようなアプリケーションの内、PersonListを選択し、DetailViewを表示できるようになるのが目標です。（右側の図）
<br /><img src="http://img.seiji.me/blog/2008/12/target-1.png" alt="target-1.png" border="0" width="400" height="337" /></p>


<h3><img src="http://img.seiji.me/blog/2008/11/xcode.png" alt="xcode.png" border="0" width="30" height="30" />ViewControler,xibの作成</h3>


<p>今迄と同じようなことなので、図は省略します。</p>


<ol>
    <li>TemplateからViewControllerのSubClassを選択し、名前を&#8221;PersonDetailViewController&#8221;とします。</li>
    <li>TemplateからView XIBを選択し、名前を&#8221;PersonDetail.xib&#8221;とします。</li>
</ol>


<h4>PersonDetailViewControllerの実装</h4>


<p>新しく作成したPersonDetailViewControllerを実装します。</p>


<h5>PersonDetailViewController.h</h5>


<pre><code>#import &lt;UIKit/UIKit.h&gt;

@interface PersonDetailViewController : UIViewController {
    NSDictionary* dict;
    IBOutlet UILabel *name;
    IBOutlet UIImageView *imageView;
}

@property (nonatomic, assign) NSDictionary* dict;
@property (nonatomic, retain) UILabel *name;
@property (nonatomic, retain) UIImageView *imageView;
@end</code></pre>


<h5>PersonDetailViewController.m</h5>


<p>viewがLoadされた後にNSDictionaryのデータをOutletに展開しています。</p>


<pre><code>#import "PersonDetailViewController.h"

@implementation PersonDetailViewController
@synthesize dict;
@synthesize name;
@synthesize imageView;

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
    [self.navigationItem setTitle:@"Detail"];
    [name setText:[self.dict objectForKey:@"name"]];
    [imageView setImage:[UIImage imageWithContentsOfFile:[self.dict objectForKey:@"path"]]];
}

// 間省略
- (void)dealloc {
    [name release];
    [imageView release];
    [super dealloc];
}

@end</code></pre>




<h3><img src="http://img.seiji.me/blog/2008/11/picture.png" alt="picture.png" border="0" width="30" height="30" />PersonDetailViewControllerとViewとの接続</h3>


<h4>PersonDetail.xib</h4>


<p> PersonDetail.xibをWクリックしInterfaceBuilderを起動します。Viewを例えば下の図のようにします。<br /><br />
<img src="http://img.seiji.me/blog/2008/12/view.png" alt="View.png" border="0" width="200" height="313" /><br /><br />
その後、下の作業を行います。
</p>


<ol>
    <li>File&#8217;s Ownerのクラス名をPersonDetailViewControllerとする。</li>
    <li>PersonDetailViewControllerの&#8221;view&#8221;をUIViewに接続する。</li>
    <li>PersonDetailViewControllerの&#8221;name&#8221;, &#8220;imageView&#8221;をそれぞれUILabel, UIImageViewに接続する。</li>
</ol>


<h3><img src="http://img.seiji.me/blog/2008/11/xcode.png" alt="xcode.png" border="0" width="30" height="30" />PersonListViewControllerの修正</h3>


<p>今回作成した、PersonDetailViewControllerはこのままではLoadされません。このPresenceアプリケーションに組み込む必要があります。</p>


<h4> PersonListViewController.m </h4>


<pre><code>- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    // Navigation logic may go here. Create and push another view controller.
    PersonDetailViewController *detailViewController = [[PersonDetailViewController alloc] initWithNibName:@"PersonDetail" bundle:nil];
    int personIndex = [indexPath indexAtPosition: [indexPath length] - 1];
    detailViewController.dict = [myData objectAtIndex:personIndex];
    [self.navigationController pushViewController:detailViewController animated:NO];
    [detailViewController release];
}</code></pre>


<p>これはTableViewのCellを選択した場合にCallされるメソッドです。PersonDetailViewController.hをImportすることも必要です。</p>


<p>これで下のように動作するかと思います。
<br /><br /><img src="http://img.seiji.me/blog/2008/12/target-1.png" alt="target-1.png" border="0" width="400" height="337" /><br /><br />
今回作成したソース<br />
<a href="http://public.me.com/seijit/iPhone/CS193P/Lecture7">http://public.me.com/seijit/iPhone/CS193P/Lecture7</a>:Presence2.tar.gz
</p>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[UINavigationController, TableViewControllerの作成-CS193P]]></title>
    <link href="http://blog.seiji.me/blog/2008/12/06/354/" />
    <updated>2008-12-06T00:00:00+09:00</updated>
    <id>http://blog.seiji.me/blog/2008/12/06/354</id>
    <content type="html"><![CDATA[<h3>UINavigationControllerの作成</h3>

<p>Lecture7を基に、新しい課題&#8221;Presence&#8221;アプリケーションを作成していきます。実際の内容と脱線するところもありますが、ご了承下さい。
<br />
<img src="http://img.seiji.me/blog/2008/11/cs193p-cocoa-programming-announcements.jpg" alt="CS193P - Cocoa Programming | Announcements.jpg" border="0" width="430" height="89" />
    <br />
    <q>
        <cite><a href="http://www.stanford.edu/class/cs193p/cgi-bin/index.php">iPhone Application Programming</a></cite>
    </q>
</p>


<!--more-->


<p>
今迄、作成したソースは<a href="http://public.me.com/seijit/iPhone/CS193P">http://public.me.com/seijit/iPhone/CS193P</a>から
</p>


<h3>今回の目標</h3>

<p>下の図のようなアプリケーションの内、PersonListをTableViewで表示できるようになるのが目標です。（左側の図）
<br /><img src="http://img.seiji.me/blog/2008/12/target-1.png" alt="target-1.png" border="0" width="400" height="337" /></p>




<h3><img src="http://img.seiji.me/blog/2008/11/xcode.png" alt="xcode.png" border="0" width="30" height="30" />新規プロジェクト、ViewControlerの作成</h3>


<h4>新規プロジェクト作成</h4>


<p>Navigation-Based Applicationを選択すれば簡単なのですが、今回はあえてWindow-Based Application を選択して作成していきます。プロジェクト名は&#8221;Presence&#8221;とします。<br /><br />
<img src="http://img.seiji.me/blog/2008/12/200812052345.jpg" alt="200812052345.jpg" border="0" width="400" height="301" />
</p>


<h4>TableViewController, xibファイルの作成</h4>


<p>ViewControllerとして今回はTableViewControllerを作成します。また、それに対応するxibファイルを作成します。TableViewControllerのサブクラスのファイル名を&#8221;PersonListViewController&#8221;,xibファイル名を&#8221;PersonList.xib&#8221;とします。<br /><br />
<img src="http://img.seiji.me/blog/2008/12/2-1.jpg" alt="2-1.jpg" border="0" width="400" height="303" /><br /><br /><img src="http://img.seiji.me/blog/2008/12/2-2.jpg" alt="新規ファイル.jpg" border="0" width="400" height="303" />

</p>


<h4>PresenceAppDelegateの修正</h4>


<p>以前、ViewControllerを追加した同様のやり方で、UINavigationControllerをDelegateクラスに追加します。</p>


<h5>PresenceAppDelegate.h</h5>


<pre><code>#import <uikit/UIKit.h>
@interface PresenceAppDelegate : NSObject <uiapplicationDelegate> {
    UIWindow *window;
    UINavigationController *navController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navController;
@end
</code></pre>


<h5>PresenceAppDelegate.m</h5>


<pre><code>#import "PresenceAppDelegate.h"
@implementation PresenceAppDelegate
@synthesize window;
@synthesize navController;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
    // Override point for customization after application launch
    [window addSubview:[navController view]];
    [window makeKeyAndVisible];
}

- (void)dealloc {
    [window release];
    [navController release];
    [super dealloc];
}
@end
</code></pre>




<h3><img src="http://img.seiji.me/blog/2008/11/picture.png" alt="picture.png" border="0" width="30" height="30" />UINavigationControllerの配置・接続</h3>


<h4>MainWindow.xib</h4>


<p>MainWindow.xibをWクリックしInterfaceBuilderを起動します。ここで、UINavigationControllerを配置します。
</p>


<p>LibraryからNavigation ControllerオブジェクトをDrag&DropでDocumentWindow上に作成します。そのオブジェクトに対して、PresenceAppDelegateクラスのOutlet,navControllerを接続します。 <br /><br />
<img src="http://img.seiji.me/blog/2008/12/1.jpg" alt="ピクチャ 1.jpg" border="0" width="400" height="250" />
</p>


<p>Navigation Controllerオブジェクトの下にはView Controllerオブジェクトがあります。このクラス名を&#8221;PersonListViewController&#8221;, NIB Nameを&#8221;PersonList&#8221;とします。 <br /><br />
<img src="http://img.seiji.me/blog/2008/12/21.jpg" alt="ピクチャ 2.jpg" border="0" width="400" height="250" />
</p>


<p>最後にNavigation ControllerオブジェクトをWクリックしView画面を出します。タイトルを&#8221;PersonList&#8221;とします。 <br /><br />
<img src="http://img.seiji.me/blog/2008/12/3.jpg" alt="ピクチャ 3.jpg" border="0" width="400" height="250" />
</p>


<p>これでMainWindow.xibを閉じ、今度はPersonList.xibを開きます。</p>


<h4> PersonList.xib</h4>


<p>初めにLibraryからTableViewを選択しview上にDrag&Dropで配置し、各Cellの高さをSize Inspectorでheightを60.00にします。次にFile&#8217;s OwnerのClass名を&#8221;PersonListViewController&#8221;とし、最後にPersonListViewControllerのviewをTableViewに接続して終了です。<br /><br /><img src="http://img.seiji.me/blog/2008/12/4.jpg" alt="ピクチャ 4.jpg" border="0" width="400" height="250" />
</p>


<p>これで、Navigation-Based Applicationを選択した場合に近いものができました。
</p>




<h3><img src="http://img.seiji.me/blog/2008/11/xcode.png" alt="xcode.png" border="0" width="30" height="30" />TableViewControllerの実装</h3>


<p>先ほど、作成したTableViewControllerのSubClassのPersonListViewControllerの実装を行います。
</p>


<h4>読み込むデータ</h4>


<p>今回、読み込むデータは静的なものにします。Project内(Bundle内)に画像(i.g. Bors.jpg)をDrag&Dropで配置します。今回使用した画像は<a href="http://www.southparkstudios.com/">South Park Studios</a>で作成したものを使わせていただいています。<br /><br />
<img src="http://img.seiji.me/blog/2008/12/personlistviewcontrollerm-presence-1.png" alt="PersonListViewController.m — Presence-1.png" border="0" width="200" height="339" /><br /><br />
ファイルパスを取得し、ファイル名を名前とするわけです。
</p>


<h4>UIImageの拡張</h4>


<p>UIImageはImageを扱うクラスです。今回、用意している画像は120px × 120pxで、このまま表示するとCellからはみだします。画像を縮小して表示したいのですが、UIImageには簡単に行えるのがない為、UIImageのカテゴリを実装し、リサイズの機能を付加します。</p>


<h5>UIImageResize.h</h5>


<pre><code>#import &lt;Foundation/Foundation.h&gt;
@interface UIImage (Resize)
- (UIImage*)resize:(CGRect)rect;
@end</code></pre>




<h5>UIImageResize.m</h5>


<pre><code>#import "UIImageResize.h"

@implementation UIImage (Resize)
- (UIImage*)resize:(CGRect)rect {
    UIGraphicsBeginImageContext(rect.size);
    [self drawInRect:rect];
    UIImage *imageCopy =　UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return imageCopy;
}
@end</code></pre>


<p>これでResizeのメソッドを持つUIImazeを扱えるようになりました。</p>


<h4>PersonListViewController.h</h4>


<pre><code>#import &lt;UIKit/UIKit.h&gt;

@interface PersonListViewController : UITableViewController {
    NSMutableArray *myData;
}

@property (nonatomic, retain) NSArray *myData;
@end</code></pre>




<h4>PersonListViewController.m</h4>


<pre><code>#import "PersonListViewController.h"
#import "UIImageResize.h"

@implementation PersonListViewController
@synthesize myData;

// 間省略

- (void)dealloc {
    [myData release];
    [super dealloc];
}
</code></pre>


<p>Bundleからファイルを読込みNSMutableArrayに格納します。</p>


<pre><code>- (void)viewDidLoad {
    [super viewDidLoad];
    // load data
    self.myData = [NSMutableArray array];
    NSBundle *bundle = [NSBundle mainBundle];
    NSArray *imgPaths = [bundle pathsForResourcesOfType:@"jpg" inDirectory:@""];
    NSString *path;
    for (path in imgPaths) {
        NSString *name =[[path lastPathComponent] substringToIndex:[[path lastPathComponent] length]- [@".jpg" length]];
        NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:name, @"name", path, @"path", nil];
        [myData addObject:dic];
    }
}
</code></pre>


<p>TableViewを表示する為のメソッドを実装します。</p>


<pre><code>// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [myData count];
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
    }

    // Set up the cell...
    int personIndex = [indexPath indexAtPosition: [indexPath length] - 1];
    UIImage *image= [UIImage imageWithContentsOfFile:[[myData objectAtIndex:personIndex] objectForKey:@"path"]];

    [cell setImage:[image resize:CGRectMake(0, 0, 60, 60)]];
    [cell setText:[[myData objectAtIndex:personIndex] objectForKey:@"name"]];
    return cell;
}
</code></pre>




<p>これで下のように動くはずです。<br /><br />
<img src="http://img.seiji.me/blog/2008/12/iphone.png" alt="iPhone シミュレータ.png" border="0" width="200" height="381" /><br /><br />
今回作成したソースは<a href="http://public.me.com/seijit/iPhone/CS193P/Lecture7">http://public.me.com/seijit/iPhone/CS193P/Lecture7</a>のPresence.tar.gzです。
</p>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[VIX指数]]></title>
    <link href="http://blog.seiji.me/blog/2008/12/05/330/" />
    <updated>2008-12-05T00:00:00+09:00</updated>
    <id>http://blog.seiji.me/blog/2008/12/05/330</id>
    <content type="html"><![CDATA[<p>アメリカ市場が底を打ったとか言われていたりするところもありますが、アメリカ自動車業界のBIG3はどうなるんでしょうか？情勢を判断する為にVIX指数をこのサイトに貼ってみることにしました。また、VIX指数は恐怖指数とも呼ばれています。
</p>




<blockquote>
恐怖指数(きょうふしすう、Volatility Index 略称:VIX)とは、シカゴ・オプション取引所(CBOE)が、S&P500を対象とするオプション取引のボラティリティを元に算出、公表している指数。数値が高いほど投資家が相場の先行きに不透明感を持っているとされる。通常は10から20の間で推移する。
    <q>
        <cite><a href="http://ja.wikipedia.org/wiki/恐怖指数">恐怖指数</a></cite>
    </q>
</blockquote>


<br />




<!--more-->


<p>
Chicago Board Option Exchange Volatile Index(CBOE VIX)はGoogle financeにはないんです。なのでYahoo financeからデータをとることにしました。ブログパーツであるかなと思ったのですが、結局WebからScrapingして貼っています。
</p>


<p>
この値が早く下がるような情勢になればよいですね。
</p>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[ハゲタカ]]></title>
    <link href="http://blog.seiji.me/blog/2008/12/03/322/" />
    <updated>2008-12-03T00:00:00+09:00</updated>
    <id>http://blog.seiji.me/blog/2008/12/03/322</id>
    <content type="html"><![CDATA[<p>LBOという略語から読み始めた本「ハゲタカ」。NHKでドラマ化され、今度は映画化もされるとのこと。</p>


<p>
    <br />
<a href="http://amazon.co.jp/o/ASIN/4062753529/seijit-22/ref=nosim" target="_blank"><img src="http://images.amazon.com/images/P/4062753529.09._PC_OU09_SCMZZZZZZZ_.jpg" alt=""></a>
</p>




<!--more-->


<p>
外資系ファンドマネージャー鷲津政彦、そして魅力ある他の登場人物と共に企業に対して不良債権処理、バイアウトをかけていく話です。架空の企業名も親しみのある名前で物語に入り込みやすい内容となっています。
</p>


<blockquote>
レバレッジド・バイアウト（Leveraged Buyout)とは、企業買収の手法の一種。LBOとも略される。<br />
    <q>
        <cite><a href="http://ja.wikipedia.org/wiki/LBO">Leveraged Buyout</a></cite>
    </q>
</blockquote>


<p>
LBOと似た用語でMBO(Management Buyout)もある。このLBO,MBOという手法がこの小説内で使われている。
</p>


<p>
個人的にはハゲタカⅡ（バイアウト）の方が好きです。
ドラマも機会があれば見たいと思います。
</p>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[NSUserDefaultsでのデータ保存-CS193P]]></title>
    <link href="http://blog.seiji.me/blog/2008/11/29/320/" />
    <updated>2008-11-29T00:00:00+09:00</updated>
    <id>http://blog.seiji.me/blog/2008/11/29/320</id>
    <content type="html"><![CDATA[<h3>NSUserDefaultsでのデータ保存</h3>

<p>Lecture6の内容にあたります。前回のHelloPolyプロジェクトを拡張します。今回はアプリケーションの終了・起動時にデータを保存・読込みを行います。具体的にはPolygonの辺の数を保存します。データが存在した場合はその数を使い描画を行います。
    <br />
<img src="http://img.seiji.me/blog/2008/11/cs193p-cocoa-programming-announcements.jpg" alt="CS193P - Cocoa Programming | Announcements.jpg" border="0" width="430" height="89" />
    <br />
    <q>
        <cite><a href="http://www.stanford.edu/class/cs193p/cgi-bin/index.php">iPhone Application Programming</a></cite>
    </q>
</p>


<!--more-->


<p>
今迄、作成したソースは<a href="http://public.me.com/seijit/iPhone/CS193P">http://public.me.com/seijit/iPhone/CS193P</a>から
</p>




<h3><img src="http://img.seiji.me/blog/2008/11/xcode.png" alt="xcode.png" border="0" width="30" height="30" />データの保存</h3>


<p>今回は値が変化したタイミングではなく、アプリケーションが終了した時のみ、データの保存を行います。</p>


<h4>MyUIViewController</h4>


<p>ViewControllerの中でアプリケーション終了時に呼び出されるメソッドを作成します。</p>


<h5>MyUIViewController.h</h5>


<pre>`- (void)willTerminate:(UIApplication *)application;`</pre>


<h5>MyUIViewController.m</h5>


<pre><code>-(void)willTerminate:(UIApplication *)application {
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setInteger:polygon.numberOfSides forKey:NUMBER_OF_SIDES];
}
</code></pre>


<h4>HelloPolyAppDelegate</h4>


<p>HelloPolyAppDelegateでapplicationWillTerminate:を実装し、その中でMyUIViewController::willTerminate:をCallします。</p>


<h5>HelloPolyAppDelegate.m</h5>


<pre><code>- (void)applicationWillTerminate:(UIApplication *)application {
    [myUIViewController willTerminate:application];
}
</code></pre>




<h3><img src="http://img.seiji.me/blog/2008/11/picture.png" alt="picture.png" border="0" width="30" height="30" />データの読込み</h3>


<p>アプリケーション起動時に読込むコードを追加します。</p>


<h4>MyUIViewController </h4>


<p>MyUIViewControllerでviewDidLoad:のメソッド中にコードを追加します。</p>


<h5>MyUIViewController.m</h5>


<pre><code>- (void)viewDidLoad {
    [polygon setMinimumNumberOfSides:3];
    [polygon setMaximumNumberOfSides:12];
    // NSUserDefaults Loading
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    int num = [defaults integerForKey:NUMBER_OF_SIDES];
    if(num == 0) {
        [polygon setNumberOfSides:numberOfSidesLabel.text.integerValue];
    } else {
        [polygon setNumberOfSides:num];
    }
    myUIView.polygon = polygon;
    [self updateInterface];
    [super viewDidLoad];
}
</code></pre>


<p>
値を変えて終了した後、再度起動するとその値が保存されて、描画されるのがわかります。<br />
<img src="http://img.seiji.me/blog/2008/11/iphone-1.jpg" alt="iPhone シミュレータ-1.jpg" border="0" width="290" height="550" />
<br /><br />
今回作成したソースは<a href="http://public.me.com/seijit/iPhone/CS193P/Lecture6">
http://public.me.com/seijit/iPhone/CS193P/Lecture6</a>のHelloPoly4.tar.gzです。
</p>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[UIViewの作成-CS193P]]></title>
    <link href="http://blog.seiji.me/blog/2008/11/29/310/" />
    <updated>2008-11-29T00:00:00+09:00</updated>
    <id>http://blog.seiji.me/blog/2008/11/29/310</id>
    <content type="html"><![CDATA[<h3>UIViewの作成と図形の描画</h3>

<p>前回のHelloPolyプロジェクトを拡張します。今回はUIVIewのSubClassを作成し、図形を描画します。
    <br />
<img src="http://img.seiji.me/blog/2008/11/cs193p-cocoa-programming-announcements.jpg" alt="CS193P - Cocoa Programming | Announcements.jpg" border="0" width="430" height="89" />
    <br />
    <q>
        <cite><a href="http://www.stanford.edu/class/cs193p/cgi-bin/index.php">iPhone Application Programming</a></cite>
    </q>
</p>


<!--more-->


<p>
今迄、作成したソースは<a href="http://public.me.com/seijit/iPhone/CS193P">http://public.me.com/seijit/iPhone/CS193P</a>から
</p>




<h3><img src="http://img.seiji.me/blog/2008/11/xcode.png" alt="xcode.png" border="0" width="30" height="30" /> UIViewのSubClass作成 </h3>


<h4>UIView SubClassテンプレート作成</h4>


<p>UIViewのSubClassを作成します。名前はMyUIViewとします。<br />
<img src="http://img.seiji.me/blog/2008/11/2-1-1.jpg" alt="2-1-1.jpg" border="0" width="400" height="296" /><br /><br />
<img src="http://img.seiji.me/blog/2008/11/2-2.jpg" alt="2-2.jpg" border="0" width="400" height="293" />

</p>


<h4>MyUIViewController.hの変更</h4>


<p>MyUIViewをPropertyに追加します。</p>


<pre><code>IBOutlet MyUIView *myUIVIew;
</code></pre>


<h3><img src="http://img.seiji.me/blog/2008/11/picture.png" alt="picture.png" border="0" width="30" height="30" /> UIViewとUIViewControllerの接続 </h3>


<h4>MyUIViewController.hの変更</h4>


<p>LibraryからUIViewを配置し、Identity InspectorでClassNameをMyViewとします。またMyUIViewControllerのOutletとの接続も行います。<br />
<img src="http://img.seiji.me/blog/2008/11/2-3-1.jpg" alt="2-3-1.jpg" border="0" width="400" height="250" />
</p>




<h3><img src="http://img.seiji.me/blog/2008/11/xcode.png" alt="xcode.png" border="0" width="30" height="30" /> UIViewなどの実装 </h3>


<h4>PolygonShape</h4>


<p>資料にあったpointsForPolygonInRect:numberOfSides:を追加します。</p>


<h5>PolygonShape.h</h5>


<pre><code>+ (NSArray *)pointsForPolygonInRect:(CGRect)rect numberOfSides:(int)numberOfSides;
</code></pre>


<h5>PolygonShape.m</h5>


<pre><code>+ (NSArray *)pointsForPolygonInRect:(CGRect)rect numberOfSides:(int)numberOfSides {
    CGPoint center = CGPointMake(rect.size.width / 2.0, rect.size.height / 2.0);
    float radius = 0.9 * center.x;
    NSMutableArray *result = [NSMutableArray array];
    float angle = (2.0 * M_PI) / numberOfSides;
    float exteriorAngle = M_PI - angle;
    float rotationDelta = angle - (0.5 * exteriorAngle);
    for (int currentAngle = 0; currentAngle < numberOfSides; currentAngle++) {
        float newAngle = (angle * currentAngle) - rotationDelta;
        float curX = cos(newAngle) * radius;
        float curY = sin(newAngle) * radius;
        [result addObject:[NSValue valueWithCGPoint:CGPointMake(center.x + curX,
                                                                center.y + curY)]];
    }
    return result;
}
</code></pre>


<h4>MyUIView</h4>


<p>PolygonShape *をPropertyに追加します。retain,copyはしません。</p>


<h5>MyUIView.h</h5>


<pre><code>#import &lt;UIKit/UIKit.h&gt;

@class PolygonShape;
@interface MyUIView : UIView {
    PolygonShape *polygon;
}
@property (nonatomic, assign) PolygonShape *polygon;

@end
</code></pre>


<h5>MyUIView.m</h5>


<pre><code>#import "MyUIView.h"
#import "PolygonShape.h"

@implementation MyUIView
@synthesize polygon;

- (id)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        // Initialization code
    }
    return self;
}

- (void)drawRect:(CGRect)rect {
    // Drawing code
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGRect bounds = [self bounds];

    CGContextBeginPath(context);
    NSArray *pointsArray = [PolygonShape pointsForPolygonInRect:bounds numberOfSides:[polygon numberOfSides]];
    NSEnumerator *pointsEnu = [pointsArray objectEnumerator];
    // firstPoint
    CGPoint firstPoint = [[pointsEnu nextObject] CGPointValue];
    CGContextMoveToPoint (context, firstPoint.x, firstPoint.y);
    // otherPoint
    for (NSValue *points in pointsEnu ) {
        CGPoint thePoint = [points CGPointValue];
        CGContextAddLineToPoint (context, thePoint.x, thePoint.y);
    }
    CGContextClosePath (context);
    CGContextSetRGBFillColor(context, 0xff/255.0, 0xd7/255.0,0x00/255.0, 1);
    CGContextDrawPath (context, kCGPathFillStroke);
}

- (void)dealloc {
    [super dealloc];
}


@end

</code></pre>


<h4>MyUIViewController</h4>


<p>MyUIViewのPolygon*のセット、そしてPolygonの状態が変更された場合の再描画の支持のコードを追加します。</p>


<h5>MyUIViewController.m</h5>


<pre><code>- (void)updateInterface {
    if ( [polygon numberOfSides] == [polygon minimumNumberOfSides]) {
        decreaseButton.enabled = NO;
    } else {
        decreaseButton.enabled = YES;
    }
    if ( [polygon numberOfSides] == [polygon maximumNumberOfSides]) {
        increaseButton.enabled = NO;
    } else {
        increaseButton.enabled = YES;
    }
    nameOfPolygon.text = [NSString stringWithFormat:@"aka a %@", [polygon name]];
    numberOfSidesLabel.text = [NSString stringWithFormat:@"%d", [polygon numberOfSides]];
    numberSlider.value = [polygon numberOfSides];
    [myUIView setNeedsDisplay];
}

- (void)viewDidLoad {
    [polygon setMinimumNumberOfSides:3];
    [polygon setMaximumNumberOfSides:12];
    [polygon setNumberOfSides:numberOfSidesLabel.text.integerValue];
    myUIView.polygon = polygon;
    [self updateInterface];
    NSLog (@"My polygon from viewDidLoad: %@", polygon);
    [super viewDidLoad];
}
</code></pre>




<p>これで図形の描画ができるようになりました。状態が変更された場合もその都度、再描画されます。
<br />
<img src="http://img.seiji.me/blog/2008/11/iphone.jpg" alt="iPhone シミュレータ.jpg" border="0" width="294" height="553" />
<br />
今回作成したソースは<a href="http://public.me.com/seijit/iPhone/CS193P/Lecture3">http://public.me.com/seijit/iPhone/CS193P/Lecture3</a>のHelloPoly3.tar.gzを。状態保存はまた別の機会に行います。</p>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[UIViewControllerとXibファイルの作成-CS193P]]></title>
    <link href="http://blog.seiji.me/blog/2008/11/28/296/" />
    <updated>2008-11-28T00:00:00+09:00</updated>
    <id>http://blog.seiji.me/blog/2008/11/28/296</id>
    <content type="html"><![CDATA[<h3>UIViewControllerとXibファイルの作成</h3>

<p>
引き続きCS193PのLecture5のAssignment3に取り組むことにする。ここまではControllerを作成し、MainWindow.xib中にUIButtonやUILabelを配置した。
</p>


<p>今回はUIViewControllerのSubClassを作成する。またそれに対応するxibファイルを新規に作成し、その中にUIButtonやUILabelを配置し、MainWindowのSubUIViewとする。
    <br />
<img src="http://img.seiji.me/blog/2008/11/cs193p-cocoa-programming-announcements.jpg" alt="CS193P - Cocoa Programming | Announcements.jpg" border="0" width="430" height="89" />
    <br />
    <q>
        <cite><a href="http://www.stanford.edu/class/cs193p/cgi-bin/index.php">iPhone Application Programming</a></cite>
    </q>
</p>


<!--more-->


<p>
今迄、作成したソースは<a href="http://public.me.com/seijit/iPhone/CS193P">http://public.me.com/seijit/iPhone/CS193P</a>から
</p>


<p>前回の&#8221;HelloPoly&#8221;プロジェクトを拡張します。</p>




<h3><img src="http://img.seiji.me/blog/2008/11/xcode.png" alt="xcode.png" border="0" width="30" height="30" /> UIViewControllerのSubClass作成 </h3>




<ul>
    <li>XCodeでUIViewControllerのサブクラスを作成します。名前はMyUIViewControllerとします。<br />
<img src="http://img.seiji.me/blog/2008/11/1-1.jpg" alt="1-1.jpg" border="0" width="400" height="300" /><br />
<img src="http://img.seiji.me/blog/2008/11/1-2-1.jpg" alt="1-2-1.jpg" border="0" width="400" height="297" />
    </li>
    <li>HelloPolyAppDelegate.h, HelloPolyAppDelegate.mを以下のように修正します。<br />
        <span>HelloPolyAppDelegate.h</span>
        <pre><code>#import &lt;UIKit/UIKit.h&gt;
@class MyUIViewController;
@interface HelloPolyAppDelegate : NSObject &lt;UIApplicationDelegate&gt; {
    UIWindow *window;
    MyUIViewController *myUIViewController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet MyUIViewController *myUIViewController;
@end
</code></pre>
        <span>HelloPolyAppDelegate.m</span>
        <pre><code>#import "HelloPolyAppDelegate.h"
#import "MyUIViewController.h"

@implementation HelloPolyAppDelegate
@synthesize window;
@synthesize myUIViewController;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
    [window addSubview:[myUIViewController view]];
    [window makeKeyAndVisible];
}
- (void)dealloc {
    [myUIViewController release];
    [window release];
    [super dealloc];
}
@end
</code></pre>
    </li>
</ul>


<h3><img src="http://img.seiji.me/blog/2008/11/xcode.png" alt="xcode.png" border="0" width="30" height="30" /> xibファイルの作成</h3>


<ul>
    <li>ファイル-新規ファイル-iPhone OS(User Interfaces)-View XIBから作成します。
名前はMyView.xibとします。<br />
    <img src="http://img.seiji.me/blog/2008/11/1-3.jpg" alt="1-3.jpg" border="0" width="400" height="294" /><br />
    <img src="http://img.seiji.me/blog/2008/11/1-4.jpg" alt="1-4.jpg" border="0" width="400" height="295" />
</li>
</ul>




<h3><img src="http://img.seiji.me/blog/2008/11/picture.png" alt="picture.png" border="0" width="30" height="30" /> ViewControllerとxibファイルの接続 </h3>


<h4>MainWindow.xib</h4>


<ul>
    <li>今迄はこの中にUILabelやUIButtonなどを配置しました。XcodeからMainWindow.xibをクリックします。Controllerのインスタンスを削除します。</li>
    <li>Interface BuilderでLibraryからViewControllerをDrag&DropしてDocumentWindowへ、Identity InspectorでClass名をMyUIViewControllerにします。<br/>
    <img src="http://img.seiji.me/blog/2008/11/1.jpg" alt="1.jpg" border="0" width="400" height="253" />
    </li>
    <li>HelloAppDelegateのプロパティmyUIViewControllerを先ほど作成したMyUIViewControllerに接続します。</li>
    <li>MyUIViewControllerのAttributes InspectorのNib Nameに先ほど作成したMyView.xibと入力します。MainWindow.xibを閉じます。</li>
</ul>


<h4>MyView.xib</h4>


<ul>
    <li>File&#8217;s Ownerを選択し、Identity InspectorでClass名をMyUIViewControllerにします。</li>
    <li>Connection InspectorでプロパティのviewをViewに接続します。<br />
    <img src="http://img.seiji.me/blog/2008/11/1-5-1.jpg" alt="1-5-1.jpg" border="0" width="400" height="250" />
    </li>
    <li>試しにUISliderでも配置してSimulatorを起動してみましょう。MainWindow.xibのWindow内にもコンポーネントが配置されているのにも関わらず、MyView.xibの内容が表示されるのがわかります。</li>
</ul>




<h3><img src="http://img.seiji.me/blog/2008/11/xcode.png" alt="xcode.png" border="0" width="30" height="30" />ViewControllerの実装</h3>


<p>MyUIViewControllerの実装を行います。Controllerの役割をこのMyUIViewControllerが行うようにしますので、Outlet, Actionを同様に実装します。また、今回はUISliderで値を設定できるようにもします。</p>


<h4>MyUIViewController.h</h4>


<pre><code>#import &lt;UIKit/UIKit.h&gt;
#import "PolygonShape.h"

@interface MyUIViewController : UIViewController {
    IBOutlet UIButton *decreaseButton;
    IBOutlet UIButton *increaseButton;
    IBOutlet UILabel *nameOfPolygon;
    IBOutlet UILabel *numberOfSidesLabel;
    IBOutlet UISlider *numberSlider;
    IBOutlet PolygonShape *polygon;
}
- (IBAction)decrease;
- (IBAction)increase;
- (IBAction)adjustNumberOfSides:(id)sender;

@end
</code></pre>


<h4>MyUIViewController.m</h4>


<pre><code>
- (void)updateInterface {
    if ( [polygon numberOfSides] == [polygon minimumNumberOfSides]) {
        decreaseButton.enabled = NO;
        NSLog(@"enabled NO");
    } else {
        decreaseButton.enabled = YES;
        NSLog(@"enabled YES");
    }
    if ( [polygon numberOfSides] == [polygon maximumNumberOfSides]) {
        increaseButton.enabled = NO;
    } else {
        increaseButton.enabled = YES;
    }
    nameOfPolygon.text = [NSString stringWithFormat:@"aka a %@", [polygon name]];
    numberOfSidesLabel.text = [NSString stringWithFormat:@"%d", [polygon numberOfSides]];
    numberSlider.value = [polygon numberOfSides];
}

- (IBAction)decrease { // Controller.mと同じ }
- (IBAction)increase { // Controller.mと同じ }

- (IBAction)adjustNumberOfSides:(id)sender
{
    UISlider *slider = (UISlider *)sender;
    float value = slider.value;
    [polygon setNumberOfSides:value];
    [self updateInterface];
}
- (void)viewDidLoad {
    [polygon setMinimumNumberOfSides:3];
    [polygon setMaximumNumberOfSides:12];
    [polygon setNumberOfSides:numberOfSidesLabel.text.integerValue];
    [self updateInterface];
    NSLog (@"My polygon from viewDidLoad: %@", polygon);
    [super viewDidLoad];
}
</code></pre>


<p>注意点は前回NSObject::awakeFromNibで実装した箇所を今回はUIViewController::viewDidLoadで実装しているところです。</p>


<h3><img src="http://img.seiji.me/blog/2008/11/picture.png" alt="picture.png" border="0" width="30" height="30" /> UIの変更とOutlet,Actionとの接続</h3>


<p>下の図のように変更します。それに伴いoutlet, actionとの接続を行います<br />
<img src="http://img.seiji.me/blog/2008/11/2-1.jpg" alt="2-1.jpg" border="0" width="400" height="250" />
</p>


<p>長くなったのでとりあえずここまでにします。図形の描画部分は次にしたいと思います。今回作成したソースは<a href="http://public.me.com/seijit/iPhone/CS193P/Lecture3">http://public.me.com/seijit/iPhone/CS193P/Lecture3</a>のHelloPoly2.tar.gzを。間違っているところもあるかと思いますが、そこはご了承下さい。</p>

]]></content>
  </entry>
  
</feed>

