iOS Development is easy with XCode, Swift3, UITableView, cocatouch, let's build iPhone, iPad and Macbook Applications.

“f” after number/float in Objective-C/C

I cannot find this in the Apple docs so: what does the “f” after the numbers here indicate? Is this from C or Objective-C? Is there any difference in not adding this to a constant number? CGRect frame = CGRectMake(0.0f, 0.0f, 320.0f, 50.0f); Can you explain why I wouldn’t just write: CGRect frame = CGRectMake(0, […]

NSMutableString as retain/copy

I have aa number of NSMutableString’s in my app (almost 10-11); all defined as ivar/property @property (nonatomic, retain) NSMutableString *str1; I read somewhere that it is better to use “copy” for strings. Is that true? If yes, can I just replace retain to copy in my app and remove the release in dealloc ? Do […]

How to add commas to number every 3 digits in Objective C?

If I have a number int aNum = 2000000 how do I format this so that I can display it as the NSString 2,000,000?

Create objective-c class instance by name?

Is it possible to create an instance of a class by name? Something like: NSString* className = @”Car”; id* p = [Magic createClassByName:className]; [p turnOnEngine]; I don’t know if this is possible in objective-c but seems like it would be,

Change position of UIBarButtonItem in UINavigationBar

How can I change the position of a UIBarButtonItem in a UINavigationBar? I would like my button to be about 5px higher than its normal position.

How do I create a NSTimer on a background thread?

I have a task that needs to be performed every 1 second. Currently I have an NSTimer firing repeatedly every 1 sec. How do I have the timer fire in a background thread (non UI-thread)? I could have the NSTimer fire on the main thread then use NSBlockOperation to dispatch a background thread, but I’m […]

interaction beyond bounds of uiview

Is it possible for a UIButton (or any other control for that matter) to receive touch events when the UIButton’s frame lies outside of it’s parent’s frame? Cause when I try this, my UIButton doesn’t seem to be able to receive any events. How do I work around this?

Creating a selector from a method name with parameters

I have a code sample that gets a SEL from the current object, SEL callback = @selector(mymethod:parameter2); And I have a method like -(void)mymethod:(id)v1 parameter2;(NSString*)v2 { } Now I need to move mymethod to another object, say myDelegate. I have tried: SEL callback = @selector(myDelegate, mymethod:parameter2); but it won’t compile.

NSString to CFStringRef and CFStringRef to NSString in ARC?

I am trying to understand the correct way of getting an NSString from a CFStringRef in ARC? Same for going the opposite direction, CFStringRef to NSString in ARC? What is the correct way to do this without creating memory leaks?

Convert objective-c typedef to its string equivalent

Assuming that I have a typedef declared in my .h file as such: typedef enum { JSON, XML, Atom, RSS } FormatType; I would like to build a function that converts the numeric value of the typedef to a string. For example, if the message [self toString:JSON] was sent; it would return ‘JSON’. The function […]