Making a Class Unavailable in Objective-C – LLVM/Xcode Tips and Tricks

So you have written an Objective-C class and you would like to mark it as unavailable so that others won’t be able to instantiate it?

The solution is simple. In the header file of your class, place the following code:

__attribute__((unavailable("Your message to the developer goes here")))

So here is an example of a class header file that uses this LLVM extension:

#import <Foundation/Foundation.h>

__attribute__((unavailable(“This class is unavailable. Please use the YourClass class instead”)))

@interface MyClass : NSObject

@end

Once a programmer attempts to use this class, they will see something similar to this in Xcode (Click to Enlarge the photo):

Unavailable Objective-C Class

Click to Enlarge

[Feature Request] Audio Comments in Xcode? That would be great!

So I have had this idea for a while. The idea is simple. Audio comments in your favourite IDEs, such as Xcode.

What do I mean by that? Well, think about all the times where you were coding something complex and wanted to leave some comments in the code explaining to a fellow programmer how your algorithm works. Wouldn’t it be better if you could just record your voice and say what the algorithm does? And have that recording attached to the code and viewable right in the IDE?

That would be great!

I know I would use that. To demonstrate, I’ve attached how I envision this feature looking in Xcode (Click on the image to enlarge it)

Leave your comments below if you think this is a good idea too and would like to see it in action.

Audio comments in Xcode

This is a new feature which I hope all IDE makers, like Apple, will start incorporating into their product. I really think this will be the next evolution on code commenting.

Update 1: 11th July 2013:

So after I submitted this feature request to Apple, this is the email I get back from their team:

Hi Vandad,
This is a follow-up regarding Bug ID# 14370555.   
Engineering has determined that this is not to be fixed based on the following information:
OSX has voice over etc. You can also add file links to an audio file in a comment for example. 
Thank you very much for the suggestion.
If you have questions regarding the resolution of this issue, please update your bug report with them.
We are now closing this bug report.
Please be sure to regularly check new Apple products for any updates that might affect this issue.
Thank you for your assistance in helping us discover and isolate bugs within our products. 
Best Regards,
Developer Bug Reporting Team 
Apple Worldwide Developer Relations
Seriously, Apple? VoiceOver? I don’t even think their engineers understood the suggestion :-D

 

String enums in Objective-C

Note: I have written a newer and better solution to this problem in a new video, which you can watch by clicking here.

Sooo a lot of programmers think enumeration items cannot be strings, and they are right, BUT, there is a BUT. You have to understand that C strings that are made out of 4 characters, each of which is 1 byte long, constitute a memory address that is 4 bytes long, or just the equivalent of int, NSInteger or whatever you want to call it.

So if you put a value such as ‘Good’ for the enumeration item, in fact, the compiler will translate the values of ‘G’, ‘o’, ‘o’ and ‘d’ as their numerical values and will generate a hexadecimal value and put it as the integral value of the enumeration item.

Let’s say we want to say “Good”, or “Nice” all in enumeration items in C. Here is the example, this code runs fine in Objective-C for iOS or OS X as well:

Screen Shot 2013-03-24 at 19.30.24

The output of this is the string “dooG” printed to the screen if you run this on an iPhone device for instance. The reason is the bytes are obviously reversed as the string ‘Good’ has the letter ‘d’ as the lowest byte and that ends up being at the first byte of the string so we end up with “dooG”. That’s not good though, is it? So we just have to swap the bytes around to get the proper string:

Screen Shot 2013-03-24 at 19.31.08

Easy peasy, aye? The highlighted line is very important. That line swaps the order of bytes in the integer. Also note that I am using the calloc function as it will not only allocate the memory but also set the byte values to 0x00 in the memory for us so we don’t have to do it manually or with another procedure.

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

xcrun is an absolute mess

So I just ran this command:

xcrun -sdk iphoneos –run PackageApplication -v “build/Release-iphoneos/testing.app” -o “/users/vandadnp/Desktop/” -s “iPhone Distribution: Pixolity Ltd.” –embed “/Users/vandadnp/Library/MobileDevice/Provisioning Profiles/Pixolity_Wildcard_Ad_Hoc.mobileprovision”

To sign a simple app and package it into an .ipa file and guess what? The packaging failed and xcrun DELETED MY WHOLE DESKTOP. You know what that means? That means all my development environment is wiped without me being able to get them back. This is absolutely mad.

So xcrun failed to do the .ipa file and then tried to clean up after itself except for the fact that the cleaning up happened on my desktop. And what is Xcrun’s solution to cleaning up? Of course, it deletes the whole freaking destination folder, in this case, my desktop.

Apple, big fail, seriously, you guys need to educate yourselves on how to create IDEs and development tools.