Using CGSPrivate

No Comments

CGSPrivate is a super cool header which allows Mac developers to use nice animations on their apps. There are many animations, but the most popular one is the cube. On the Mac OS X, when you switch the user usingthe fast user switching, the desktop rotates and the other user’s desktop appears. You can use that and many other animations on an ordinary NSWindow with a few lines of code.

CGSPrivate uses private APIs, which means it can stop working anytime as Apple may update Mac OS X and remove the support for the animations with no prior notice. Mostly likely it’s not going to happen any time soon, as CGSPrivate has been here for a couple years(the first version of CGSPrivate was wrote back in 2003, I believe). It also can’t be used on apps you pretend to sell on the Mac App Store. Apple doesn’t like apps that use private APIs.

More

[Book]Cocoa Programming for Mac OS X

No Comments

People ask me very often what they should do to get started in programming. I usually tell them to read books. And what’s the best book for those who want to learn Mac programming? It’s Cocoa Programming forMac OS X by Aaron Hillegass. This book is the best, it simple defines what we are, it’s our bible. The book considers you already know a little C or C++ and teaches you everything a decent Mac developer should know: from a hello world to printing, web services and Core Animation.

The guy who wrote this book can be considered the world’s best Cocoa teacher. He taught Objective-C at companies like Intel, NeXT, Apple and Microsoft. He is also the own of Big Nerd Ranch, a very famous training center.

Now let me tell you guys about my faith testimony. I started to try to learn Cocoa in the beginning of 2008, I had gave up and started to look for alternatives to Objective-C. I mean, that syntax looked so weird. A very long time after that, in the end of 2009, Lars Bergstrom told me about this book. In less than a month I was writing my first commercial app.

At the time I’m writing this, it costs $30.24 USD on Amazon. It’s not the world’s cheapest book, but it isn’t the most expensive one. It’s worth investing on a copy. Get it on Amazon.

Share and Enjoy:

Documents folder and UIFileSharing

No Comments

On the iOS, we can only save files on the documents folder. The bundle for example, is not writable. Getting the path of the documents folder is easy. Just use the following code:

NSArray *array = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documents = [[array objectAtIndex:0] copy];

The variable documents will be the path to the documents folder. Now if you want to create an URL from it, use the following code:

NSURL *url = [NSURL URLWithString:documents];

Say you saved a couple files and want your users to be able to transfer it to their computers. On iOS 3.2, Apple introduced UIFileSharing. It allows users to transfer files from their iOS devices to any computer running iTunes. To enable that, just add the Application supports iTunes file sharing line to your info.plist and check the box.

Your users will be able to transfer any file from the documents folder to a computer. To do that, open iTunes then click on your device name. Go to the apps tab and scroll down.

Just drag and drop any file to/from the documents table view.

[Quickies]Opening URLs in external applications

No Comments

Opening URLs on external applications is easy, no matter if you’re on an iPhone/iPod touch/iPad or on a Mac. On the Mac, we’d do something like this:

NSURL *URL = [NSURL URLWithString:@"http://www.sensitivecode.com"];
[[NSWorkspace sharedWorkspace] openURL:URL];

Simple, uh? Now let’s see how to do this on the iOS:

NSURL *URL = [NSURL URLWithString:@"http://www.sensitivecode.com"];
[[UIApplication sharedApplication] openURL:URL];

Easy peasy :)

[Quickies]Putting a NSXMLDocument into a NSTextView

Comments Off

Say you want to display a XML to the user on a NSTextView. You have a NSXMLDocument called “xmldocument” and you need to put into a NSTextView(you created an IBOutlet called “xmlTextView” in order to make your code interact with the NSTextView). You’d just use this code:

//Convert the NSXMLDocument to NSData
NSData *data = [xmldocument XMLDataWithOptions:NSXMLNodePrettyPrint];
//Create a string from the NSData object you have
NSString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
//Create a NSAttributedString from it
NSAttributedString *attributedString = [[[NSAttributedString alloc] initWithString:string] autorelease];
//Now set the attributed string for the NSTextView
[[xmlTextView textStorage] setAttributedString:attributedString];

