Your Ad Here

Learn to use Xcode 4 snippets

January 17th, 2012

Code Snippets

One of my favorite features of the new Xcode 4 is code snippets. Code snippets let you use (and re-use) common classes and objects by simply typing a shortcut. For example if you type dealloc, Xcode 4 automatically generates the deallocation method for you:

- (void)dealloc {

<#deallocations#>

[super dealloc];

}

To add your code snippets to Xcode:

  1. Find the code you want and highlight it.
  2. Drag the selected code to the the Snippet Library
  3. Name your snippet (this is just the name you see in the Snippet Library)
  4. Choose a shortcut for your snippet which is used to invoke it (a good practice is to use shortcuts that show what the snippet does, like dealloc is used for invoking the deallocation method).
  5. Choose language and platform (so Xcode knows when to offer this snippet).
  6. If you like a bubble to appear as part of your snippets (like the #deallocations# in the example), just type <#text in the bubble#> in your snippet.
Tags: , ,

Mobile Safari

Since iOS 3.1, Mobile Safari features an anti-phishing filter. In order to be protected from phishing sites as much as possible, the filter’s database must be up-to-date. According to Apple, the database upgrades automatically while the user charges the iPhone (in order to protect battery life). To upgrade you have to: connect the iPhone to the AC adapter, launch Mobile Safari and lock the screen. Easy enough except that most users exit Safari before locking the screen in a regular use.

Tags: , ,

Thank you Steve!

October 6th, 2011

Steve Jobs passed away at the age of 56! Tech world will never be the same without him! Rest in Peace Steve! Thank you for everything and may your spirit lead Apple to more innovations!

Tags: , ,

If you try to load your WordPress blog and you come across this warning (or anything similar), the fix is really easy. The error message should look like this:

Warning: Cannot modify header information – headers already sent by (output started at //home/htdocs/wordpress/wp-config.php:1) in /home/htdocs/wordpress/wp-login.php on line 12

Notice that the error could warn about any file, not only the wp-config and the wp-login. The solution is to edit any file that is noticed in the error message (download via ftp and edit it locally, then upload it to your wordpress directory and replace the old one, or edit it directly in your server) and remove all spaces before the <?php and after the ?>. 

Tags: ,

After upgrading to OS X Lion, I released that the Library folder in my user’s home folder (where all the .plist files from the installed apps are stored) was gone. I wish Lion would have respected my folders and installed apps from my Snow Leopard installation during setup (it also removes iSync. Not big deal unless you use some kind of old-school Nokia cell phone). As there is no option to show hidden folders in OS X (or I haven’t found it), the only way to bring back the Library folder is via terminal. Open the Terminal.app (found under Utilities folder or search it with Spotlight) and paste the following command. Yes, you are done!

chflags nohidden ~/Library/

Tags: , , ,

lion

The first thing that tracked my attention after upgrading to OS X 10.7 Lion is that my full name (logged in user) was displayed on the top menu bar! Except that I do not want my surname showing up there, I am the only user on my mac. It is very easy to remove this option. You just have to click on the username in the menu bar while holding the Command (⌘) key and drag it off of the bar.

You can reenable it again by going into System Preferences > Users & Groups > Login Options and checking the “Show fast user switching menu as” option. If the options are greyed out (and you are not able to modify them), just click the Lock icon at the bottom left corner, typer your password and you are ready to go.

Tags: , , , ,

Mac OS X (despite its user-friendly UI and the general ease of use) is built on Darwin kernel which means thats it is a UNIX system. Using the terminal (it is located in application>utilities folder) you can easily get some valuable info about your mac. If you run Mac OS X 10.6 Snow Leopard, you have the ability to boot with the 64-bit kernel instead of the 32-bit that loads by default (Apple has chosen the 32-bit as the default boot kernel to prevent glitches caused by 32-bit kernel extensions). To boot with the 64-bit kernel you need a Mac with an Intel Core 2 duo or newer processor (Intel Core Duo does not support 64-bit) and 64-bit capable EFI. To check if your EFI supports 64-bit, open the terminal and type the following command:

ioreg -l -p IODeviceTree | grep firmware-abi

If the terminal returns “EFI64″ as shown in the image below you are ready to go. Just restart your mac holding “6″ and “4″ numeric keys and it will boot with the 64-bit kernel. Note though that in a typical system (for example a core 2 duo mac with 2 to 4 GB of RAM), there will be no significant performance improvement. Also even with the 32-bit kernel, you can run 64-bit applications and take full advantage of 64-bits (that is not a Snow Leopard feature. Leopard was able to run 64-bit apps and adress more than 4GB of RAM too).

Some other important info you can easily get about your portable mac from the terminal, is your battery condition. Type the following in the command line and you the terminal will return your battery’s max capacity, current capacity and design capacity.

ioreg -l | grep Capacity

If you see that max capacity is lower than design capacity do not panic, batteries start to loose capacity after some charging cycles.

Tags: , , , , , , ,

Sometime ago I wrote a post about finding your original photo files from photos stored in your iPhoto library using Finder. Here is a quick way to locate a photo file within iPhoto (iPhoto ’11 as the menu options changed a little bit since the previous version).

Tags: , , , ,

Sometimes after upgrading your Xcode and iPhone SDK installation you may see the alert “Base SDK missing” when you try to compile and build an old project (that was written with a previous version of Xcode and an older version of iPhone SDK). That issue is as easy to fix as performing some clicks. Let’s see how:

  1. Open old project. On the upper side of the Xcode window you should see the message of the missing SDK as shown in the image below.
  2. Click the info button (blue icon with the “i”).
  3. Navigate to the “General” tab.
  4. Under the “Base SDK for all configurations” choose the latest version of iOS (now its 4.1. Choose iOS Simulator if you want to run the program on your Mac, or iOS Device if you have a developer device and you want to build the project and run it straight to the device).
  5. Click “build and run” and your project should now compile as usual.
Tags: , , , , , ,

As you may have mentioned, lot of iPhone apps (especially games) run by default in landscape mode! You can easily force the app you develop to run in landscape mode! Let’s see how:

  1. In Xcode find the file [YourAppName]-Info.plist and open it up.
  2. Right click on the table and select “Add Row”. Select “Initial interface orientation” and set the value to Landscape (left or right).
  3. Right click again and add Status bar is initially hidden.This is optional, it has nothing to do with view orientation, but it will hide the status bar.
  4. Open [YourAppName]ViewController.m file and uncomment the following:
    // Override to allow orientations other than the default portrait orientation.
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
        // Return YES for supported orientations
        return (interfaceOrientation == UIInterfaceOrientationPortrait);
    
  5. Change the code you just uncommented to look like this:
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
        // Return YES for supported orientations
        return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
    }

    Parameter interfaceOrientation == UIInterfaceOrientationLandscapeRight starts the app with the Home button at the right side. interfaceOrientation == UIInterfaceOrientationLandscapeLeft starts the app with the Home button at the left side. Set the same landscape orientation that you’ve set in Info.plist file.

Tags: , , , , ,

TopTOP

Your Ad Here