I am learning Objective-C. This post contains some Objective-C trivia which I picked up over the last few weeks.

Concatenating Strings

In Objective-C, NSString class represents strings. Concatenating two strings is not easy. To ease the pain, there is a NSMutableString class. It has an append method. The StackOverflow post summarises the different methods available to concatenate strings. Usually, we have problems with XML strings which run into multiple lines.…

Read More

Playing audio in an iOS app consists of two steps:

  1. Creating an Audio session using AVAudioSession class.
  2. Playing the audio using Audio player using AVAudioPlayer class.

AVAudioSession

We want to play audio in apps even though the background music is running. For that, create a shared audio session. The code for initializing a shared session is shown below.

-(void)initAudio
{
    NSError *error;
    
    [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:nil];
    BOOL success = [[AVAudioSession sharedInstance] setActive: YES error: &error];
    if(!success)
Read More

SQLite database has native support in iOS. The post provides a simple helper class that you can use to retrieve data and perform update operations on the data.

The helper class uses the libsqlite3.dylib library. Link the XCode project with the library. Create a helper class in Objective-C: DbHelper.

Header file

Define the DbHelper class with a static method (getInstance) to create a singleton instance.…

Read More