Initializer

init(domain:type:name:)

Returns the receiver, initialized as a network service of a given type and sets the initial host information. レシーバを返します、与えられた方のネットワークサービスとして初期化され、初期ホスト情報を設定されます。

Declaration 宣言

convenience init(domain: String, 
            type: String, 
            name: String)

Parameters パラメータ

domain

The domain for the service. To resolve in the default domains, pass in an empty string (@""). To limit resolution to the local domain, use @"local.". サービスに対するドメイン。省略時のドメインにおいて解決するには、空の文字列を渡してください(@"")。解決をローカルドメインに制限するには、@"local."を使ってください。

If you are creating this object to resolve a service whose information your app stored previously, you should set this to the domain in which the service was originally discovered. それの情報をあなたのアプリが以前に格納したサービスを解決するためにあなたがこのオブジェクトを作成しようとするならば、あなたはこれを、それにおいてこのサービスがそもそも発見されたドメインに設定すべきです。

You can also use a NSNetServiceBrowser object to obtain a list of possible domains in which you can discover and resolve services. あなたはまたNSNetServiceBrowserオブジェクトを使って、それにおいてあなたがサービスを発見および解決することが可能なドメインのリストを取得できます。

type

The network service type. ネットワークサービス型。

type must contain both the service type and transport layer information. To ensure that the mDNS responder searches for services, as opposed to hosts, prefix both the service name and transport layer name with an underscore character (“_”). For example, to search for an HTTP service on TCP, you would use the type string "_http._tcp.". Note that the period character at the end of the string, which indicates that the domain name is an absolute name, is required. typeは、サービス型およびトランスポート層情報の両方を含まなければなりません。mDNSレスポンダがサービスを、ホストではなくて、検索するのを確実にするには、サービス名とトランスポート層名の両方にアンダースコア文字(“_”)で接頭辞をつけてください。例えば、HTTPサービスをTCP上で検索するには、あなたは型文字列 "_http._tcp." を使うでしょう。文字列の最後で、ドメイン名が完全名であるのを指し示す、ピリオド文字が必要であることに注意してください。

name

The name of the service to resolve. 解決することになるサービスの名前。

Return Value 戻り値

The receiver, initialized as a network service named name of type type in the domain domain. このレシーバ、それはnameと名前をつけられ、型typeで、ドメインdomainの中にネットワークサービスとして初期化されます。

Discussion 議論

This method is the appropriate initializer to use to resolve a service—to publish a service, use init(domain:type:name:port:). このメソッドは、サービスを解決するために使うのに適切なイニシャライザです — サービスを出版するには、init(domain:type:name:port:)を使ってください。

If you know the values for domain, type, and name of the service you wish to connect to, you can create an NSNetService object using this initializer and call resolve(withTimeout:) on the result. あなたが接続を望むサービスのdomaintype、そしてnameに対する値を知っているならば、あなたはNSNetServiceオブジェクトをこのイニシャライザを使って作成して、その結果上でresolve(withTimeout:)を呼び出すことができます。

You cannot use this initializer to publish a service. This initializer passes an invalid port number to the designated initializer, which prevents the service from being registered. Calling publish() on an NSNetService object initialized with this method generates a call to your delegate’s netService(_:didNotPublish:) method with an NetService.ErrorCode.badArgumentError error. あなたは、このイニシャライザをサービスの出版に使うことはできません。このイニシャライザは、ある無効なポート番号を指定イニシャライザに渡します、それはサービスが登録されることを防ぎます。publish()をこのメソッドで初期化されたNSNetServiceオブジェクト上で呼び出すことは、あなたの委任先の持つnetService(_:didNotPublish:)メソッドへのNetService.ErrorCode.badArgumentErrorエラーを使う呼び出しを生成します。

See Also 参照

Creating Network Services ネットワークサービスを作成する