我創建了簡單的NSObject類來獲取一些值。當我運行並構建應用程序時,我的應用程序沒有出現任何錯誤。我嘗試了很多時間來運行程序。我是目標c的初學者。它不是調用NSObject類
代碼::
#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
我的應用程序頭類
#import <UIKit/UIKit.h>
#import "FibonachiNo.h"
@interface ViewController : UIViewController
@property FibonachiNo *myFibonachi;
@end
調用方法NSObject類::
NSLog(@"fibonacci for 10 = %@", [myFibonachi fibonacci:10]);
NSLog(@"10! = %d",[myFibonachi factorial:10]);
這是任何錯誤在此調用的方法?
現在它運行正常。我有另一個問題。我在靜態類庫中創建了這個類。並且我在Mach-O Type中更改爲Static Library,並將abc.a和abc.h文件添加到我的新應用程序中。然後顯示波紋錯誤檢查相關性 應用程序目標的'staticlib'的MACH_O_TYPE值無效。: – Himesh
使用TextEdit打開YourProjectName.xcodeproj文件夾中的project.pbxproj文件,搜索productType並將其值從「com.apple.product動態「到」com.apple.product-static「 –
也可以試試這個答案:http://stackoverflow.com/questions/10255044/xcode4-create-static-library-from-existing-project –