Suppose I am creating a static library and in which I have two NSObject
Classes Named as ClassA
and ClassB
, User can Access ClassA.h
to execute the functions inside library
. Now I've some functions defined into ClassB
and I want user to execute these functions from their ViewController
as per their need but I don't want to give ClassB.h
to user so how user can access it using ClassA
.
ClassA.h
#import <Foundation/Foundation.h>
@interface ClassA : NSObject
+ (void) method_1;
+ (void) method_2;
+ (void) method_3;
// Tried to pass Instance of ClassB to user ViewController
+ (id) getClassBInstanceObject;
@end
ClassA.m
#import "ClassA.h"
#import "ClassB.h"
@implementation ClassA
+ (void) method_1 {
//Some Stuffs Done Here !!
}
+ (void) method_2 {
//Some Stuffs Done Here !!
}
+ (void) method_3 {
//Some Stuffs Done Here !!
}
// Tried to pass Instance of ClassB to user ViewController
+ (id) getClassBInstanceObject {
id objB = [ClassB sharedInstance];
return objB;
}
@end
ClassB.h
#import <Foundation/Foundation.h>
@interface ClassB : NSObject
+ (id)sharedInstance;
-(void)Test_ClassB_function;
@end
ClassB.m
#import "ClassB.h"
@implementation ClassB
+ (id)sharedInstance {
static ClassB *instance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
});
return instance;
}
-(void)Test_ClassB_function {
NSLog(@"this is the method called from ClassB !!!!");
}
@end
Now User Have a Static library FAT (lib.a
) file and ClassA.h
File Which He'll include in his project and then he can import ClassA.h
into his ViewController
Class to execute library functions and user wants to execute Test_ClassB_function
using ClassA
.
ViewController.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@end
ViewController.m
#import "ViewController.h"
#import "ClassA.h"
@interface ViewController ()
@end
@implementation ViewController
override func viewDidLoad() {
super.viewDidLoad()
[ClassA method_1];
[ClassA method_2];
[ClassA method_3];
}
- (IBAction)Button1:(id)sender {
id class_B_Object = [ClassA getClassBInstanceObject];
[class_B_Object Test_ClassB_function];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
Can anybody tell me how to achieve this goal in Objective-C.