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

Detecting iPhone/iPod Touch Accessories

Is it possible to detect if the iPod Touch/iPhone has any headphones or other accessories connected to it? I’m building an app that requires a microphone, and need to know if the “iSomething” has one connected or not, either via the dock connection, or using the headphone port, such as with the inline headphone/microphone accessory […]

Obtaining an NSDecimalNumber from a locale specific string?

I have some string s that is locale specific (eg, 0.01 or 0,01). I want to convert this string to a NSDecimalNumber. From the examples I’ve seen thus far on the interwebs, this is accomplished by using an NSNumberFormatter a la: NSString *s = @”0.07″; NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init]; [formatter setFormatterBehavior:NSNumberFormatterBehavior10_4]; [formatter setGeneratesDecimalNumbers:YES]; […]

Objective-C dot notation with class methods?

Note, I’m specifically referring to the fact that dot notation is being used with class methods, not instance methods. Out of curiosity, I wanted to see what would happen if I tried to use Objective-C dot notation syntax with a class method. My experiment was as follows: #import <Foundation/Foundation.h> static int _value = 8; @interface […]

NSDateFormatter dateFromString returns nil

Here is my code : NSString *_date = @”Tue, 23 Nov 2010 16:14:14 +0000″; NSDateFormatter *parser = [[NSDateFormatter alloc] init]; [parser setDateFormat:@”EEE, dd MMM yyyy HH:mm:ss ‘+0000′”]; [parser setTimeZone:[NSTimeZone timeZoneWithName:@”UTC”]]; NSDate *date = [parser dateFromString:_date]; This doesn’t run : ‘date’ is set to ‘nil’. I tried with [parser setDateFormat:@”EEE, dd MMM yyyy HH:mm:ss ZZZ”]; With […]

UITextView inside UIScrollView with AutoLayout

I am trying to place UITextView inside UIScrollView with AutoLayout with no luck. What I have tried is, I placed UIScrollView inside the main view in Storyboard I placed UITextView inside UIScrollView in Storyboard and disabled Scrolling Enabled I set constraints (leading, trailing, top, bottom) on UIScrollView I set constraints (top, leading, trailing, height) on […]

Compiler error “expected method not found” when using subscript on NSArray

I wrote this simple code to try out the new Objective-C literal syntax for NSArrays: NSArray *array = @[@”foo”]; NSLog(@”%@”, array[0]); The first line works fine, but the subscripting results in an error: Expected method to read array element not found on object of type ‘NSArray *’ Just wondering if I have done something wrong, […]

What's the difference between and nil?

Here’s a context where I have seen that: NSMutableArray *controllers = [[NSMutableArray alloc] init]; for (unsigned i = 0; i < kNumberOfPages; i++) { [controllers addObject:[NSNull null]]; } why not nil in that place?

Reference from UITableViewCell to parent UITableView?

Is there any way to access the owning UITableView from within a UITableViewCell?

Category usage in Objective-C

I’m seeing some code I’ve inherited that looks like the following: @interface SomeClass (private) This is within SomeClass.m, the implementation file. There is an accompanying header file which doesn’t suggest that the class is using a category. Is (private) in this case just a poor name given to a category for SomeClass? And I’m assuming […]

Can the new Clang Objective-C literals be redirected to custom classes?

Although the overloading of @ begins to tread on dangerous territory, I love the addition of the new Objective-C literals in Clang 3.1. Unfortunately the new literals are of limited use to me. Except for instances where code needs to interface with AppKit, I’ve mostly dropped the use of Foundation classes in favor of my […]