27
Oct
2008
 

Announcement: Marcus’ Core Data Book Just Went Beta!

by Matt Long

Core Data BookA lot of hard work has gone into this book already and I see it becoming the definitive text on the subject of Core Data. The release date is slated for March 30, 2009, but it’s great to see it in beta. If you want to pick up the beta in PDF, it is available now from Pragmatic here: Core Data: Apple’s API for Persisting Data under Mac OS X.

While new Cocoa programmers will find it a great help to getting started quickly with Core Data, the book also covers some really interesting and advanced topics such as data versioning and migration, Spotlight/Quick Look integration, Sync Services, and multi-threading. You can really see Marcus’ command of the subject shine in these chapters which are already available in the beta.

Give Marcus some feedback on the book as it progresses. It’s going to be a great reference for any Cocoa Developer looking to harness the power of Core Data.

$21.00 for the beta PDF
$41.35 for the beta PDF plus hard copy when it’s released in March.

Mad props to Marcus. Congratulations!

 
25
Oct
2008
 

Core Animation Tutorial: Slider Based Layer Rotation

by Matt Long

It is often helpful to create a custom control for you application that will display a value as a level like a gas gauge shows how full your tank is. In this post I will demonstrate how to create a three layer tree that will show the current rotation of a circular layer as the value from a slider (NSSlider) is updated in real time. The layers include the root layer, the rotation layer, and a text layer that will display the current rotation in degrees.
(more…)

 
1
Oct
2008
 

Cocoa Touch Tutorial: iPhone Application Example

by Matt Long

Similar to one of my first blog posts on building a basic application for Mac OS X using xcode 3.0, I am going to explain for beginning iPhone/iPod Touch developers how to build the most basic Cocoa Touch application using Interface Builder and an application delegate in xcode 3.1. This tutorial post is really to provide a quick how-to. I won’t go into any depth explaining why things are done the way they are done, but this should help you get up and running with your first application pretty quickly so that you too can clog the App Store with useless superfluous apps (kidding… just kidding).

If you are a visual learner, it may be helpful to you to instead watch a video presentation of this tutorial. I’ve posted it on the site, but you’ll have to click the link to see my Cocoa Touch Video Tutorial.
(more…)

 
24
Sep
2008
 

Core Animation Tutorial: Core Animation And Quartz Composer (QCCompositionLayer)

by Matt Long

Last night at NSCoder night, Fraser Hess was asking question about being able to draw in a Quartz Composer View (QCView) about which none of the rest of us had any knowledge or experience. As I’ve been doing a lot with Core Animation lately, I asked him if it was possible to just make the view layer backed and start adding layers to it. Fraser hasn’t worked with Core Animation much yet, so he was unsure. The other three of us set to looking at docs and making demo apps. The race was on… Oh. It’s not a race? Sorry about that. I thought we were practicing for Iron Coder…
(more…)

 
10
Sep
2008
 

Core Animation Tutorial: Rendering QuickTime Movies In A CAOpenGLLayer

by Matt Long

I’ve been experimenting a great deal lately with OpenGL and QuickTime trying to see how the two technologies work together. It’s been a bit challenging, but fortunately Apple provides two really great resources–number one, sample code. I’ve been able to learn a lot just from the samples they provide in the development tools examples as well as online. And second, the cocoa-dev and quicktime-api lists are great. Lot’s of brilliant people there who are willing to share their knowledge. It’s very helpful, prohibition to discuss the iPhone SDK notwithstanding.

Getting two technologies to work together can be a challenge especially when the bridges between the two are not necessarily clearly laid out in documentation. As I pointed out Apple provides some excellent sample code to help you along, but there is no hand-holding approach to any of it. I actually appreciate that having come from the Windows world as it seems that there all you get sometimes is hand-holding where Microsoft doesn’t trust you, the developer to figure things out and really own what you’re doing. But I digress (wouldn’t be a CIMGF post if I didn’t dig on MS a bit).
(more…)

 
24
Aug
2008
 

