I created simple NSObject class to take some values. My application has not come any error when I run and build the application. I tried it lot of time to run program. I am beginner of the objective c.
Code ::
#import "FibonachiNo.h"
@implementation FibonachiNo
- (NSArray *) fibonacci:(NSInteger) n {
NSMutableArray *fib = [NSMutableArray array];
int a = 0;
int b = 1;
int sum;
int i;
for (i=0; i<=n; i++)
{
[fib addObject:[NSNumber numberWithInt:a]];
sum = a + b;
a = b;
b = sum;
}
return (NSArray *) fib;
}
- (NSInteger) factorial:(NSInteger) n {
if ( n <= 1 )
return 1;
else
return n * [self factorial:( n-1 )];
}
@end
My application header class
#import <UIKit/UIKit.h>
#import "FibonachiNo.h"
@interface ViewController : UIViewController
@property FibonachiNo *myFibonachi;
@end
Calling Method to NSObject Class ::
NSLog(@"fibonacci for 10 = %@", [myFibonachi fibonacci:10]);
NSLog(@"10! = %d",[myFibonachi factorial:10]);
Is it any wrong in this calling method ?
first alloc init your Array
Calling Method to NSObject Class ::
in
ViewDidLoaduse following.if still you facing any issue , then show your NSLog output here.