Objective-C

Very Very Classy

Posted by Dallas on June 17, 2010
Apple, Cocoa, Cocoa Touch, Fanboy, Mac, Objective-C, Programming, WWDC, iPhone / No Comments

I was VERY disappointed that I was unable to make it to Apple’s WWDC (World Wide Developer Conference) this year (it was last week).

The sessions are always VERY informative, but it is also a excellent chance to not only meet with other Mac/iOS developers, but you have the chance to talk one on one with the very people who are writing the software and API’s (Application Programming Interface) that we write software for/with.

Apple does make the videos of the sessions (along with the slides) available to everyone that attends, and allows those that didn’t attend to purchase the videos.
Before last year, these videos usually took around 6 months to become available, however last year they had them released within a month.

This year Apple TOTALLY outdid themselves and have released the videos all today!
That is LESS than 1 week!
Not only did they release everything within a week, but Apple has made all of the videos and slides available to ALL registered developers (even the free developer accounts) FOR FREE!!! That is a $500 savings for those that couldn’t attend!

I only have 2 things to say…

First: Good bye to my Hard Drive space :-) (The videos are available in HD and Standard formats this year)

and Secondly… Classy Apple! VERY VERY CLASSY!

Reminder: Even though the videos did not cost this year, they are still covered under an NDA that you agree to when signing up for a developer account. Don’t make them sorry that they were so giving.

Tags: ,

Core Data Speed Gotcha

Posted by Dallas on December 31, 2009
Cocoa, Cocoa Touch, Core Data, Mac, Objective-C, Programming, iPhone / No Comments

Recently I was doing some performance stress testing on my upcoming iPhone app, Newsprint, and ran into a little Core Data gotcha that I thought I would document for both myself and for Google to index for others.

Special thanks to Jeff LaMarche for guiding me in the right direction to figure this out. You can find his blog at: http://iphonedevelopment.blogspot.com/

This issue came to play when I needed to do a fetch request from Core Data and then run a couple of Predicate “searches”/”filtering” on the data.

My original thought was that doing a single fetch request and then running my different predicates on the returned set of objects would have better performance then doing multiple fetch requests since I would only have to pull from the Core Data SQLite DB once and then I would have everything in memory and I could just simply manipulate it.

Turns out that this is HIGHLY incorrect.

If instead you just do multiple fetch requests and implement your predicate into your fetch request, that Core Data and SQLite are smart enough to scan the records more efficiently and without causing Core Data Faults to fire.

This gives a MASSIVE speed increase!

So if you are ever doing something similar, make sure to check this method and see if it to can speed your app up.

Cocoa Touch for iPhone OS 3, Now Shipping!

Posted by Dallas on November 19, 2009
App Store, Apple, Cocoa Touch, Objective-C, Personal, Programming, SDK, iPhone / No Comments

The book that I was the Technical Editor for, Cocoa Touch for iPhone OS 3, is now shipping from Amazon.com and should also be in (hopefully) most Barnes and Nobles.
View it at Amazon.com by clicking here.

This book is great for new iPhone developers as well as experienced ones.
You will need some Objective-C knowledge, but if you have some OOP (Object Oriented Programming) experience you should be ok with picking up an Objective-C book as well for as you work through the book.

If you are in a B&N stroll into the Geek, err, I mean Computer Programming section and look for the book.
Feel free to buy a copy to support my good friend and author of the book, Jiva DeVoe.
If you can’t get yourself to that level of geek, at least pick it up and look at the ‘Credits’ page, right before the Table of Contents and then you can go around to all the geeks in that area and say, “I KNOW THIS GUY!” :-)

This makes 2 iPhone development books that I have been involved in, each one with more of a role than the last, however I can safely say it will be my last as after being involved with the book writing processes and having the author be a close friend of mine, I don’t really have a desire to write one myself (unless it’s an offer I just can’t refuse).

cocoaTouchForIPhone

Coming Soon to a Bookstore Near You

Posted by Dallas on May 05, 2009
Apple, Cocoa Touch, Objective-C, Personal, Programming, SDK, iPhone / No Comments

I have been offered a gig of being the Technical Editor for an upcoming iPhone programming book.

