Skip to content

Commit

Permalink
Fix for #10
Browse files Browse the repository at this point in the history
Crash when viewing ipfs daemon
  • Loading branch information
lapcat committed Mar 13, 2019
1 parent a0b1cc6 commit d275d79
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion source/ServiceDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,13 @@ class ServiceDelegate:NSObject, NetServiceDelegate, BonjourNode {
records.removeAll()

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) )
Expand Down

0 comments on commit d275d79

Please sign in to comment.