2012-03-27 28 views
6

Parece que estoy teniendo un error al intentar compilar y parece estar apuntando directamente a dos archivos ... Controlador de menú y Primer controlador de vista superior. Creo que tiene algo que ver con mis importaciones, ya que cada una de ellas está importando la otra, sin embargo, el error hace referencia a mi objeto Building, que apenas se usa en él. Además, con el error de clang, ¿cómo uso -v para ver la invocación?iOS - Error del enlazador, símbolo duplicado

Error:

ld: duplicate symbol _OBJC_CLASS_$_Building in /Users/alexmuller/Library/Developer/Xcode/DerivedData/ECSlidingViewController-gjxwxiwumgohyehiawnlamggzmop/Build/Intermediates/ECSlidingViewController.build/Debug-iphonesimulator/ECSlidingViewController.build/Objects-normal/i386/FirstTopViewController.o and /Users/alexmuller/Library/Developer/Xcode/DerivedData/ECSlidingViewController-gjxwxiwumgohyehiawnlamggzmop/Build/Intermediates/ECSlidingViewController.build/Debug-iphonesimulator/ECSlidingViewController.build/Objects-normal/i386/MenuViewController.o for architecture i386 
clang: error: linker command failed with exit code 1 (use -v to see invocation) 

FirstTopViewController.h

#import <UIKit/UIKit.h> 
#import <QuartzCore/QuartzCore.h> 
#import "ECSlidingViewController.h" 
#import "MenuViewController.h" 
#import "TimesViewController.h" 
#import "BuildingViewController.h" 
#import "BuildingAnnotation.h" 
#import <MapKit/MapKit.h> 

@class BuildingViewController; 

@interface FirstTopViewController : UIViewController <MKMapViewDelegate> { 
    IBOutlet MKMapView *_map; 
    BuildingViewController *buildingVC; 
    BuildingAnnotation *buildAnnotation; 
} 

@property (nonatomic, strong) MKMapView *map; 

- (IBAction)revealMenu:(id)sender; 
- (IBAction)revealTimes:(id)sender; 
- (void)loadBuilding:(Building *)building; 

@end 

FirstTopViewController.m

#import "FirstTopViewController.h" 

@implementation FirstTopViewController 

@synthesize map = _map; 

- (void)viewDidLoad { 

    buildingVC = (BuildingViewController *)[self.storyboard instantiateViewControllerWithIdentifier:@"BuildingList"]; 
    [super viewDidLoad]; 
} 

- (void)viewWillAppear:(BOOL)animated 
{ 
    [(UIView *)[self.view viewWithTag:10] setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"RedWithNoise"]]]; 
    [super viewWillAppear:animated]; 
    [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"toolbar"] forBarMetrics:UIBarMetricsDefault]; 
    [[UINavigationBar appearance] setTitleTextAttributes: 
    [NSDictionary dictionaryWithObjectsAndKeys: 
     [UIColor colorWithRed:204.0/255.0 green:204.0/255.0 blue:102.0/255.0 alpha:1.0], 
     UITextAttributeTextColor, 
     [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8], 
     UITextAttributeTextShadowColor, 
     [NSValue valueWithUIOffset:UIOffsetMake(0, -1)], 
     UITextAttributeTextShadowOffset, 
     [UIFont fontWithName:@"AGaramondPro-Regular" size:23.0], 
     UITextAttributeFont, 
     nil]]; 
    self.view.layer.shadowOffset = CGSizeZero; 
    self.view.layer.shadowOpacity = 0.75f; 
    self.view.layer.shadowRadius = 10.0f; 
    self.view.layer.shadowColor = [UIColor blackColor].CGColor; 
    self.view.layer.shadowPath = [UIBezierPath bezierPathWithRect:self.view.layer.bounds].CGPath; 
    self.view.clipsToBounds = NO; 

    MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(CLLocationCoordinate2DMake(30.451667, -84.268533), 16090.344, 16090.344); 
    viewRegion = [_map regionThatFits:viewRegion]; 
    [_map setRegion:viewRegion animated:YES]; 

    if (![self.slidingViewController.underLeftViewController isKindOfClass:[MenuViewController class]]) { 
     self.slidingViewController.underLeftViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"Menu"]; 
    } 

    if (![self.slidingViewController.underRightViewController isKindOfClass:[TimesViewController class]]) { 
     self.slidingViewController.underRightViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"Times"]; 
    } 

    [self.view addGestureRecognizer:self.slidingViewController.panGesture]; 


} 

