I was such a moron…

No Comments

Not too much people could say they had the chance to get rich when they were 14. Really. Believe in me or not, I had that fucking chance and I knew that. Not sure if you guys remember, but a couple years ago, as soon as the iPhone App Store came out, there was a lot of people making money on it. I knew that and all I had to do was to learn Objective-C + Cocoa(which I was supposed to have learned a couple months before I found out about the iPhone-made-rich-man). Even if my apps didn’t sell a lot, come on, there were a lot of people willing to invest everything they had on it(even their asses and their souls). So yeah, I had the chance. Mobile platforms have never been my favorites. In fact, I’d write only Mac software if I could. But I knew I had to program for the iPhone.

I started making plans for the money, like moving to Los Angeles, Mountain View, San Jose or San Francisco, buying an iPhone 3G(my dream gadget at the time) and a 17″ MacBook Pro with the best processor, memory and hard drive available. Not to mention other things like buying a Nintendo Wii and go to the mall to spend money(for just one day guys, I have never been so immature to spend a lot of money on shit all the time). I still go to the mall to walk and not to buy stuff. It makes no sense at all, I know.

Basically I was depressed at the time. I was depressed for almost 1 and a half years at the time. This depression lasted for another year. I read some time ago that the dementors from Harry Potter were inspired on depression. If it’s not, it’s would be a great inspiration for such characters. Depression sucks your blood and hope, just like a vampire. I really didn’t know I had depression at the time. Depression sucked my desire to learn how to program for the Mac and the iPhone. I just used to think that I still had time. DAMN! FUCKING DAMN! FUCKING DAMN SHIT!  6 months passed and it became impossible to make money on the iPhone app market. Basically because there was a lot of apps and developers out there(including those in India which will create an app for 140 bucks).

I wonder how my life would be now. While there is a possibility I’d have lost everything due to little experience, there’s a chance I’d pick that up quickly. I’d probably be living in the US right now and who knows what else. I still blame myself for that. Now that I’m an expert on iOS development, the market isn’t that good anymore. A lot of people thought like me, but the difference was that, unlike me, those people actually did something. So now I’m here, a mid-class worker living in Brazil.

So you might be thinking “That was a long time ago, why the hell you’re writing this post?”. It’s not about remembering about that time. It’s about something else. Have ya ever heard that music can bring our feelings back? Right now I’m listening to a song that I used to listen in early 2009, and that brought the feeling back. I feel like I’m still in that year while I’m listening to it.

BTW, I know I shouldn’t talk about suffering from depression in public as most people think people who suffer from depression got schizofrenia and randomly decide to kill people. If you think that, ya should be ashamed of yourself. Depression is just the lack of pleasure of living. If someone who suffers from it kills somebody, it surely will be themselves, not other people. But seriously, I had to write about that.

PS: comments saying depression is the lack of Jesus in my life will be ignored. I don’t need Jesus as I already have the Flying Spaghetti Monster.

RIP Sensitive Code

No Comments

Hey folks, unfortunately, my blog Sensitive Code is dead. I had no time to update it and ended up not renewing the domain registration. It had a great page rank. For example, if you type UIFileSharing on Google, a post from Sensitive Code it is the first result(not sure for how long). I moved every post from there to this blog, so everything is still available. I hope to write about programming on this blog in the future.

Easy multithreading, a courtesy of NSOperation

No Comments

Threading is known for being very hard in any language. A foolish mistake can make your application crash. Programmers spend a lot of time to make sure everything works fine. On Mac OS X 10.5, Apple finally introduced a very easy way to deal with threading. NSOperation is The Apple Way® to deal with threading. All you have to do is to subclass the NSOperation, create and initialize a NSOperationQueue, create and initialize the NSOperation and add it to the NSOperationQueue. For this tutorial, I will teach you how to write a simple app that will load a RSS feed and display it on a NSTableView.

To get started, go to Xcode and create a new project. I will call mine RSS Reader, but feel free to call it whatever you want. Let’s start by editing our AppDelegate.h. Create 3 IBOutlets:

More

Audio streaming with QTKit

No Comments

Audio streaming can be a painful task. Download the audio data and feed an AudioQueueBuffer may be a risky operation and may involve many lines of code. So finally, on Mac OS X 10.6 Apple has introduced QuickTime X. We must remember that QuickTime doesn’t necessarily mean QuickTime Player. In this case, I’m talking about the QTKit framework. QTKit(AKA QuickTime Kit) is a high level framework for dealing with media. The QTKit framework was also updated and now includes this and other new features.

More

[Quickies]Shaking a NSWindow

No Comments

On the Mac OS X login window, when you don’t type the right password, the window shakes. It’s a very cool and classic way to tell people the password is wrong. Even WordPress copied it. You can reproduce the same behavior on an ordinary NSWindow with just 7 lines of code! Here’s how it works:

//Gets the window rect
NSRect rect = [window frame];
//Shake offset amount
int amount = -10;
//Shake the window 5 times
for(int i = 0; i < 5; i++){
//Changes the frame origin
[window setFrameOrigin:NSMakePoint((rect.origin.x + amount), rect.origin.y)];
//Pause the thread for 0.04 seconds
usleep((useconds_t)40000);
//Inverts the offset amount
amount *= -1;
}
//Restore the window’s original position
[window setFrame:rect display:NO];

Download the sample app here.

[Quickies]IRCClient, IRC made easy

No Comments

Have you ever needed/wanted to implement an IRC chat on your Cocoa application? It might be easier than you think! There’s a Cocoa “bridge” for the libircclient library. The lib was written by Georgy Yunaev. Get the files on this link. These few lines of code will make it work:

IRCClientSession *session = [[IRCClientSession alloc] init];
MyIRCClientSessionDelegate *controller = [[MyIRCClientSessionDelegate alloc] init];

[session setDelegate:controller];
[controller setSession:session];

[session setServer:@"irc.dal.net"];
[session setPort:@"6667"];
[session setNickname:@"test"];
[session setUsername:@"test"];
[session setRealname:@"test"];
[session connect];

[session run]; //starts the thread

[Book]Cocoa Programming for Mac OS X

1 Comment

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:

[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.

Older Entries