I have created a new class of type NSObject, which created two files — a .h and a .m file. Here is the code from the two files:
SocketConnection.h
#import <Foundation/Foundation.h>
@interface SocketConnection : NSObject
{
}
+ (SocketConnection *)getInstance;
@end
SocketConnection.m
#import "SocketConnection.h"
#import "imports.h"
static SocketConnection *sharedInstance = nil;
@implementation SocketConnection
- (id)init
{
self = [super init];
if (self)
{
while(1)
{
Socket *socket;
int port = 11005;
NSString *host = @"199.5.83.63";
socket = [Socket socket];
@try
{
NSMutableData *data;
[socket connectToHostName:host port:port];
[socket readData:data];
// [socket writeString:@"Hello World!"];
// Connection was successful //
[socket retain]; // Must retain if want to use out of this action block.
}
@catch (NSException* exception)
{
NSString *errMsg = [NSString stringWithFormat:@"%@",[exception reason]];
NSLog(errMsg);
socket = nil;
}
}
}
return self;
}
+ (SocketConnection *)getInstance
{
@synchronized(self)
{
if (sharedInstance == nil)
{
sharedInstance = [[SocketConnection alloc] init];
}
}
return sharedInstance;
}
@end
And I seem to be getting a Linker error. When I comment out all the code in the SocketConnection.h/SocketConnection.m, the errors go away. I have several views in my project. I have a header file called “imports.h”, which I have imported SocketConnection.h, and included “imports.h” in my SocketConnection.m file. Any help would be greatly appreciated, since I seem to be stuck here :/. Thanks!
Errors:
Undefined symbols for architecture i386:
"_OBJC_CLASS_$_Socket", referenced from:
objc-class-ref in SocketConnection.o
(maybe you meant: _OBJC_CLASS_$_SocketConnection)
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
You need to #import “Socket.h” at the top of you .m file.
The error here
is saying that SocketConnection is referencing an Objective-C class named “Socket” that it does not know about.