All posts by Farhad Noorzay
Why I love doing what I do
Posted by Farhad Noorzay on April 28, 2012
http://farhadnoorzay.com/2012/04/28/why-i-love-doing-what-i-do/
A Simple Alternative to UDID’s on iOS

Photo courtesy of http://www.talkandroid.com
The fact that Apple deprecated the use of UDID’s as an identifier for developers in iOS 5 is nothing new. There have been many privacy concerns related to the use of a users UDID by developers, but I won’t get into that. Till now, developers could still access a users UDID, since the API is only deprecated and not fully removed. After the recent Path privacy fiasco, Apple has felt the heat and required app developers to ask for user permission before accessing just about any user data, including UDID.
The good news is there is a very simple alternative to using a users UDID and it’s called UUID (Universally Unique Identifier). UUID was standardized by the Open Software Foundation (OSF) and is said to be “practially unique” rather than “guaranteed unique”. But that’s not something you need to worry about. The Wikipedia page for UUID states:
“… one’s annual risk of being hit by a meteorite is estimated to be one chance in 17 billion, that means the probability is about 0.00000000006 (6 × 10−11), equivalent to the odds of creating a few tens of trillions of UUIDs in a year and having one duplicate. In other words, only after generating 1 billion UUIDs every second for the next 100 years, the probability of creating just one duplicate would be about 50%.”
The even better news is generating a UUID in iOS is extremely simple thanks to Core Foundations CFUUID class. Here’s how:
- (NSString *)uuid
{
// Creates a Universally Unique Identifier (UUID) object.
CFUUIDRef uuidObject = CFUUIDCreate(kCFAllocatorDefault);
// Returns the string representation of a specified CFUUID object.
NSString *uuid = (NSString *)CFUUIDCreateString(kCFAllocatorDefault, uuidObject);
CFRelease(uuidObject);
return [uuid autorelease];
}
Note: With ARC you need to use __bridge when casting from CFStringRef to NSString *.
That’s all the code you need to replace your use of UDID’s.
Please share any comments or suggestions below!
Posted by Farhad Noorzay on March 11, 2012
http://farhadnoorzay.com/2012/03/11/a-simple-alternative-to-udids-on-ios/
Tips for improving performance of your iOS application
Great post on iOS performance by Ankit Gupta, co-founder @ Pulse News!
http://eng.pulse.me/tips-for-improving-performance-of-your-ios-application/
Posted by Farhad Noorzay on March 11, 2012
http://farhadnoorzay.com/2012/03/11/tips-for-improving-performance-of-your-ios-application/
Objective-C: How to Add Delegate Methods in a Subclass
I love design patterns. When understood and used properly they can make your life as a developer so much easier. One of my favorites is the delegate pattern which is used all over the place in Cocoa Touch. Delegation is a design pattern which allows an object to “delegate” work to another helper object. This design pattern is great because it allows you to provide custom behavior without having to subclass.
But there are times when you need to subclass a class that has already implemented a delegate and add additional delegate methods. As a matter of fact, one of the most used classes in iOS does this… UITableView. We’ll take a look at UITableView and see how it adds delegate methods.
UITableView is a subclass of UIScrollView as you can see from its header file.
UIKIT_CLASS_AVAILABLE(2_0) @interface UITableView : UIScrollView <NSCoding>
If we look at the UIScrollView header we’ll see
UIKIT_CLASS_AVAILABLE(2_0) @interface UIScrollView : UIView <NSCoding> {
id _delegate; // A delegate instance variable is declared of type id
}
// The delegate will be required to conform to the UIScrollViewDelegate protocol
@property(nonatomic,assign) id<UIScrollViewDelegate> delegate;
@end
You can see that the “delegate” instance variable should conform to the UIScrollViewDelegate protocol. So as a subclass, UITableView wants to also use the delegate pattern and has to add the additional methods it needs. It’s actually pretty simple to do so.
Step 1) Create your delegate protocol and extend the parent classes delegate protocol (in your .h)
// This is the syntax to extend another protocol @protocol UITableViewDelegate<NSObject, UIScrollViewDelegate> // Your delegate methods go here... @optional // Display customization - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath; @end
@property(nonatomic,assign) id <UITableViewDelegate> delegate;
Step 3) Tell the compiler that the delegate property will be provided at runtime (by the superclass in our case) (in your .m)
@dynamic delegate;
That’s all there really is to it. Other classes can now conform to the delegate protocol, set themselves as the delegate, and receive delegate calls from UITableView and UIScrollView. So if you ever need to add delegate methods in a subclass, remember UITableView is a great example.
*You can learn more about design patterns in iOS in Apples documentation.
Posted by Farhad Noorzay on January 20, 2012
http://farhadnoorzay.com/2012/01/20/objective-c-how-to-add-delegate-methods-in-a-subclass/
Pulse Sync Released!
Today was the first major Pulse release that I’ve been a part of! We released Pulse sync so you can now sync your sources across all your devices. Check out our blog post. One of our most requested features and definitely a feature I’ve been looking forward to.
It was a long day but very exciting, tense, busy, and fun
This release was a cross team effort and it was really nice to see how everyone came together to make this possible.
Make sure to download the update from the app store and let me know what you think!
Posted by Farhad Noorzay on October 12, 2011
http://farhadnoorzay.com/2011/10/12/pulse-sync-released/
Check out my post on the Pulse blog
Wrote a piece on the Pulse blog about what it’s like to be an engineer at Pulse. Really meant every word in that post. Pulse truly is a great place to be at.
http://blog.pulse.me/whats-it-like-to-be-an-engineer-at-pulse
Thanks to @knga for taking the pictures and helping put it together.
Posted by Farhad Noorzay on September 29, 2011
http://farhadnoorzay.com/2011/09/29/check-out-my-post-on-the-pulse-blog/
Finally!
I’ve been meaning to setup this blog for a while and I’ve finally managed to do it! I have a lot of ideas for things I want to use this blog for and am really excited to get things going. I plan to share my thoughts on a lot of different stuff. More importantly, hope to share code snippets and simple tutorials for iOS related stuff. Best way to learn is to teach so, more than anything, this is a forum for me to learn
Posted by Farhad Noorzay on September 29, 2011
http://farhadnoorzay.com/2011/09/29/finally/