Objective-C on other platforms

No Comments

As some of you know, NeXTSTEP was very popular because it allowed developers to create applications in a fraction of time it would take on the other platforms. What if we could program in Objective-C on Windows, Linux, BSD and other platforms? Yes, we can! Here I’ve got a couple tips for those who want to port Cocoa apps to other OSes.

Cocoatron

Cocoatron is a very young alternative. It was started in 2006. It promisses to be the “Cocoa for Windows” implementation. It’s not very mature and you will often find a NSUndefinedClass, which will make your app crash. You must be using a Mac in order to compile code using Cocoatron. Not to mention the fact you may end up having to use the WIN32 API for some stuff.

GNUStep

GNUStep seems to be the best choice if you want to program in Objective-C on other platforms. It features many tools like Gorm(similar to the Interface Builder), ProjectCenter(similar to Xcode) and a couple other apps. It can be implemented on Linux, Windows, BSD and most(if not all) operating systems out there. And best of all, it’s released under GNU Lesser General Public License(AKA LGPL) which allows you to create commercial and closed-source app using it. It uses its own drawing system, which will not allow an app to look like a native app. The workaround is to theme it! It has a great themming functionality. Also, you must ship the GNUStep installer with the apps you create using it, otherwise they will not work.

Bonus: CoreFoundation

CoreFoundation isn’t written in Objective-C, but Apple has made it open-source. One of its biggest problems is the fact it’s an old version of CoreFoundation. It’s the CF from Tiger, newer versions are not open-source. It can be ran on Linux and Windows under Cygwin.

ShareKit: sharing made easy

No Comments

Today being social means being cool. I mean, most apps have some sort of a sharing feature. There are tons of social networks, but the ones that hold most attention are Twitter and Facebook. Imagine yourself coding a share feature for each social network. Seems a bit painful, doesn’t it? So here’s the solution for your sharing problems! ShareKit is a framework which contains classes that allows you to share stuff on most popular social networks. ShareKit supports networks like ReadItLater, Facebook and Twitter.

Just copy a couple files to your project, import a header and implement a share feature with a few lines of code, and it’s done! Some networks will require you to get an API key, but ShareKit has a header file for you to configure it. Just paste your API keys and it’s configured.

You can download it and find more information on its official website.

Obama is a joke

No Comments

I still remember the 2008 USA elections. The country’s biggest economic crises was going on after 8 years of George Bush. Everybody thought Obama would be the greatest solution. He had a great speech, it seemed like he had super powers, that he could do everything. It’s been 3 years since he became the US president and, as most people, I’m very disappointed with him.

He promised a lot, but we haven’t seen much. While Osama Bin Laden is dead and the recession is over, he didn’t do almost 10% of what he was supposed to do. Recession is over, but the country is still broke. Unemployment is much higher than it is supposed to be, the country’s debt is incredible and so on. One of the most important things to me, the immigration reform, has no signs of life. And to be honest, I doubt that will happen anytime soon. Not to mention WikiLeaks. In fact, that made me lose all my respect for Hilary Clinton because of her speech. I expected more from him on this topic. What about apologizing, fix things and admit they screwed up? The US wouldn’t be so infamous now and people would still have more faith in the humanity.

He says the opposition won’t allow him to do anything. Come on, he is the fucking president! Instead of giving excuses, why not doing something? He talks about republicans, but he won’t assume that the biggest opposition is in his own party! For example, the Dream Act didn’t pass because 5 democrats voted against it. He lost a lot of time trying to convince republicans of his ideas, but he forgot about his own party. I mean, if he had spent more time trying to convince democrats about his plans when they were the majority in the congress, things would have been MUCH easier.

Seriously, I hope the next president will be better. Let’s just hope it won’t be Sarah Palin or any other Barack Obama.

Birthday!

No Comments

Today I’m turning 18. I guess I won’t need that emancipation document anymore. lol

PS: gifts are important :)

Stop SOPA

No Comments

Visit http://americancensorship.org/ and show your support.

Older Entries Newer Entries