Tuesday, August 30, 2011

なぜMobile SafariのJavascript エンジンが速くて、UIWebViewのJavaScriptエンジンは速くないの?

iOS 4.3のアップデートの中に、Mobile SafariにNitroというJavaScript エンジンが搭載されて、パフォーマンスが著しく改善されました。しかし、UIWebViewを使うとき、その効果を感じていない開発者が多くいると思います。

結果的に、John Gruberさん(Daring Fireball, @gruber)さんが非常に素晴らしい分析をしてくれいました。翻訳するのが大変ので、要点を抽出して、ここにリストします。英語が大丈夫な方は元の文書を読んでもらえれば一番良いと思います。

  • Mobile Safari for iOS 4.3+がJavaScriptのJIT技術を搭載している[JIT@en.Wikipedia] [JIT@ja.Wikipedia]
  • JITがメモリ上のMemory pagesを実行可能にすることが必要
  • iOSでSandboxがMemory pagesを実行可能にすることが禁じている
  • Mobile Safari for iOS 4.3+ がシステムの特別処理を受けていて, Memory pagesが実行可能になっている
  • その特別処理は超大変(3年ぐらい掛かった)


それこそ、JITの技術を勉強しましょうか。Mobile Safariがもっとモバイルブラウザの市場シェアがさらに上がっていますよね〜。

Ordered the Official Biography of Steve Jobs


It's a big thing, as an iOS/Mac Developer, this biography looks like a bible for us. 15 Years ago, I was inspired by Bill Gates. Today, I'm motivated by Steve Jobs.

Here is the book.

By the way, the Japanese version will also be available on Nov 21, 2011.

You can order the book on Amazon.co.jp. It will be 2 parts, スティーブ・ジョブズ(上) and スティーブ・ジョブズ(下)

日本語版は講談社が発売します。定価は現時点(2011年8月30日)にまだ未定です。予約は可能です。皆さんも買いましょう〜〜


Monday, August 29, 2011

Count source code lines roughly by command line

I started to understand the command line a little bit more.

Today, I met a problem, I need to count the lines of my project. My first reaction is to use the `find` and `wc` command. OK, first I got this:

find . -type f \( -name "*.h" -or -name "*.m" \) -exec wc -l {} \;

OK, it works, but, all the line numbers are for each file, there is no summary information such as total number of lines which is the most important data I wanted. After googling, I got a hit on Stackoverflow.com, here is the correct solution. Also using the same command, but with a different order. This time, this command generated what I wanted.



[Update 1@Aug 30, 2011]
The above method is still not good enough. A good example is that when the file name or folder name contains space, the above command could not work properly with this kind of file name/folder name. How to resolve it?

Here is another way:



To understand this, you need to know some basic ideas behind Unix command line. Please see detail of awk@wikipedia, pipeline@wikipedia. About using `-or` in find command, please refer to the man page.

Command line is powerful, use it often and wisely. It will save you a lot of time.

Friday, August 26, 2011

How to use "git tag -s "

It's cost me over 2 hours to figure out how to use the "git tag -s <tag name>" command.

The first step is you need to have `gpg` installed.

The most part of these 2 hours were fighting with "MacPorts" and "HomeBrew" to install `gpg`. Why? because MacPort does not allow me to upgrade `libiconv` when I tried to install `gnupg`, and as a result, I uninstalled `MacPort` which had been served me for over 2 years. I chose `HomeBrew` as my new partner, when I downloaded it and installed `gnupg`, it still told me again for build error. WTF? What's the problem? When I was at a loss what to do, suddenly I saw that brew provided a funny function as 'brew doctor', I ran it, it told me to remove "GREP_COLOR='--color=always'" in my `.bashrc` file and told me that's the reason for CMake failed to work! Oh My god, that's the problem! The rest was easy to go.

`brew install gpgme` // to install gpg, you'd better to install gpgme

`gpg --gen-key` // follow the interactive command line to create your private key. 
Remember that, the email you entered must be the same as you set with your git account.

`git config --global user.signingkey <8bytes HEX value from gpg's public key>`
Note that there is no '=' after signingkey