- (void)loadBuilding:(Building *)building { 
    if (buildingVC.buildingSelected) { 
     if (buildAnnotation != nil) { 
      [_map removeAnnotation:buildAnnotation]; 
     } 
     NSLog(@"%@", building.getName); 
     buildAnnotation = [[BuildingAnnotation alloc] initWithCoordinate:building.getLocation.coordinate withName:building.getName withAddress:building.getAddress]; 
     [_map setCenterCoordinate:buildAnnotation.coordinate animated:YES]; 
     [_map addAnnotation:buildAnnotation]; 
    } 
} 

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 
{ 
    self.view.layer.shadowPath = nil; 
    self.view.layer.shouldRasterize = YES; 
} 

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation 
{ 
    self.view.layer.shadowPath = [UIBezierPath bezierPathWithRect:self.view.layer.bounds].CGPath; 
    self.view.layer.shouldRasterize = NO; 
} 

- (IBAction)revealMenu:(id)sender 
{ 
    [self.slidingViewController anchorTopViewTo:ECRight]; 
} 

- (IBAction)revealTimes:(id)sender { 
    [self.slidingViewController anchorTopViewTo:ECLeft]; 
} 

@end 

MenuViewController.h

#import <UIKit/UIKit.h> 
#import "ECSlidingViewController.h" 
#import "FirstTopViewController.h" 
#import "TimesViewController.h" 

@interface MenuViewController : UIViewController <UITableViewDataSource, UITabBarControllerDelegate> { 
    NSIndexPath *selectedIndex; 
} 

@end 

MenuViewController.m

#import "MenuViewController.h" 

typedef enum { 
    ENGINEERING, 
    GARNET, 
    GOLD, 
    HERITAGE, 
    NIGHT, 
    OSCEOLA, 
    RENEGADE, 
    TOMAHAWK 
} RouteName; 


@interface MenuViewController() 
@property (nonatomic, strong) NSArray *menuItems; 
@property (nonatomic, strong) NSArray *optionItems; 
@property (nonatomic, strong) NSArray *arrayItems; 

- (UIImage *)determineActiveRoute:(RouteName)route; 
@end 

@implementation MenuViewController 
@synthesize menuItems, optionItems, arrayItems; 

