2

I started studying Objective C using Xcode 6. so i am new to this. i follow some tutorial on Web and trying some examples. i am using mac os x 10.9. i did not get error so far like this. i have tried many objective c codes. here i attached my coding.

main.m

#import <Foundation/Foundation.h>
#import "CarUtilities.h"

int main(int argc, const char * argv[]) {
@autoreleasepool {

NSDictionary *makesAndModels = @{
 @"Ford":@[@"Explorer",@"F-150"],
 @"Honda":@[@"Accord",@"Civic",@"Pilot"],
 @"Nissan":@[@"370Z",@"Altima",@"Versa"],
 @"Porsche":@[@"911 Trubo",@"Boxter",@"Cayman S"]

 };

 NSString *randomCar = CUGetRandomMakeAndModel(makesAndModels);
 NSLog(@"Selected a %@",randomCar);
}
return 0;
}


//CarUtilities.m

#import #import "CarUtilities.h"

//private function declaration

static id getRandomItemFromArray(NSArray *anArray);

//public funtion implementation

NSString *CUGetRandomMake(NSArray *makes){

return getRandomItemFromArray(makes);
}

NSString *CUGetRandomModel(NSArray *models){
return getRandomItemFromArray(models);
}

NSString *CUGetRandomMakeAndModel(NSDictionary *makesAndModels){

NSArray *makes = [makesAndModels allKeys];
NSString *randomMake = CUGetRandomeMake(makes);
NSArray *models = makesAndModels[randomMake];
NSString *randomModel = CUGetRandomeModel(models);

return [randomMake stringByAppendingFormat:@" %@",randomModel];

}

//private function implementation

static id getRandomItemFromArray(NSArray *anArry){

int maximum = (int) [anArry count];
int randomIndex = arc4random_uniform(maximum);

return anArry[randomIndex];

}
CarUtilities.h

#import <Foundation/Foundation.h>

NSString *CUGetRandomeMake(NSArray *makes);
NSString *CUGetRandomeModel(NSArray *models);
NSString *CUGetRandomMakeAndModel(NSDictionary *makesAndModels);

when i try to run this code i got following errors.

Ld /Users/samudrjkumara/Library/Developer/Xcode/DerivedData/CarUtilities-govahlvyjxsayfaxlqircwemwocg/Build/Products/Debug/CarUtilities normal x86_64 cd /ObjectiveC/CarUtilities export MACOSX_DEPLOYMENT_TARGET=10.9 /Applications/Xcode6-Beta6.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch x86_64 -isysroot /Applications/Xcode6-Beta6.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk -L/Users/samudrjkumara/Library/Developer/Xcode/DerivedData/CarUtilities-govahlvyjxsayfaxlqircwemwocg/Build/Products/Debug -F/Users/samudrjkumara/Library/Developer/Xcode/DerivedData/CarUtilities-govahlvyjxsayfaxlqircwemwocg/Build/Products/Debug -filelist /Users/samudrjkumara/Library/Developer/Xcode/DerivedData/CarUtilities-govahlvyjxsayfaxlqircwemwocg/Build/Intermediates/CarUtilities.build/Debug/CarUtilities.build/Objects-normal/x86_64/CarUtilities.LinkFileList -mmacosx-version-min=10.9 -fobjc-arc -fobjc-link-runtime -Xlinker -dependency_info -Xlinker /Users/samudrjkumara/Library/Developer/Xcode/DerivedData/CarUtilities-govahlvyjxsayfaxlqircwemwocg/Build/Intermediates/CarUtilities.build/Debug/CarUtilities.build/Objects-normal/x86_64/CarUtilities_dependency_info.dat -o /Users/samudrjkumara/Library/Developer/Xcode/DerivedData/CarUtilities-govahlvyjxsayfaxlqircwemwocg/Build/Products/Debug/CarUtilities

Undefined symbols for architecture x86_64: "_CUGetRandomeMake", referenced from: _CUGetRandomMakeAndModel in CarUtilities.o "_CUGetRandomeModel", referenced from: _CUGetRandomMakeAndModel in CarUtilities.o`` ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

where i have gone wrong. please need a help on this as i am new to Xcode and Objective C..

samudra
  • 21
  • 3

2 Answers2

2

I think the issue is related to Project build settings.

In your target build setting do check if under architecture subview:

"Architecture" includes all supported architectures. (including arm64)

"Build active architecture only": NO.

Not enough repo to add image. so please check the image at this post:

Xcode 5 and iOS 7: Architecture and Valid architectures

Community
  • 1
  • 1
bllakjakk
  • 5,045
  • 1
  • 18
  • 28
0

Typos:

NSString *CUGetRandomMake(NSArray *makes){
    return getRandomItemFromArray(makes);
}
...

NSString *randomMake = CUGetRandomeMake(makes);
//                                ^

same for CUGetRandomModel().

trojanfoe
  • 120,358
  • 21
  • 212
  • 242