How would I make a GUI program that displays your Ip address with a click of a button? Please, no difficult explanations, I just started Cocoa not long ago.
Thanks,<
For determining the IP address, I found this.
As for making it into a Cocoa app, add an NSTextField
(label) to your main window in Interface Builder, put in a button, add in an application controller (a subclass of NSObject
that you make), put in the outlet and the action, do the proper connenctions, and in the "get IP" method, put in that code and set the value for the label's stringValue
.
You can use [[NSHost currentHost] address]
, but it won't always display what you like. On my system, for example, it gives my IPv6 address.
EDIT: On my system, [[[NSHost currentHost] addresses] objectAtIndex:0]
has my IPv4 address.