iOS 7 Programming Cookbook’s Source Code

As you know, my recent book is now published, titled “iOS 7 Programming Cookbook”. You can purchase it here:

http://shop.oreilly.com/product/0636920031031.do

All the source codes written for this book are now available on Github at the following location:

https://github.com/vandadnp/ios-7-programming-cookbook-source-codes

If you have any questions, please let me know.

Advertisements

The REAL location of the CIFilter in OS X Mountain Lion (Development)

So you are trying to use CIFilter for the first time and the documentation tells you that this class sits in the following location?

Library/Frameworks/CoreImage.framework

Image

The documentation is LYING its ass off to you. The real location of this class is in the QuartzCore framework. Import QuartzCore.framework and you are sorted.

Image

Find cpp, c++, clang++ and clang in Xcode 4.3.x and Higher

 

So you have some scripts that use “cpp”, “c++” or “clang” and etc but you cannot find them in your path? Not to worry, read on…

With OS X Lion and sandboxing, you can find your c++ compiler using the “find” command:

find /Applications/Xcode.app/ -name “c++”

This will return something like:

find /Applications/Xcode.app/ -name “c++”
/Applications/Xcode.app//Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
/Applications/Xcode.app//Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/c++

The one in the “bin” folder is the one we are looking for so the folder that contains our toolchain is here:

/Applications/Xcode.app//Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/


Navigate to that folder to do some inspection:

cd /Applications/Xcode.app//Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/
ls -la c++
lrwxr-xr-x 1 root wheel 7 19 Jun 22:41 c++ -> clang++
ls -la clang++
lrwxr-xr-x 1 root wheel 5 19 Jun 22:41 clang++ -> clang
ls -la clang
-rwxr-xr-x 1 root wheel 22985632 19 Jun 22:41 clang

You can see right away that c++ is a symlink to clang++ and clang++ is a symlink to clang. What a mess!

Now let’s find “cpp”:

ls -la cpp
ls: cpp: No such file or directory

Oopsy daisy, it’s not there. That’s one of the issue a lot of developers will be facing. So let’s remedy this by first creating cpp as an alias. We want this alias to be permanent between Terminal sessions so we put it in our bash_profile and we also have to make sure the toolchain bin url highlighted above is in our path:

vim ~/.bash_profile

And then change the content of your bash profile so that your path includes:

/Applications/Xcode.app//Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/

and also create an alias for cpp to point to clang. The contents of my ~/.bash_profile now looks like this:

export PATH=~/bin/:/Applications/Xcode.app//Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/:$PATH
alias cpp=’clang’

Once you are done, press Escape in vim and then type :wq and press enter. That will “write” and then “quit”.

After you are done, close Terminal and open it again and type cpp:

cpp
clang: error: no input files

Lovely, it’s working. Any questions? Leave them down below 🙂

Installing Git on Mac OS X

If you want to install Git on your OS X Lion, whether you have Xcode or not, you can head to:

http://git-scm.com/download

There choose your platform and the install process will start automatically. This will download a .dmg package to your machine. Simply follow the installation process. After installation, you should be able to find Git in the following folder:

/usr/bin/git

And since this folder is already added to your path, you can simply access it in Terminal by typing git

Git from command-line after installing Xcode on OS X Lion

Xcode 4.3.x or newer comes with Git but the problem is when you install Xcode on your machine (OS X Lion or newer), Git’s path won’t be added to the user path which means if you run git from your command-line, your system will say:

-bash: git: command not found

Xcode’s installation of Git is at the following location on your machine:

/Applications/Xcode.app/Contents/Developer/usr/libexec/git-core/

With the git binary sitting here:

/Applications/Xcode.app/Contents/Developer/usr/libexec/git-core/git

To add this binary to your path (which will allow you to run “git” from any directory on your system), go to terminal and type this command:

export PATH=”/Applications/Xcode.app/Contents/Developer/usr/libexec/git-core/”:$PATH

There is one caveat to this approach and that is the PATH will only be changed in your current running instance of terminal. As soon as you close terminal and open it again, you will have to enter the above command again to get access to the git app. So what is the proper solution? You will have to add the above “export” command to the .profile file in your home directory. The .profile file gets read every time you open terminal. So open a terminal instance and type the following command:

cd ~/

And then type this command:

ls -la | grep “.profile”

We are trying to find out if we already have a file named .profile in our home directory. If after running the above command you won’t see anything getting printed to the terminal, use the following command to create a new .profile file. If you already have a .profile file, skip this command:

touch .profile

Now open the .profile with this command:

open .profile

Now add the git path to the PATH variable in the .profile file so that your .profile content will look something like this (it really depends on what you already have in this file. I am assuming your .profile file didn’t exist until now and you just created it):

export PATH=”/Applications/Xcode.app/Contents/Developer/usr/libexec/git-core/”:$PATH

Save your changes to the .profile file and close terminal and open it again. Now whichever directory you are in, in terminal, you can use the git command. Good luck.

Easter Egg in GarageBand for iPad (Curtain-Call demo song)

So after reading how cool GarageBand was (which it truly is) for iPad, I purchased it the other day. I got a few crashes after using it for a long time. I think some memory warnings, because I am running it on the original iPad rather than iPad 2.

When you open the app, you can start composing music. But what got my attention was that there is a little “secret” demo song that gets shipped with GarageBand for iPad and it’s called Curtain-Call. Why is it secret? Because it won’t appear on your iPad’s GarageBand unless it has crashed at least once!

That sounds weird, doesn’t it. But if you can, get GarageBand to crash once on your iPad. Then open it again and in your library of songs, you should see a new song called Curtain Call, it’s amazing. It looks like Apple has put this as an easter egg in GarageBand (that’s so unlike Apple though). Check out the screen shots that I’ve taken of my GarageBand on iPad. Do you have this song in your GarageBand library on the iPad?

I have also attached the song to the end of this post, if you want to just listen to it. It really sounds cool knowing that it has been composed entirely on an iPad with GarageBand!

Curtain Call, GarageBand Demo Song (Easter Egg)

 

 

Curtain Call 8 Track

Curtain Call iPad Demo Song for Garage Band