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

Real world examples of @optional protocol methods

I’m learning Objective-C at the moment and have come across optional methods in Protocols. My background is C# and can see a Protocol as something similar to a C# Interface. Where a C# Interface represents a contract, by advertising an Interface you are saying that you will implement the methods defined. With this in mind […]

CFNetwork / NSURLConnection leak

Running instruments on the device, I intermittently incur a memory leak of exactly 3.5 KB in CFNetwork, the responsible frame being “HostLookup_Master::HostLookup….” I have read a number of questions re this issue and have separately tried the following to fix the leak: Included the following in applicationDidFinishLaunching: NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil]; […]

Objective-C error: initializer element is not constant

Why does the compiler give me the following error message on the provided code: “initializer element is not constant”. The corresponding C/C++ code compiles perfectly under gcc. #import <Foundation/Foundation.h> const float a = 1; const float b = a + a; // <- error here int main (int argc, const char * argv[]) { NSAutoreleasePool […]

iOS 8.3 'UIView-Encapsulated-Layout-Width' in Custom Keyboard

I have implemented a custom keyboard. It works fine on a device which runs iOS 8.2. However, when I run the same code on a device with iOS 8.3 I get the following warnings and the height of the keyboard is not set properly: Probably at least one of the constraints in the following list […]

Localization: application crashes when language is changed in simulator

In order to localize my application, I created Localizable.strings for three languages. I didn’t need to localize any nib files since I’m not using any in my project. No images were localized, only the strings. In the code, I read the strings using NSLocalizedStrings(@”key”, @”comment”). The Localized.strings files use UTF-16 format. The strings look like […]

Pesky new lines and whitespace in XML reader class

I’m using a class written by a blogger ( that takes an XML string and spits out a NSDictionary. It’s beautiful…works perfectly, except I end up with a weird configuration of newlines and white space at the beginning of many element values. I haven’t been able to figure out why. I’m posting the class here […]

How to determine if an NSString is latin based?

I’m trying to determine if a string is latin based or Japanese. I’ve tried something like the following but it returns YES for Japanese strings as well: NSCharacterSet *alphaSet = [NSCharacterSet alphanumericCharacterSet]; BOOL isAlpha = [[myStr stringByTrimmingCharactersInSet:alphaSet] isEqualToString:@””]; A string might be a word like “café” or something like “カフェ” or “喫茶店”.

how to dismiss action sheet

i used this code to show uipicker in uiactionsheet but when i click close button i want to remove action sheet from view. so what should be the code for removing actionSheet form view. – (BOOL)textFieldShouldBeginEditing:(UITextField *)textField { UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil]; [actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent]; CGRect pickerFrame = CGRectMake(0, 40, […]

Add ivars in @implementation

For good encapsulation, decent Objective-C programmers put their private ivars in a private extension declared in the main implementation file, like this: // MyClass.m @interface MyClass () { float value; } @end @implementation MyClass @end But recently, I found a simpler way to hide private ivars: ivars can be declared in a {} block following […]

why is textFieldDidEndEditing: not being called?

I’m playing with writing my first iphone app; SDK 3.0. I’ve got a UITextField, and when text gets entered into that, I want to obtain the doubleValue from the text field and perform some computations and display them in a UITableView. The delegate for the UITextField adopts the UITextFieldDelegate protocol, and implements both textFieldShouldReturn: and […]