R – NSLog not printing to terminal

command lineconsolenslogobjective cterminal

Ok, so I've been using NSLog in objective-C for awhile now to debug and I know it's supposed to print to the terminal whatever I put in the parentheses. For some reason, it just stopped printing to the terminal and I'm not sure how to fix this error. I was wondering what other people would suggest doing to fix this problem. I've only included part of my code because I don't want to scare away someone from answering this simple (or at least I hope it's simple to fix) problem. When I run the code, the only two statements that print are "serverButton – Stage 1" and "serverButton – Stage 2 – Complete" but nothing else in between. FYI -(void)startServer is in another class called "Server" and I have made "server" a pointer to that said class.

-(IBAction)serverButton {
NSLog(@"serverButton - Stage 1");
[server startServer];
NSLog(@"serverButton - Stage 2 - Complete");
}

-(void)startServer {
    NSLog(@"serverButton - Stage 1");

    memset(&hints, 0, sizeof hints);
    hints.ai_family = AF_UNSPEC; // set to AF_INET to force IPv4
    hints.ai_socktype = SOCK_DGRAM;
    hints.ai_flags = AI_PASSIVE; // use my IP

    if ((rv = getaddrinfo(NULL, MYPORT, &hints, &servinfo)) != 0) {
        NSLog(@"ERROR: serverButton - Stage 1");
        fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));
        serverError = 1;
        NSLog(@"Error");
    }

Best Answer

Add a check to make sure server is not nil before you call startServer, if it was nil then nothing would get called and no error would be generated.