質問

I recently started a new project in Xcode 4.4 running on Mountain Lion. I have a class called TSTopChartManager, which is in the MainMenu nib of my project. I also have a data container called PodcastShow, which basically has a bunch of properties and a method to fetch an image from the internet. This is what TSTopChartManger looks like...

The .h file...

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

@interface TSTopChartManager : NSObject

@property NSMutableArray *topPodcasts;
@end

The .m file:

#import "TSTopChartManager.h"

@implementation TSTopChartManager
-(id) init
{
    if (self)
    {
        /*PodcastShow *myShow = [[PodcastShow alloc] init];
        myShow.title = @"This is a show";*/
    }
    return self;
}
@end

Right now, it runs perfectly. But when I remove the block comment in the init method like so...

if (self)
    {
        PodcastShow *myShow = [[PodcastShow alloc] init];
        myShow.title = @"This is a show";
    }

I get the following errors..

Undefined symbols for architecture x86_64:
  "_OBJC_CLASS_$_PodcastShow", referenced from:
      objc-class-ref in TSTopChartManager.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I have no idea why this is happening. I haven't seen errors like this before. How would I go about fixing it? Any ideas? Thank you!

For the curious: PodcastShow is treated as a data container in my app. It has a few properties and two methods. Here's what PodcastShow looks like:

.h:

#import <Foundation/Foundation.h>

@interface PodcastShow : NSObject
{
    NSString *title;
    NSString *network;
    NSString *imageURL;
    NSImage *image;
    NSString *link;
    NSString *description;
}
-(void) fetch;
@property (strong, readwrite) NSString *title;
@property (strong, readwrite) NSString *network;
@property (strong, readwrite) NSString* imageURL;
@property (strong) NSImage *image;
@property (strong, readwrite) NSString *identification;
@property (strong, readwrite) NSString *link;
@property (strong, readwrite) NSString *description;
@end

m:

#import "PodcastShow.h"

@implementation PodcastShow
-(id) init
{
    if (self)
    {
        NSLog(@"initilized");
    }
    return self;
}

-(void) fetch
{
    [NSThread detachNewThreadSelector:@selector(getImageFromInternet) toTarget:self withObject:nil];
}

-(void) getImageFromInternet
{
    self.image = [[NSImage alloc] initWithContentsOfURL:[NSURL URLWithString:self.imageURL]];
}
@end
役に立ちましたか?

解決

Probably PodcastShow.m is not part of the build phase. Click on it in the project navigator and look on the right of the screen in the file info. Make sure your app target is ticked.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top