- (void)awakeFromNib 
{ 

    self.menuItems = [NSArray arrayWithObjects:@"Engineering", @"Garnet", @"Gold", @"Heritage Grove", @"Night Nole", @"Osceola", @"Renegade", @"Tomahawk", nil]; 
    self.optionItems = [NSArray arrayWithObjects:@"Buildings", @"Directions", nil]; 
    self.arrayItems = [NSArray arrayWithObjects:self.menuItems, self.optionItems, nil]; 
} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    [self.slidingViewController setAnchorRightRevealAmount:200.0f]; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)sectionIndex 
{ 
    return [[self.arrayItems objectAtIndex:sectionIndex] count]; 
} 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    return [self.arrayItems count]; 
} 

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 
    return 35; 
} 

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { 
    UIView *sectionView = [[UIView alloc] init]; 
    [sectionView sizeToFit]; 
    sectionView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"navCellDivider"]]; 
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(5, 5, 100, 20)]; 
    label.textColor = [UIColor grayColor]; 
    label.backgroundColor = [UIColor clearColor]; 
    label.font = [UIFont fontWithName:@"AGaramondPro-Regular" size:12.0]; 
    if(section == 0) 
     label.text = @"BUS ROUTES"; 
    else 
     label.text = @"OTHER OPTIONS"; 
    [sectionView addSubview:label]; 
    return sectionView; 
} 

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { 
    return 20; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UILabel *label; 
    UIImageView *imageView; 
    NSString *cellIdentifier = @"MenuItemCell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; 

    } 
    UIView *selectedView = [[UIView alloc] initWithFrame:cell.frame]; 
    selectedView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"navCellBackgroundSelected"]]; 
    cell.selectedBackgroundView = selectedView; 
    cell.contentView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"navCellBackground"]]; 
    label = (UILabel *)[cell.contentView viewWithTag:100]; 
    label.font = [UIFont fontWithName:@"AGaramondPro-Regular" size:15.0]; 
    label.text = [[self.arrayItems objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]; 
    imageView = (UIImageView *)[cell.contentView viewWithTag:101]; 
    if (indexPath.section == 0) { 
     [imageView setImage:[self determineActiveRoute:indexPath.row]]; 
    } else { 
     if (indexPath.row == 0) { 
      [imageView setImage:[UIImage imageNamed:@"building"]]; 
     } else { 
      [imageView setImage:[UIImage imageNamed:@"60-signpost"]]; 
     } 
    } 

    return cell; 
} 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    /* Type cast view as a First Top to make it easier to read. Do switch to select correct route, 
     then modify map afterwards to load up correct route. 
    TimesViewController can be set to the corresponding times when selected 
    */ 
    FirstTopViewController *mapViewController = (FirstTopViewController *)self.slidingViewController.topViewController; 
    TimesViewController *timesViewController = (TimesViewController *)self.slidingViewController.underRightViewController; 

    if (indexPath.section == 0) { 
     selectedIndex = indexPath; 
     switch (indexPath.row) { 
      case ENGINEERING: 
       NSLog(@"Engineering Selected\n"); 
       timesViewController.times.text = @"Engineering"; 
       break; 
      case GARNET: 
       NSLog(@"Garnet Selected\n"); 
       timesViewController.times.text = @"Garnet"; 
       break; 
      case GOLD: 
       NSLog(@"Gold Selected\n"); 
       timesViewController.times.text = @"Gold"; 
       break; 
      case HERITAGE: 
       NSLog(@"Heritage Grove Selected\n"); 
       timesViewController.times.text = @"Heritage Grove"; 
       break; 
      case NIGHT: 
       NSLog(@"Night Nole Selected\n"); 
       timesViewController.times.text = @"Night Nole"; 
       break; 
      case OSCEOLA: 
       NSLog(@"Osceola Selected\n"); 
       timesViewController.times.text = @"Osceola"; 
       break; 
      case RENEGADE: 
       NSLog(@"Renegade Selected\n"); 
       timesViewController.times.text = @"Renegade"; 
       break; 
      case TOMAHAWK: 
       NSLog(@"Tomahawk Selected\n"); 
       timesViewController.times.text = @"Tomahawk"; 
       break; 
      default: 
       break; 
     } 
    } else { 
     if (indexPath.row == 0) { 
      BuildingViewController *buildings = [self.storyboard instantiateViewControllerWithIdentifier:@"BuildingList"]; 
      buildings.userLoc = [[CLLocation alloc] initWithLatitude:mapViewController.map.userLocation.coordinate.latitude longitude:mapViewController.map.userLocation.coordinate.longitude]; 

      [self presentModalViewController:buildings animated:YES]; 
     } 
     [tableView deselectRowAtIndexPath:indexPath animated:NO]; 
     [tableView selectRowAtIndexPath:selectedIndex animated:YES scrollPosition:UITableViewScrollPositionNone]; 
    } 
    [self.slidingViewController anchorTopViewTo:ECRight animations:nil onComplete:^{ 
     [self.slidingViewController resetTopView]; 
    }]; 
} 

