Skip to content

Posts from the ‘Objective C Examples’ Category


Example: Implement a Stack of Strings in Objective C

In the next example it is shown how to implement a class of strings using Objective C language. We will first read a text from a file and we will store it into a NSString. Then we will split the string into words (by spaces) and we will store the words in a NSArray.

Then we will iterate through that NSArray will add elements to our stack only if element not equal with “-”. If element is equal with “-” character then we will pop element from top of stack. We will display elements that we remove (using pop()) from our stack.

We will also use another class called Element for elements of our stack.

Element Class

Class’s Element header file (Element.h):

#import <foundation /Foundation.h>
@interface Element : NSObject
    @property NSString *value;
    @property Element *next;

Read more »