The book is called “Cocoa Touch for iPhone 3.0″ and is being written by my friend Jiva DeVoe and published by Wiley and Sons Publishing.

You can visit the current pre-emptive webpage for the book at: http://www.wiley.com/WileyCDA/WileyTitle/productCd-0470481072.html

I was previously a Technical Reviewer for the programming book: iPhone SDK Application Development, 1st Edition

It will be interesting the see the differences between being a technical reviewer and a technical editor.

Tags: ,

ChocTop

Posted by Dallas on March 01, 2009
Cocoa, Objective-C, Personal, Programming, Programs / No Comments

I have been finalizing the beta for iDeskCal 2.0 and in the process came across ChocTop.

ChocTop is a system for rapid mac software DMG packaging.

In setting it up and using it I found that it lacked a feature I wanted.
Mainly the ability to specify that it should you a Debug build instead of the standard Release build that you would usually use.
The reason for wanting a Debug build is simple… I am packaging up a Beta.

So even though I don’t know Ruby (which is what ChocTop is written in) I set foot to add this feature.
Luckily like most computer languages I was able to understand it enough to understand what was going on and enough to add this new ability.

Once I was done and used it myself, I sent it back into the developer and he has already integrated it into the repo version of the code.

If you are a Mac developer checkout http://drnic.github.com/choctop/

Log all accessed methods in Objective-C with DTrace

Posted by Dallas on February 07, 2009
Cocoa, Cocoa Touch, DTrace, Mac, Objective-C, Programming, iPhone / No Comments

I have recently been debugging some Objective-C and Cocoa/Cocoa Touch code.

Not being familiar with all the code and with a TON of methods being accessed in milliseconds, my attempts at stepping through the code just wasn’t working, as clicking ‘Step Into’ as fast as I could keep up and over an hour of stepping through I was still not even close to figuring out what I needed to know.

This lead me to the thought of logging every method that was accessed and then I could step look through it and skip around as needed.
However with 60 some odd files and say maybe 20 methods in each file, that would take a lot of NSLog’s.
I started looking around and was pointed to bbums blog about doing something similar.
However it still would take adding some code, plus I couldn’t get it working right with the iPhone.

This lead me to wonder about DTrace.
After a recent podcast from Scotty at the Mac Developer Network, featuring Colin Wheeler talking about DTrace, I have been very interested in learning more about DTrace.

The difficult thing I have been finding is that since DTrace was originally written for Sun, it is hard to find info related to MacOS and more so Cocoa.

I then found a video from Colin about using DTrace with Cocoa and XCode.
http://www.viddler.com/explore/Machx/videos/8

I wasn’t able to get what I wanted working, so I hit Colin up on Twitter and then talked to him a bit in email and he pointed me to the Golden Solution!

The solution is:
objc$target:::entry{}

So I took that and created a DTrace script.
You can grab it here:
http://kdbdallas.com/wp-content/uploads/2009/02/logallmethodsd.zip

To run it open Terminal and run:
sudo ./logAllMethods.d -p PID

Of course replacing ‘PID’ with the PID of your running program and remembering that for DTrace ’sudo’ is required.

Also note that this works for iPhone programs running in the iPhone Simulator.
Just look for the PID of your iPhone app within Activity Monitor once it’s running in the simulator.

Be careful as depending on the program it can spit out a TON of data VERY quickly.

Running this against Adium for only a fraction of a second gave me a couple hundred lines of output.

The output looks like this:

tesseract:Desktop dallas$ sudo ./logAllMethods.d -p 4371
dtrace: script ‘./logAllMethods.d’ matched 71222 probes
CPU ID FUNCTION:NAME
0 59398 -retain:entry
0 34684 +retain:entry
0 32061 +idleAllMovies::entry
0 32062 -idle:entry
0 34707 -retain:entry
0 32914 -_usingVisualContext:entry
0 32878 -_resyncNaturalSize:entry
0 31935 -loadState:entry
0 31972 -naturalSize:entry

Hopefully this helps someone out there.
Just remember always use the info I post for good.
(or if its for evil make sure it profitable and then send me a cut)

Once again, special thanks to Colin Wheeler.

Tags: , , , , ,