- (UIImage *)determineActiveRoute:(RouteName)route { 
    NSCalendar *gregorianCalender = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; 
    NSDateComponents *components = [gregorianCalender components:NSHourCalendarUnit fromDate:[NSDate date]]; 
    switch (route) { 
     case ENGINEERING: 
      if ([components day] % 7 == 2) { 
       if (([components hour] >= 7) && ([components hour] < 17)) { 
        return [UIImage imageNamed:@"green"]; 
       } else { 
        return [UIImage imageNamed:@"red"]; 
       } 
      } else if (([components day] % 7 == 3) || ([components day] % 7 == 4)) { 
       return [UIImage imageNamed:@"red"]; 
      } else { 
       //Weekday 
       if (([components hour] >= 7) && ([components hour] < 19)) { 
        return [UIImage imageNamed:@"green"]; 
       } else { 
        return [UIImage imageNamed:@"red"]; 
       } 
      } 
      break; 
     case GARNET: 
     case GOLD: 
     case HERITAGE: 
      if ((([components day] % 7 <= 3) || ([components day] % 7 >= 5)) && 
       (([components hour] >= 7) && ([components hour] <= 19))) { 
       return [UIImage imageNamed:@"green"]; 
      } else { 
       return [UIImage imageNamed:@"red"]; 
      } 
      break; 
     case NIGHT: 
      if ((([components day] % 7 == 6) || ([components day] % 7 <= 3)) && 
       (([components hour] >= 22.5) || ([components hour] <= 3))) { 
       return [UIImage imageNamed:@"green"]; 
      } else { 
       return [UIImage imageNamed:@"red"]; 
      } 
      break; 
     case OSCEOLA: 
     case RENEGADE: 
     case TOMAHAWK: 
      if ((([components day] % 7 <= 3) || ([components day] % 7 >= 5)) && 
       (([components hour] >= 7) && ([components hour] <= 19))) { 
       return [UIImage imageNamed:@"green"]; 
      } else { 
       return [UIImage imageNamed:@"red"]; 
      } 
      break; 
    } 
} 

@end 
+1

Los símbolos duplicados significa que tiene dos clases, ambas llamadas 'Generador' en su proyecto, o lista de compilación. – CodaFi

+1

Tengo Building.h, BuildingAnnotation.h y BuildingViewController.m/h.¿Hay alguna manera de borrar la lista de compilación y hacer que Xcode la regenere? –

+1

Borre su lista de compilación, luego cuando vaya a agregar todo, busque el término ".m" (sin comillas) y resalte cada archivo .m. luego haz clic en agregar. – CodaFi

Respuesta

17

según su petición:

quitar todas las clases de fuentes de compilación, a continuación, haga clic en el botón + y buscar el término '.m'. Resalta cada clase, luego haz clic en agregar. Construye y corre de nuevo.

+0

No funcionó para mí :( – NightFury

+0

iAnum compruebe que su @implementation line tiene el nombre correcto –

+2

Pude entrar en las fuentes de compilación al archivo específico que se quejaba de los símbolos duplicados. Lo eliminé y lo volví a agregar. trabajado. Esencialmente lo mismo que esta respuesta sin bombardear todo. – teradyl

1

No estoy seguro, pero hay un par de cosas que podría ser.

  1. Me he dado cuenta de que ni la clase parece importar Building.h así que mi primer pensamiento es que el compilador no sabe dónde obtener la información de esta clase. ¿TIENES QUE AGREGAR UN IMPORTE?

  2. Lo siguiente fue que generalmente trato de evitar tener dos clases que se importan entre sí. La compilación puede tener problemas al tratar de determinar en qué orden compilarlos. Puede necesitar cambiar uno de ellos para usar @class ... en lugar de #import ... para que el compilador lo deje hasta el tiempo de ejecución para resolver la clase.

  3. Finalmente, ¿ha hecho una limpieza? Algunas veces, al refaccionar mucho, las definiciones de clases antiguas quedan en los directorios de compilación y pueden causar problemas como este.

23

Compruebe que no ha importado el archivo .m donde debería estar el archivo .h. Doh!

+1

¡Increíble, gracias –

+0

increíble! Me estaba volviendo loco y nunca habría mirado lo suficiente para esto – IMFletcher

1

Borre el archivo y elija "Eliminar referencia". Arrastre el archivo nuevamente al proyecto y debería estar bien. Esto funcionó para mí.

1

El problema que me estaba causando esto era que había duplicado un archivo m, pero no renombré @implementation. Asegúrese de no tener declaraciones @implementation duplicadas.

1

Tuve un error similar cuando importé una biblioteca de terceros con múltiples archivos * .a en mi proyecto IOS. En mi caso, la eliminación del indicador del enlazador '-all_load' resolvió el problema.

+0

Esto eliminó la mayoría de mis duplicados. Todavía quedan 4. –

Cuestiones relacionadas