The notion of NSInteger and NSNumber may seem confusing at first glance, but in reality it is simple.
NSNumber is a subclass of NSValue – container for C or Objective-C data item. The purpose of NSValue class, and, hence, NSNumber class – to allow items of different data types (ints, floats, chars, pointers, structures, as well as object ids) to be added to collections, such as instances of NSArray, for example. As simple is that!
With that purpose in mind, it’s easy to memorize NSNumber features:
1. it stores and retrieve primitives, but it’s NOT primitive;
2. it can be displayed using %@ format specifier;
3. it is incredible useful when we need to stick a number into NSArray of NSDictionary.
NSInteger also has some features:
1. it is very much like traditional int in C, only it save us from dealing with int/long on 32/64 bit processor architecture;
2. it is a primitive.
We can convert them between each other:
NSInteger myInt = [numberValue integerValue]; //NSNumber to NSInteger//NSInteger to NSNumber
NSNumber myNum = [NSNumber numberWithInteger: integerValue];
NSNumber myNum = @(integer);
For every user who wants to make the next step and try to write some code, setting up the environment is the first hardship to overcome. Considering virtually non-existing level of experience, the task turns into a tedious exercise, when we have to follow tons of tutorials copy-pasting the solutions and lines of code having no real understanding of the meaning behind it. So I put together my setup process (some parts took me a while to figure out):
1. Get Xcode, of course! Xcode is an integrated development environment (IDE), that is an application which helps you to write code. The easiest way is to get it from the App Store.
We click on Spotlight icon on the top right of the screen and type “App Store”, we get the result. Click on it opens App Store.
Go to search bar (upper right), type Xcode. Find Xcode icon, install by pressing Free button.
2. As a programmer to-be, we know we will have to use Terminal – the application, which provides text-based access to the operating system. Click on Spotlight, type “Terminal”. Terminal window opens. It looks rather trivial – black letters on white screen.
I prefer Solarized theme. Download it. Click open to unzip (unarchive) the folder. Than go back to Terminal -> Preferences and click on a cog image in lower left corner under the list of themes.
Click import and navigate to the directory, where solarized folder is stored (most likely that will be Downloads), find osx-terminal.app-colors-solarized folder, inside which you choose Solarized Dark ansi.terminal, click open and see it in the list of your themes.
In this list choose the theme and click on it. If we want to keep this theme default, so it will open every time we open Terminal, we also click Default in lower left corner.
3. We want to make our terminal to highlight with different colors our user name, hostname and current working directory? For that we’ll have to do some programming! When we enter something into command line it is processed by command line interpreter (in our case it’s GNU Bash). In can be a singe word, for example, ps, or complicated set of commands and conditionals. If we combine a set of such instructions in one file, we create a script, which computer can understand.
(Press enter after each step)
- Go to our user directory:
cat >> .bash_profile
- Paste this line
export PS1="\[33[36m\]\u\[33[m\]@\[33[32m\]\h:\[33[33;1m\]\w\[33[m\]\$ "- Press
You appended a line to file named .bash_profile (or created it if the file did not exist). A line contains a variable PS1, which describes how the bash will ask us to type a command, i.e. prompt line. We change color by changing its ANSI color code – and computer gives us a prompt line with neat colors. By saying export we ask computer to use this variable for all processes, so it stays unchanged after we closed Terminal and opened it again.
4. When we want to open a file from command line, we will open it in the default text editor, which we may not be happy with. Let’s change this.
I personally like Sublime Text. Download, drag it to application folder and open to make sure everything works.
(Press enter after each step)
– Go to our user directory: cd ~
– Type: ls and search for /bin directory
– If there is none, type: mkdir bin
– Paste as single line:
sudoln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl
This command will prompt you for your password, if you don`t have one, you will have to create it. By doing this we create a symbolic link – a reference to the actual directory.
– Type: subl –help to check if all works
How we have Xcode for creating applications, neatly looking Terminal for dealing with developers day-to-day tasks and we can access a good text editor Sublime Text by simple typing in command line subl <file_name><name_of_file>