{ connected:YES connectionID:4" /> { connected:YES connectionID:4" /> { connected:YES connectionID:4"/>

How do I fetch name from an object?

52 Views Asked by At
let temp   = printer.information?.reserved["accessory"];
print(temp)

Output:

Optional(Optional(<EAAccessory: 0x281d04db0> { 

  connected:YES 
  connectionID:40870953 
  name: TSP100 
  manufacturer: Star Micronics 
  modelNumber: TTRDFGIBI GY 
  serialNumber: 07657643f 
  ppid: (null) 
  regioncode: (null) 
  firmwareRevisionActive: 1.0.0 
  firmwareRevisionPending: (null) 
  hardwareRevision: 1.0.0 
  dockType:  
  certSerial: 15 bytes 
  certData: 908 bytes 
  protocols: (
    "jp.star-m.starpro"
) 
  delegate: (null) 

}))

The type of the above printed object is Any.

Not sure how to get the value of name from the above object.

1

There are 1 best solutions below

0
HangarRash On

Since you are getting an EAAAccessory object you can access the name property. Something like this:

if let accessory = printer.information?.reserved["accessory"] as? EAAAccessory {
   let name = accessory.name
   print(name)
} else {
   print("Unable to access accessory")
}