3

Apologies- i'm new to xcode/cocoa/objective-c...

I'm struggling to understand what is wrong with:

NSHost *host = [NSHost hostWithAddress:@"192.168.0.155"];

I'm receiving 2 errors"

No known class method for selector 'hostWithAddress:'
Receiver 'NSHost' for class message is a forward declaration

Could you help explain the errors and how I can achieve the simple task of creating an instance of NSHost pointing to 192.168.0.155.

Thanks

Lee

Aaron Brager
  • 65,323
  • 19
  • 161
  • 287
Lee Tickett
  • 5,847
  • 8
  • 31
  • 55

3 Answers3

4

It turns out NSHost is not available on the iPhone! It's a shame xcode didn't highlight that for me!

I tried to use NSHost and XCode didn't recognize it

Thanks for your help,

Lee

Community
  • 1
  • 1
Lee Tickett
  • 5,847
  • 8
  • 31
  • 55
2

According to the documentation for NSHost, you are using exactly the right method. However from looking at your error message, it says hostwithAddress, the correct casing is hostWithAddress, so make sure there is a capital W.

Also, make sure you have #import <Foundation/Foundation.h> at the top of your .m file.

Remember, Objective-C is a case sensitive language.

Jake Petroules
  • 23,472
  • 35
  • 144
  • 225
  • Unfortunately it wasn't that simple. I copy/pasted the code but the error message doesn't allow copy/paste so i retyped it and made a typo (which i have now corrected. Any other ideas? Thanks – Lee Tickett Dec 29 '11 at 23:21
  • 1
    Did you import the Foundation framework? Your error message says it is only a forward declaration which means it isn't finding the implementation of that class. – Jake Petroules Dec 29 '11 at 23:33
  • You got it. I think the fact that auto-complete was kicking in threw me off. Thanks! – Lee Tickett Dec 29 '11 at 23:39
  • OK now i'm even more confused... I had #import "" which made the error go away but then when i tried to build i realized it should be <> or "" but not both and the error has returned :( – Lee Tickett Dec 29 '11 at 23:49
  • Could you post the full code? What error has returned, the same one? – Jake Petroules Dec 30 '11 at 02:59
  • Same 2 errors. I literally created a brand new "single view application" added the #import line right below #import "ViewController.h" and then added the troublesome line in viewDidLoad{} – Lee Tickett Dec 30 '11 at 07:13
0

As mentioned NSHost is not available in iPhone, depends on what you need it for you could bypass it by using this sample code by apple: https://developer.apple.com/library/ios/qa/qa1652/_index.html

Ben Quan
  • 773
  • 11
  • 25