| ページ一覧 | ブログ | twitter |  書式 | 書式(表) |

MyMemoWiki

差分

ナビゲーションに移動 検索に移動
1,838 バイト追加 、 2022年3月19日 (土) 01:48
try container.encode(comment, forKey: .comment)
}
</pre>
 
===ディレクトリ判定===
----
<pre>
private static let fm = FileManager.default
static func isDirectory(path: String) -> Bool {
var isDir = ObjCBool(false)
fm.fileExists(atPath: path, isDirectory: &isDir)
return isDir.boolValue
}
</pre>
DispatchQueue.main.sync {
observableobj.content = text
}
</pre>
===ディレクトリを選択===
----
<pre>
static func chooseDir() -> String {
let dialog = NSOpenPanel();
 
dialog.title = "Choose a root directory"
dialog.showsResizeIndicator = true
dialog.showsHiddenFiles = false
dialog.allowsMultipleSelection = false
dialog.canChooseDirectories = true
dialog.canChooseFiles = false
 
if (dialog.runModal() == NSApplication.ModalResponse.OK) {
let result = dialog.url
 
if (result != nil) {
let path: String = result!.path
return path
}
}
return "";
}
</pre>
==処理==
===サブプロセスを起動===
----
*プロセスを起動し、arp -a を呼び出し、出力
<pre>
}
</pre>
 
===非同期処理===
----
<pre>
let c = {
(ip:String) -> String in
let hostName = getHostName(ip: ip) // 時間がかかる処理
return hostName
}
 
let que = DispatchQueue.global(qos: .default)
for host in hosts.hosts {
print("CALL-\(host.ip)")
que.async { // 非同期処理
let hostname = c(host.ip) // 時間がかかる処理
DispatchQueue.main.async { // 画面に反映
host.host = hostname
}
}
}
</pre>
 
==[[正規表現]]==
===arp -a の結果からIPアドレスを抜きだす===
}
</pre>
===digを経由してBonjourでIPアドレスをホスト名に解決===
*コマンドをswiftで呼び出し dig +short -x 192.168.0.45 @224.0.0.251 -p 5353
<pre>
let outputPipe = Pipe()
let _ = shell(outputPipe,
path:"/usr/bin/dig",
args: "+short",
"-x", ip,
"@224.0.0.251", "-p","5353") // Bonjour IPアドレス
let theTaskData = outputPipe.fileHandleForReading.readDataToEndOfFile()
let stringResult = String(data: theTaskData, encoding: .utf8)
</pre>
 
===名前を付与してキャプチャ===
----

案内メニュー