One last step to go
`git tag -s "v1.0" -m "RTM v1.0"`

If you are using github(I highly recommend it, actually, I'm recommending git) service, another command to go,

`git push --tags`
Push the tags to server.

How to make the command's output language to English

Today, I installed gnupg which is a open source tool by FSF. Installing gnupg was simply in order to use `git tag -s "tag name"` to sign the tag. I used 'HomeBrew' to install it on my Mac. The installation was satisfactory, only after the installation, when I type 'gpg' on the command line, it showed me Japanese translation. WTF!?

I guess it could be some kind of settings read from system, but there should also be a way to modify this. After a few minutes of googling, I found out that we need to set an environment variable to make it show English at any circumstances. Here is how:

Add the following line to your ".bashrc" if you are using bash, or other shell's configuration file.

`export LC_MESSAGES="en.utf-8"`

Actually, you can also use 

`export LC_MESSAGES=C`

The difference is `C` is only showing the ASCII, but en.utf-8 will support unicode.

See more on Bash's environment variable list:


type `env` on the command line to see all environment variables set to the system. 

Good luck to anybody else who has the some trouble as me!


Tuesday, August 9, 2011

Everything About NSIndexPath/NSIndexPathの全て

NSIndexPath[Class Reference] is a special class from Foundation, UIKit added some special functions/methods for using it with UITableView[See NSIndexPath UIKit Additions]. Usually, we use it like indexPath.row, or indexPath.section, but there is very special feature for this class, if you remember it, you can make your code much more neet and easy to understand.

NSIndexPath objects are uniqued and shared

Yes, that's it. All the NSIndexPath objects that have the same value are UNIQUED and SHARED. What do these 2 words mean to an NSIndexPath object? That means if you have an index path refer to a special cell, let's say row 2 and section 1, you can create an index path by yourself, and it should be equal to the one generated by system.

In another word, you can use  if (myIndexPath == systemIndexPath) to compare 2 index path instead of if (myIndexPath.row == systemIndexPath.row && myIndexPath.section == systemIndexPath.section). Isn't that much easy to understand?



NSIndexPath[Class Reference] はFoundationの中にある特別なクラスだ、UIKit はそれの上にUITableView[See NSIndexPath UIKit Additions]で使いやすくなるような便利なメソッドを追加した。普通は、indexPath.rowindexPath.sectionのように使っている。ただし、このクラスの特徴を思えておくと、非常に綺麗なコードを書ける。

NSIndexPath のオブジェクトは唯一であり共有している

そう、これだけだ。全ての同じ値を持っているNSIndexPathのオブジェクトは唯一であり、共有されいる。どういう意味?つまり、あなたが作ったIndex Pathオブジェクトとシステムが作られたIndex Pathが同じPath(例えば、sectionの1とrowの2)を指している場合、同じオブジェクトのはずだ。

言い換えると、この書き方を使えば、IndexPathの値比較は可能だ: if (myIndexPath == systemIndexPath) 、逆に、この書き方が要らないよ: if (myIndexPath.row == systemIndexPath.row && myIndexPath.section == systemIndexPath.section). これは便利だろう!

----
追加: NSIndexPathの文書に書いてある説明用の図


Figure 1  Index path 1.4.3.2
Index path “1.4.3.2”

Sunday, August 7, 2011

iOSの開発ネタを公開する

ここまで、iOSデバイス上の開発経験は結構積んでいて、そのまま個人で保有するのが意味がないなと思って、ここで共有します。

基本的に開発の初心者向け(自分もある意味で初心者です) 、iOSを開発する際に、注意すべきことを書きます。メインの読者は日本人と想定していて、主に日本語で書きます。たまに英語を書いておきます。

そもそもはGoogleの広告をいれておきましたが、とりあえず外します。毎日1万のPVを達成できるまではいれません。

iOSの開発記事以外は英語勉強の事なども書きます。今年のTOEICは見事に900以上と言う目標を達成できまして、自分なりの勉強方法も一部紹介します。

では、楽しみにしておきましょう!よし、出発!


iOS の開発
その他のチップ