0

The offending element is the

let mSSIDDATA = SSIDDict["SSIDDATA"]

field. If I leave it as it is, it prints out to the log window as shown here.

Looking up SSID info for en0 SSIDDict Values: ["SSID": SKYF7BFF, "BSSID": 7c:4c:a5:c:8b:15, "SSIDDATA": <534b5946 37424646>]

mSSID: SKYF7BFF

mBSSID: 7c:4c:a5:c:8b:15

mSSIDDATA: <534b5946 37424646>

SSID: SKYF7BFF

BSSID: 7c:4c:a5:c:8b:15

SSIDDATA: <534b5946 37424646>

=========

However - It doesn't print out into the UITextField in the iOS interface. The other two do, but this third one doesn't, and I can't figure out why.? If I change the [String : Any] to [String : AnyObject] it creates another whole set of warnings and errors.

So basically, how do I convert that mSSIDDATA to a string that the UITextField can handle?

            guard let SSIDDict: [String : Any]  = (unwrappedCFDictionaryForInterface as NSDictionary) as? [String: AnyObject] else {
            print("System error: interface information is not a string-keyed dictionary")
            return false
        }
        print("SSIDDict Values: \(SSIDDict)")
        let mSSID = SSIDDict["SSID"] as? String
        let mBSSID = SSIDDict["BSSID"] as? String
        let mSSIDDATA = SSIDDict["SSIDDATA"] //as? String

        print("mSSID: \(mSSID ?? "")")
        vSSID.text = mSSID
        print("mBSSID: \(mBSSID ?? "")")
        vBSSID.text = mBSSID
        print("mSSIDDATA: \(mSSIDDATA ?? "")")
        vSSIDDATA.text = mSSIDDATA as? String

        for d in SSIDDict.keys {
            print("\(d): \(SSIDDict[d]!)")
        }



    }
    return true
}
Syed Qamar Abbas
  • 3,637
  • 1
  • 28
  • 52
Harry McGovern
  • 517
  • 5
  • 19

2 Answers2

2

Your „SSIDDATA” is most likely od Data type - you need to convert it to String. You can USD the init(data:encoding:) on String to achieve this.

Losiowaty
  • 7,911
  • 2
  • 32
  • 47
2

As the name mSSIDDATA implies and the output <...> indicates the type of the value is Data

if let mSSIDDATA = SSIDDict["SSIDDATA"] as? Data {
    print(String(data: mSSIDDATA, encoding : .utf8)!) // SKYF7BFF
}

Practically it's the Data representation of the mSSID string value.

vadian
  • 274,689
  • 30
  • 353
  • 361
  • Thanks, so this works and puts the converted string into the UITextField. like this. vSSIDDATA.text = (String(data: mSSIDDATA as! Data, encoding : .utf8)!) Where vSSIDATA is the UITextField. Is it possible then to not convert the data, but still print it to the UITextField? – Harry McGovern Apr 19 '18 at 15:07
  • If you want to print `<534b5946 37424646>` then write `print(String(describing: mSSIDDATA as NSData))` – vadian Apr 19 '18 at 15:13
  • Excellent. Looks like I'm doing some in-depth study on Data. This works. print(String(describing: mSSIDDATA as! NSData)) vSSIDDATA.text = (String(describing: mSSIDDATA as! NSData)) – Harry McGovern Apr 19 '18 at 15:20