# PowenKo,iOS Tutorial 110, Create Universal Static Libraries

September 8, 2011   ·   0 Comments

# Create Universal Static Libraries

## Step1:

FILE\NEW Project\Framework & Library\cocoa touch static library

## Step 2: Code your static library

```#import <Foundation/Foundation.h>

@interface Tutorial_Lib_staticLib : NSObject{

}
- (NSArray *) fibonacci:(NSInteger) n;
- (NSInteger) factorial:(NSInteger) n;

@end
```

```
#import "Tutorial_Lib_staticLib.h"

@implementation Tutorial_Lib_staticLib

- (id)init
{
self = [super init];
if (self) {
// Initialization code here.
}

return self;
}

- (NSArray *) fibonacci:(NSInteger) n {

NSMutableArray *fib = [NSMutableArray array];

int a = 0;
int b = 1;
int sum;
int i;

for (i=0;i < n;i++)
{
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

```

### build

copy the your
xxx.a
xxx.h

to share your friends and coworkers.

### sample code:

Tutorial_Lib_staticLib

### reference:

http://www.cocoanetics.com/2010/04/universal-static-libraries/

share

By

iOS Tutorial9