Swift: Convert Unmanaged to String

Edit 1 (20th October 2014): Apple has now fixed this issue. To convert an unmanaged object to managed, just use the takeUnretainedValue() or the takeRetainedValue() method on it, based on whether you want to take a retained or unretained value.

So let’s say you have an Unmanaged<AnyObject> value that you know internally contains a value of type CFStringRef and you want to convert this to a value of type String in Swift. This is how I have managed to do that:

func convertCfTypeToString(cfValue: Unmanaged!) -> String?{

/* Coded by Vandad Nahavandipoor */

let value = Unmanaged.fromOpaque(
cfValue.toOpaque()).takeUnretainedValue() as CFStringRef
if CFGetTypeID(value) == CFStringGetTypeID(){
return value as String
} else {
return nil
}
}

Shown in Xcode it looks like this:

Screen Shot 2014-07-07 at 14.43.52

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

15″ Retina MacBook Pro 2012 – Some Photos

So I finally got my 15″ Retina MacBook Pro (Mid 2012). The specs are:

  • 2.7GHz Quad-core Intel Core i7
  • 16GB 1600MHz DDR3L SDRAM
  • 512GB Flash Storage
The first thing you will notice in the photos is the glare on the screen that has been significantly reduced. In the background, you can see my 27″ Thunderbolt screen, with the same light source (my desk lamp on both the TB and the Retina displays) and the Retina display has much less glare than the Thunderbolt display.

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.

Xcode 4 Refactoring Features – Part 1

In this video, you will learn about Rename, Extract, Create Superclass, and Move Up refactoring facilities in Xcode 4, Apple’s latest and greatest development environment for iOS and Mac OS X. If you have any questions, or comments, leave them down here.

Buying the brand new MacBook Pro. Announced on February 24th 2011

So apple announced they have made new MacBook Pros. Having a MBP myself, I was keen to see what the specifications were and how Apple improved this machine which already was a beast. So here is the deal:

First thing you will notice is that all CPUs are upgraded to Intel Core i5 and Core i7. That’s great but what is even better is that they are not just normal Core i5 and i7. They are, on 15 and 17″ MacBook Pros, indeed, Quad Core i5 and i7 CPUs. That’s a huge processing power for a laptop.

The next thing you’ll notice is that the 13″ MacBook Pro is also upgraded to take advantage of Intel Core i5 and i7 but the CPU on 13″ models is dual core rather than a quad core on 15 and 17″ models. It’s a great processor nonetheless!

The other thing that you’ll notice is the graphics adapter on the 15 and the 17″ models which is now switched to use AMD chipsets. The 15″ comes with these variety of graphic chipsets:

AMD Radeon HD 6490M with 256MB GDDR5
AMD Radeon HD 6750M with 1GB GDDR5

The battery life, not much change there but considering the huge upgrade in the CPU, it is pretty impressive the same battery life is provided to customers since you’d be expecting the CPU to consume more power (although that’s not always the relation between increase in processing power and consumption of batter).

All in all, these new MacBook Pros seems amazing. Are you going to order one? Have you ordered one already? B)