iOS 8 Swift Programming Cookbook

Hi lovely readers 🙂

My iOS 8 book is out and it is ALLLLL new, rewritten to use Swift with tons of new stuff in it.

Check it out, it is 50% off. Click here to go to O’Reilly’s website to purchase the book.

Also a surprise, I have also done a video course to teach you all about iOS 8 programming with Swift. THAT too is 50% off for a limited time. You can click here to get the videos.

Happy coding everyone

Getting the most out of your WiFi dongle data plan (The definitive guide)

I am currently facing a situation where I need to carry out my work while I am connected to a WiFi dongle. I have spent about £20 for 6GB of data that can be used for up to 3 months, whichever comes first. So I have now learnt a lot of tricks on how to minimize my data usage and save money. Here, I want to share with you some of these tricks.

Trick 1 – Disabled images in your browser

If you view the web without images, your browser does not have to load those images from the internet so you will save A LOT of data. Every browser is different so I cannot tell you how to do that on every browser. Here is how to disable the loading of images on Safari on OS X:

  1. Go to Safari Preferences
  2. Go to the Advance tab
  3. At the bottom of the Advance tab, find the “Show Develop menu in menu bar”
  4. Then close the preferences window
  5. Go to the newly-shown Develop menu and choose Disable Images

That’s it. Some websites will not look nice without images and that just shows you how some web developers have now become too reliant on using images! Their fault really.

Trick 2 – Use Git commands carefully

I use Git through the terminal and two of the most useful commands that I use quite often are git fetch and git rebase. Now, git fetch, will fetch every new branch and all change-sets from the server and brings it into your local machine. What you want to do is to replace git fetch with the following command:

git fetch origin NAME OF BRANCH

So if you are on a branch named “ios7” and you want to just bring the remote changes on that branch to your local repo, do this:

git fetch origin ios7

git rebase origin/ios7

Now you got only the changes in that branch and you rebased to the latest changes

Trick 3 – Use Adblock… A LOT

Install Adblock on your browser and go to your popular websites and start blocking anything that looks useless and will consume your data. So just start blocking all content that is irrelevant.

Trick 4 – Disable Flash

I don’t have to explain this. Flash videos are memory, CPU and data hungry. They consume your battery so fast it is unbelievable. Just disable Flash to make sure your browser will not try to load those darn Flash videos for you.

Trick 5 – Stop watching videos on websites

Do not go to YouTube and other streaming video websites. They are very data hungry no matter how low you have set the quality of the videos. Watch videos when you are on a proper broadband, not on a tiny WiFi dongle.

Trick 6 – Subscribe to websites with push notifications

I read MacRumors quite a lot. I go to their website probably 3-4 times a day. But instead of doing that, it’s best that you subscribe to push notifications from news websites that offer that service. Then you can get push messages directly to your OS X desktop of new content that get posted on those websites instead of going there every time you want to check the news. A push notification will only contain the new article, not the whole website. But if you go and browse the website, you are viewing everything that is on the front page at least, hopefully without the images, as one of the tricks you learnt earlier!

Trick 7 – Stop opening a browser page ever time you think you’ve lost your internet connection

We all do this. When we think we have no internet connection, which can happen on a daily commute on a Wifi dongle, we open our browsers and navigate to our favorite website. If the website loads, we go “Aha, it works”. Instead of that, do this:

  1. Open Terminal
  2. Type this: ping http://www.apple.com

Once you see ICMP packets going and coming back, you know at least ICMP is working and you are almost 99.99% sure that your internet works.

Trick 8 – Do not preload top hits in your browser

Users of Safari or most modern browsers know that when they type in the search field for anything, a few “suggested” websites and terms will appear automatically. For instance, if you start typing “blood”, in your search field in your browser, you may get suggested words such as “blood pressure”, “check your blood sugar level”, and etc. Every time you type something in your browser’s search field, your browser will hit your search engine and look for suggested words and links. This will take battery and will use your internet. To disable this in Safari, follow these steps:

  1. Open Safari Preferences
  2. Go to the Privacy tab
  3. In the “Smart search field” area, click the “Prevent search engine from providing suggestions”
  4. In the same area, click the “Do not preload Top Hit in the background”

Okay that is it for now. These are all the tricks I have up my sleeves for saving you some data usage on your WiFi dongle. If you have any other tips that you believe are worth sharing with others, please let me know and I will include them here.

Enjoy

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.

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.