Skip to content
Browse files

Fix for #10

Crash when viewing ipfs daemon
  • Loading branch information...
lapcat committed Mar 13, 2019
1 parent a0b1cc6 commit d275d79d5de1ac918965c25932e72f0485ac3e98
Showing with 7 additions and 1 deletion.
  1. +7 −1 source/ServiceDelegate.swift
@@ -116,7 +116,13 @@ class ServiceDelegate:NSObject, NetServiceDelegate, BonjourNode {

if let txtRecordData = service.txtRecordData() {
let txtRecord = NetService.dictionary(fromTXTRecord:txtRecordData)
// This crashes in Swift:
//let txtRecord = NetService.dictionary(fromTXTRecord:txtRecordData)
// When the TXT Record is not in the format key=value,
// +[NSNetService dictionaryFromTXTRecordData:] illegally inserts NSNull in place of NSData,
// and this crashes when bridged to Swift because it can't bridge NSNull to Data.
// We fall back to using the TXT Record data itself with no key.
let txtRecord = CFNetServiceCreateDictionaryWithTXTData(nil, txtRecordData as CFData)?.takeRetainedValue() as? Dictionary<String,Data> ?? ["":txtRecordData]
for (key, data) in txtRecord {
if let line = NSString(data:data, encoding:String.Encoding.utf8.rawValue) {
records.append( (key, line as String) )

0 comments on commit d275d79

Please sign in to comment.
You can’t perform that action at this time.