NSHost Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/Foundation.framework
Availability
Available in OS X v10.0 and later.
Companion guide
Interacting with the Operating System
Declared in
NSHost.h

Overview

The NSHost class provides methods to access the network name and address information for a host. Instances of the NSHost class represent individual hosts on a network. Use NSHost objects to get the current host’s name and address and to look up other hosts by name or by address.

To create an NSHost object, use the currentHost, hostWithAddress:, or hostWithName: class methods (don’t use alloc and init). These methods use available network administration services (such as NetInfo or the Domain Name Service) to discover all names and addresses for the host requested. They don’t attempt to contact the host itself, however. This approach avoids untimely delays due to a host being unavailable, but it may result in incomplete information about the host.

An NSHost object contains all of the network addresses and names discovered for a given host by the network administration services. Each NSHost object typically contains one unique address, but it may have more than one name. If an NSHost object has more than one name, the additional names are variations on the same name, typically the basic host name plus the fully qualified domain name. For example, with a host name “sales” in the domain “anycorp.com”, an NSHost object can hold both the names “sales” and “sales.anycorp.com”.

NSHost methods are thread-safe.

Tasks

Creating Hosts

Getting Host Information

Comparing Hosts

Managing the Host Cache

Class Methods

currentHost

Returns an NSHost object representing the host the process is running on.

+ (NSHost *)currentHost
Return Value

NSHost object for the process’s host.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSHost.h

hostWithAddress:

Returns the NSHost with the Internet address address.

+ (NSHost *)hostWithAddress:(NSString *)address
Parameters
address

Network address to look up. For example, @"127.0.0.1" or @"fe80::1".

Return Value

The host for address.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSHost.h

hostWithName:

Returns a host with a specific name.

+ (NSHost *)hostWithName:(NSString *)hostname
Parameters
hostname

Name of the host to look up. Can be either a simple hostname, such as @"sales", or a fully qualified domain name, such as @"sales.anycorp.com".

Return Value

The host named hostname.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSHost.h

Instance Methods

address

Returns one of the network addresses of the receiver.

- (NSString *)address
Return Value

One of the network address for the receiver. For example, @"192.42.172.1" or @"fe80::1".

Availability
  • Available in OS X v10.0 and later.
Declared In
NSHost.h

addresses

Returns all the network addresses of the receiver.

- (NSArray *)addresses
Return Value

All the network addresses of the receiver.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSHost.h

isEqualToHost:

Indicates whether the receiver represents the same host as another NSHost object.

- (BOOL)isEqualToHost:(NSHost *)host
Parameters
host

Host to compare the receiver to.

Return Value

YES when the receiver and host share at least one network address; NO otherwise.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSHost.h

localizedName

Returns the name used as by default when publishing NSNetServices.

- (NSString *)localizedName
Return Value

A string containing the computer name.

Discussion

This is the name displayed in the Finder sidebar, as well as in the Sharing preference panel.

This method only returns an NSString when sent to the the currentHost instance, all other instances currently return nil.

This property is key-value observable.

Availability
  • Available in OS X v10.6 and later.
Declared In
NSHost.h

name

Returns one of the hostnames of the receiver.

- (NSString *)name
Return Value

One of the hostnames of the receiver. Can be either a simple hostname, such as @"sales", or a fully qualified domain name, such as @"sales.anycorp.com".

Availability
  • Available in OS X v10.0 and later.
Declared In
NSHost.h

names

Returns all the hostnames of the receiver.

- (NSArray *)names
Return Value

All the hostnames of the receiver.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSHost.h