Sunday, December 25, 2011

NSNotification

It seems every NSNotification has a method named "object" returns the real UI element fires this notification. For example, in table view, when user click one item in the table view, a "NSTableViewSelectionDidChangeNotification" is fired, and the delegate will receive it. Then the delegate can use [aNotification object] to get the real table view. So it won't need to save a outlet of the table view.

Monday, December 5, 2011

How to import Xcode project into bitbucket

BitBucket supports private repository for free users, so it is very suitable for hosting our Xcode projects :)

When you signup your free account, and create a new project for yourself, the problem is coming, how to import your xcode project into the bitbucket?

1. Create your SSH key

First, you need to update your SSH key(s) into bitbucket, as we're OS X users, so it is very :)

1.1 Check your SSH key

In console, type:

$ls ~/.ssh<enter>

If there are id_rsa and id_rsa.pub exist, you've already got your SSH keys, so skip the next step.

1.2 Create your SSH key

In console, type:

$ssh_keygen<enter>

The program will ask you for a passphrase, you can just take it as a "password". And when the program finishes, there will be two files in your ~/.ssh

  • id_rsa - which is your private key, you need to protect this file, don't be touched by others.
  • id_ras.pub - which is the pub key, you can upload / send this file to others, such as bitbucket.

So we have our SSH key, then we upload it to bitbucket

2. Update your SSH key to bitbucket

Go to Bitbucket settings, click the "choose key", and browser to your id_rsa.pub (you may need to copy it to some directory that the finder can locate it, for example, in console, use: cp ~/.ssh/id_rsa.pub ~/ ), then click the same button, it should be "update key", after that, you public is uploaded successfully.

3. Upload your repository

I refer to this link, you need to:

  1. Create a repository in bitbucket
  2. Note the URL you should use is: git@bitbucket.org:youruser/yourepo.git
  3. in console, go to your locale repository: $cd /path/to/my/repo
  4. git push --mirror git@bitbucket.org:youruser/progbuenos.git

Then the local code will be uploaded to bitbucket, you can use git clone to fetch it back

Tuesday, November 22, 2011

How to update xcode via app store?

I just update xcode from 4.2 to 4.2.1 via App Store. However, after downloaded the latest version of xcode, there is nothing happens!
I searched the internet, and finally found that I must run /Applications/install xcode.app.... it means App Store only download the install package, and place it into /Applications, but doesn't run it for you.

You can click "install xcode" from launchpad, and follow the instructions.

Wednesday, November 16, 2011

For windows users, we all know that we can edit c:\windows\system32\drivers\etc\hosts to specify an IP address to a host name. But where is the "hosts" in Mac?

I searched the internet, and find out that this file is on: /private/etc/ so the file is:

/private/etc/hosts

And the format is the same as other systems.

Saturday, October 29, 2011

Error in .vimrc

So I copy my .vimrc from my PC to Mac. I put it into ~/. But when start MacVim, there is error message like this:

E488: Trailing characters: nocompatible^M

So the vimrc can't be loaded into MacVim. I googled but their solution doesn't work for me. There is a very simple solution is....


1. In terminal:

$mv ~/.vimrc vimrc
$mvim ~/.gvimrc

2. Then in vim:
:tabe ~/vimrc
:gg
:ctrl+v
:G
:y
:tabp
:p


That means, copy the whole content from "vimrc" to ".gvimrc" in MacVim. So the ".gvimrc" will work well.

Friday, October 28, 2011

Vim for Mac

I use vim for many years (on windows), so I also want to use vim on Mac. Because Mac OS is a type of UNIX, so there is a text based vim built-in it. But I want a GUI vim. It seems that MacVim is the best choise for vimer on OSX. You can download it from: https://github.com/b4winckler/macvim, or http://code.google.com/p/macvim/.

After download / install MacVim, there are two method to open it in console:
  • $open -a MacVim
  • $mvim
Let me explain:


1. open -a MacVim
Because MacVim is installed on /Application, so the system allow us to open the app by the name, the path is not needed. It is very handy, but it seems that if you want to edit a file with administrator privilege, "sudo open -a MacVim" can't work. So we need the second method.

2. mvim
mvim is included in the install package of MacVim, you can copy it to a dir, for example, I have a directory: ~/scripts, and I copy mvim into ~/scripts. Then I need to add ~/scripts into the PATH.
Because OSX read the follow configurations when terminal opens (via this):
  • /etc/profile
  • ~/.bash_profile
  • ~/.bash_login
  • ~/.profile
So we can edit ~/.profile and add this line:

export PATH=~/scripts:$PATH

into it. So ~/scripts is added into PATH whenever you open a terminal.
Then in terminal, you can just type:
$mvim <path to file>
or
$sudo mvim <path to system file>
to edit.

Why this blog

I just bought a Mac Mini and began to study the iOS dev. But I'm not familiar with Mac OS, so I write blog here, to recod every progress I get. And I hope this can be helpful to others :)