Cocoa Tutorial: C# LINQ Or Cocoa Key Paths And NSPredicate

by Matt Long

I think it may be helpful to demonstrate how to perform certain tasks in Cocoa from the perspective of a Windows programmer. And considering that I was one, it seems that I may be able to help shine some light on some of the issues that programmers face when coming over to the Mac platform. In this post I want to highlight one of Objective-C’s coolest features, key-value coding, in light of a Microsoft technology that was introduced in the most recent edition of the .NET framework (v3.5).

Microsoft’s new technology called LINQ, which stands for Language Integrated Query provides a way for developers to massage data collections using a SQL-like syntax that is built right into the language. You can perform simple data queries like this.

List products = GetProductList();

var soldOutProducts =
    from p in products
    where p.UnitsInStock == 0
    select p;
    
Console.WriteLine("Sold out products:");
foreach (var product in soldOutProducts)
{
    Console.WriteLine("{0} is sold out!", product.ProductName);
}

Notice how it has a very SQL like syntax. It’s actually very powerful and robust. There are a lot of capabilities. Take a look at the 101 LINQ Samples page if you would like to see more examples. What’s most interesting to me though is that the ideas behind this technology are not new.

If you’re new to Cocoa, you’ve probably heard of key-value coding and have probably even worked through some examples of its use without really understanding it. While the usage is different between the two, these technologies provide similar capabilities. Objective-C just had them first.
(more…)

 
29
Jul
2008
 

Cocoa Tutorial: Windows OOP vs Cocoa MVC

by Matt Long

Encapsulate everything! Right? Or not. I was watching the Cocoa developers email list today and saw a post asking for help getting two views to communicate between one another. Having been a Windows programmer for longer than I’m willing to admit, I recognized the question as it was one that I also had when I moved to Objective-C on the Mac. I think I can ask the question more succinctly now than I could then. Better phrased it would be “I have a dialog object that I instantiated and obtained some data from the user with it. I now need to get that data out of my dialog object back into my main window object where I can do something with it. How can I get the information back into my main window from the dialog?”

In Windows, more specifically C# .NET, you would create a new window by adding a Windows Form object that you could then edit with the designer adding various controls pretty easily. But once that window was created, you now need to create an instance of it in your main window code and then provide public accessors to assign or obtain data between the two windows. The window class generated by the Windows Form template encapsulates everything for you. It certainly makes the code look clean, but it really breaks the Model View Controller paradigm so it’s no wonder Windows programmers (myself included) have a hard time shifting their way of thinking.
(more…)

 
16
Jun
2008
 

Cocoa Tutorial: Custom Folder Icons

by Matt Long

This is just another one of those things that seems like it ought to be a simple little code snippet and you’re there, but in actuality it’s just not the case. I am building an exporter for my application that will export a movie project in iMovie HD format. I want to mimic the file format exactly and one of the things I noticed about the directories that are stored inside iMovie HD‘s custom format (select ‘Show Package Contents’ from the context menu in the Finder) is that they have custom icons assigned to them. So the problem to solve was how to do that programatically. Here is what I’ve found.
(more…)

 
3
Jun
2008
 

Version Control Makes You A Better Programmer

by Matt Long

I’m a believer. I’ve used version control before, but Marcus has convinced me that with a little known version control system called Git, written by Linus Torvalds (the creator of Linux), version control is not just about versioning, it’s about expressing yourself with your code and collaborating with others, seamlessly.

As memory serves the only time I’ve used version control in a meaningful way the system I was using was Visual SourceSafe from Microsoft. I know. Blech! It’s awful! I’ve pulled code from many a CVS or Subversion repository, but I’ve never really used them in the way they are intended to be used. Now, thanks to Marcus, I realize that version control isn’t just about versioning any more. It’s a whole methodology/ideology that makes better programmers. Here is what I mean.
(more…)

 
24
May
2008
 

Cocoa Tutorial: Working With Application Resources

by Matt Long

