Singleton Method, Using singleton method concatenate two String

Singleton Method, NSString

ViewController.h

#import “SingletonClass.h”

ViewController.m

#import “ViewController.h”

@interface ViewController ()

@end

@implementation ViewController

– (void)viewDidLoad {

    [super viewDidLoad];

    

    NSString *stringFirst = @”First”;

    NSString *stringSecond = @”Second”;

    NSString *stringConcatenated;

    stringConcatenated = [[SingletonClass sharedSingletonClass]twoStringConcatenationFirstString:stringFirst SeconString:stringSecond];

    NSLog(@”%@”,stringConcatenated);

    

    

    // Do any additional setup after loading the view, typically from a nib.

}

– (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

@end

SingletonClass.h

+ (SingletonClass *)sharedSingletonClass;

– (NSString *)twoStringConcatenationFirstString:(NSString *)aFirstString SeconString:(NSString *)aSecondString;

SingletonClass.m

+ (SingletonClass *)sharedSingletonClass

{

    static SingletonClass *sharedInstance = nil;

    static dispatch_once_t oncePredicate;

    dispatch_once(&oncePredicate, ^

                  {

                      sharedInstance = [[self alloc]init];

                  });

    return sharedInstance;

}

– (NSString *)twoStringConcatenationFirstString:(NSString *)aFirstString SeconString:(NSString *)aSecondString

{

    NSString *strinfConcatenation;

    strinfConcatenation = [aFirstString stringByAppendingString:aSecondString];

    return strinfConcatenation;

}

Click here to download Singleton Method, Using singleton method concatenate two String Project

Leave a comment