White Indeterminate Progress Indicator (AKA: White NSProgressIndicator)

Posted by Dallas on December 28, 2008
Cocoa, Objective-C, Programming / 1 Comment

If you have ever wanted to use a Indeterminate Spinner NSProgressIndicator on a dark background you have probably been upset to find that there is no way to get a white spinner.
That is where WhiteIntermProgIndicator comes into play.
WhiteIntermProgIndicator, is based off of AMIndeterminateProgressIndicatorCell by Andreas at Harmless Cocoa.

Screenshot:
whiteintermprogindicator

Download: WhiteIntermProgIndicator.zip

Tags: , ,

Mac/iPhone: Show Available Usable Disk Space

Posted by Dallas on December 27, 2008
Mac, Objective-C, Programming, iPhone / 5 Comments

If you have an application that allows users to upload content to the app, you might want to show the user how much space is available for them to use.

This is especially true on the iPhone where it is not as easy for the user to quickly check if they have enough room to upload a given file.

You may also want to check if there is enough space before you start the upload, so you can inform them that the file wont fit.

That brings you to the task of figuring out how much free space there is, and more importantly how much free space is left that you as an unprivileged program can access.

The following code is based towards the iPhone, however all that would be needed to change it to be used on the Mac is the location you are checking for free space, and the setting of the label.

NOTE: The below “shown” code is old. The updated code is in the zip file at the bottom

#include <sys/param.h>
#include <sys/mount.h>
NSString *sizeType;
 
float availableDisk;
 
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
 
struct statfs tStats;
 
statfs([[paths lastObject] cString], &tStats);
 
availableDisk = (float)(tStats.f_bavail * tStats.f_bsize);
 
if (availableDisk > 1024)
{
	//Kilobytes
	availableDisk = availableDisk / 1024;
 
	sizeType = @" KB";
}
 
if (availableDisk > 1024)
{
	//Megabytes
	availableDisk = availableDisk / 1024;
 
	sizeType = @" MB";
}
 
if (availableDisk > 1024)
{
	//Gigabytes
	availableDisk = availableDisk / 1024;
 
	sizeType = @" GB";
}
 
diskSpaceLbl.text = [[@"Available Disk Space: " stringByAppendingFormat:@"%.2f", availableDisk] stringByAppendingString:sizeType];

This will give you something like the following:

availablediskspace

UPDATE:
I have gone a step further and made this into an easy to use class, that works out of the box with the iPhone and the Mac.

FSStats.zip

Tags: , , , ,

Pi Presentation: SQLite

Posted by Dallas on December 04, 2008
Cocoa Touch, Objective-C, Programming, SDK, iPhone / No Comments

Last night I gave a presentation at the Phoenix iPhone Developers Group (Pi) on SQLite.

I am posting the presentation and sample code here for anyone who is interested.

Please note that this is by no means the “proper” or only way of doing things. This is simply one way of doing it, and is for reference purposes only. The code uses the FMDB SQLite Wrapper.

Example Code: (example.zip)

Keynote Presentation (sqlite-presentation.zip)

Tags: , , ,

Phoenix NSCoder Night

Posted by Dallas on October 26, 2008
Cocoa, Mac, Objective-C, Programming, iPhone / No Comments

I am proud to introduce NSCoder Night for Phoenix.

If you haven’t heard of NSCoder Night, here is a brief intro (partially borrowed from the website)

NSCoder Night is a weekly event where Cocoa developers come together for some coding and camaraderie in the relaxed atmosphere of a coffee shop or pub with a wireless network.
Unlike more formal meetings like CocoaHeads there is no presentation, just hanging out with other (similar interest) geeks and working on your own projects or group projects. It is a great way to gain a IRL (in real life) friendship with other developers, as well as getting help on something you are stuck on.

It is kind of similar to how we go somewhere after XCodePhoenix meetings, but with your laptops and more frequently.

As there is no presentation it is a low key come and leave as you need type of meet-up.
If you can’t make it one week, thats ok, make it the next week.

The Phoenix chapter of NSCoder Night will be meeting Tuesdays at 7pm at Coffee Rush @ Gilbert and Baseline in Gilbert.

Fell free to to tell all your dev friends and we hope to see you there.

Tags: