William Boles
  • William Boles
  • Home
  • About
  • Favourites
  • Mind Maps

The only time you should release self

#memory management

The only time you should call [self release] is if during the initialization of your object an error occurs that causes you to return nil. - (id) initWithData:(NSData *)userData error:(NSError **)error { if(!userData){ if(error){ *error = //set up err

18 Oct 2011

Passing with `&`

#memory management

In Objective-C you pass by reference by placing the "&" symbol (minus the quote marks) in-front of the variable name i.e. &var instead of just var . This informs the compiler to pass the memory address of the variable rather than its value. This is useful when you want to update th

04 Oct 2011 • 1 min read

Hide the tab bar on certain view controllers

#ui

I found it surprisingly tricky to track down how to hide the tabbar on certain view controllers without ending up with a white area where the tabbar would have been. What you need to do is set the tabbar hidden property on the UIViewController you are about to push rather than on the UITabbarControl

30 Sep 2011 • 1 min read

Saving and retrieving data from NSUserDefaults

#userdefaults #persistence

NSUserDefaults is a great way to save small amounts of data that you want to persistent across application "sessions" (especially where a database would be overkill). Saving data to NSUserDefaults: [[NSUserDefaults standardUserDefaults] setBool:YES forKey:KEY_TO_IDENTIFY_INFORMATIO

26 Sep 2011 • 1 min read

Clearing the delegate when dealloc-ing

#memory management

Often when creating a delegate relationship between two objects: A (delegate) and B (delegating object), you can sometimes run into the scenario where the delegating object outlives the delegate. Meaning that if we don't inform B that A is dealloc'ed we could end up with a fatal app crash. T

25 Sep 2011 • 1 min read

Sorting with sort descriptors

#sorting

Sorting an array of NSNumber elements in Objective-C is fairly straight forward: NSArray *unsortedArray = @[@(9), @(5), @(1), @(2), @(4)]; NSArray *sortedArray = [unsortedArray sortedArrayUsingSelector:@selector(compare:)]; NSLog(@"sortedArray: %@", sortedArray); But what happens if we

20 Sep 2011 • 2 min read

Loading bundle images in a UIWebView

#ui

I ran into this problem were I could not get a bundle image to appear in a UIWebView. It turns out that in order to enable this functionality you need to tell the webview where to look for these images, in the below example we tell it to use the main bundle: NSString *bundlePath = [[NSBundle mainB

13 Sep 2011 • 1 min read

Consuming a web feed

#networking

Here we're going to go through an implementation of parsing xml into a model class. This comprises of: 1. A xml message 2. A service call layer 3. A parser - in two parts 4. A factory XML Message <?xml version="1.0" encoding="utf-8" ?> <getUserDetailsRe

28 Aug 2011 • 9 min read

Interview puzzles in Objective-C

#interviewing

It seems to be difficult (in Objective-C) to find a coherent post about those tricky puzzles that sometimes crop up so I thought I'd post one 😀. String Puzzles Reverse a string - (NSString *)reverseString:(NSString *)originalString { int lengthOfString = [originalString length];

24 Jul 2011 • 3 min read

Keeping things @class-y

#xcode #errors

I run into the following error from time to time" Expected specifier-qualifier-list before `XYZ` and everytime it takes me a while to work out what caused it. Making sure I don't forget 🙃 It's caused by introducing an import circular dependance where class abc imports class xy

29 Jun 2011 • 1 min read

Polling with NSOperation

#concurrency

Recently I was writing an application that analysed audio input and updated an audio visualiser on screen. Running everything in the main thread just ground UI responsiveness down so I decided to spin off the audio capture into a separate thread. My first thoughts where to use NSOperationInvocation

16 May 2011 • 1 min read

Limiting input

#ui

A common scenario in iOS development is to create a textfield that will only allow a certain number of characters to be entered. We can implement this constraint by: - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { BO

28 Apr 2011

Setting the return key

#ui

When I wanted to add a Done/Next key to the keyboard I found it surprisingly hard to find out how this was possible. After much research I stumbled upon the solutions that you go through the textfield to set the button. Done - (void)textFieldDidBeginEditing:(UITextField *)textField { text

25 Apr 2011 • 1 min read

Add a background image to the navigation bar

#ui

Recently I was asked to add a pale (off-white) color as the background color of a navigation bar, which I thought would just be a case of updating the tintColor property . However when I did this instead of getting the gradient effect that we were after all I ended up with was a solid off-white colo

28 Mar 2011 • 1 min read
Page 5 of 7

No results for your search, please try with something else.

William Boles © 2025

GitHub | Mastodon | Bluesky | LinkedIn | RSS

JavaScript license information