For most simple applications using and managing resources is handled seamlessly and you don’t ever have to intervene programatically. There are times, however, as your applications begin to mature that you need to access resources directly. Doing so is pretty straightforward, but I thought I would document it here–if for no other reason than to have it written down somewhere for the next time I need it. I hope it might be helpful to you too.
(more…)

 
13
May
2008
 

From Hacker to microISV: Custom File Formats

by Matt Long

In this continuing series on my own transition from a Mac application hacker to microISV (Independent Software Vendor), I am going to demonstrate how to create your own file format for your application. You’ve probably seen these types of files in popular applications such as iMovie HD (06′) or GarageBand or even xcode in which the actual files used are, behind the scenes, folders that the operating system treats as regular files. These folders/files have a special bit set on them that tell OS X how to deal with them. The goal of this post is to demonstrate how you can do the following:

  • Create your own file format with your own file extension
  • Register your file format with the operating system
  • Provide application loading of your file that’s been double clicked in the Finder
  • Write data and preferences back out to your application file
  • Add resources such as media files to your application file

(more…)

 
3
May
2008
 

Cocoa Tutorial: File Copy With Progress Indicator

by Matt Long

I often find and therefore come to expect common problems in Cocoa to be easily solvable, however, there are times, like this, where I am a bit disappointed that the problem can be so difficult. All I need to do is copy a file. This is a simple task right? All you need is NSFileManager and a call to – (BOOL)copyPath:(NSString *)source toPath:(NSString *)destination handler:(id)handler and you’re good to go. Not so fast, city slicker. This one is going to take a bit more effort cause you want one of them fancy new-fangled progress indicators to show how much of the file has been copied. Well, if you want Cocoa to help you, you’re out of luck cause NSFileManager won’t do that for you, but with a little bit of effort you can get it to work with some… gulp… C APIs.
(more…)

 
28
Apr
2008
 

From Hacker to microISV: Dynamic About Box Version and Copyright, and Text Formatting

by Matt Long

In this post I continue to address topics of relevance to Macintosh programmers who are, like me, moving from being hackers to becoming independent software vendors (micro ISV). Today I am going to address adding copyright and version information to your about dialog and show you how you can update these dynamically. I also cover a few tips on formatting the text in your about dialog. There is more than one way to achieve these things, but my hope is to help others out there who need to accomplish these things and have no prior experience doing them on the Mac.
(more…)

 
19
Apr
2008
 

From Hacker To microISV: App Names And Icons

by Matt Long

For the past five or six months, I have been developing an application for the Mac that I intend to release for sale in the near future. Though you could probably call me a switcher, to my credit I was a Mac user all through college and would have remained so had the job market been a bit more supportive of that desire when I finished school, but all along I’ve wanted to become a Macintosh developer. That time has finally come.
(more…)

 
9
Apr
2008
 

Cocoa Tutorial: Introduction To Identity Services

by Matt Long

Morpheus, Badass!System programming is one of the more interesting topics to me because it seems like it’s the hackers domain. When I first got into programming I always wanted to see if I could make the computer do something that nobody else anticipated it could do. I think it was probably just from watching too many hacker movies. Even the Matrix (the first one, not those other two contorted kill joys) had this affect on me that somehow I could beat the system because as Morpheus put it,

I’ve seen an agent punch through a concrete wall. Men have emptied entire clips at them and hit nothing but air, yet their strength and their speed are still based in a world that is built on rules. Because of that, they will never be as strong or as fast as you can be.

Man! I loved that movie the first time I watched it. A world without rules? Or more specifically a world where you set the rules by your most awesome hacker powers. Sweet!

But alas, as I’ve proceeded and matured (I hope) in my programming abilities, this whole area has become much less glamorous as I realize that hacking is really about finding vulnerabilities in other people’s code. That’s really not that exciting to me, but system level programming remains interesting and a good place to start is to look into who the users are on my system. Time to use Identity Services. And in this intro I’ve written a very basic password cracking system.
(more…)