CEPubnub with ARC
29th February 2012 in Programming

If you are struggling to make CEPubnub work with ARC then below is how I solved it for myself.
1. Remove all mentions of release and autorelease from all CEPubnub files. I had to remove quite a few but it was very straightforward.
2. Next step is to rename all methods that call init on object self to start with "init". There will be a couple in CEPubnub.h /.m and CEPubnubRequest.h /.m. Don't forget to find where these methods are called and update method names accordingly. For example, change the following:
-(CEPubnub*) publishKey: (NSString*) pub_key subscribeKey: (NSString*) sub_key secretKey: (NSString*) sec_key sslOn: (BOOL) ssl_on origin: (NSString*) origin;
to
-(CEPubnub*) initWithPublishKey: (NSString*) pub_key subscribeKey: (NSString*) sub_key secretKey: (NSString*) sec_key sslOn: (BOOL) ssl_on origin: (NSString*) origin;
3. If you then run Analyser it will say there is a potential memory leak in urlencode method. I had to assign the result of CFURLCreateStringByAddingPercentEscapes to a new NSString object to get rid of the warning.
CFStringRef stringRef = CFURLCreateStringByAddingPercentEscapes(NULL, (__bridge CFStringRef)(string), NULL, (CFStringRef)@"!*'();:@&=+$,/?%#[]", kCFStringEncodingUTF8);
NSString *newString = [NSString stringWithFormat:@"%@", (__bridge NSString *)stringRef];
return newString;
I have uploaded my final code here.
