Crash with empty string in NSPopupButton & Bindings

14 views
Skip to first unread message

Jean Suisse

unread,
Apr 16, 2015, 1:40:31 PM4/16/15
to swift-l...@googlegroups.com
Dear all,

I have this ObjC / Swift application with a swift class that contains:

1. Variable & outlets & Bindings
 A NSPopUpButton and a member variable tied to the button’s selected value (File’s Owner.self.someDevicePopupButton)

@IBOutlet weak var someDevicePopupButton: NSPopUpButton!
dynamic  var someDeviceName: String ""

2. Initialization of the popup button in:
override func windowDidLoad()
{
   ...
   let sensors = deviceManager.listOfAllAvailableDevicesOfKind(DEVICE_SENSOR) + [""]
   self.someDevicePopupButton.removeAllItems()
   self.someDevicePopupButton.addItemsWithTitles(sensors)
   self.someDevicePopupButton.safelySelectItemWithTitle(the device that was last used, createIfNeeded: NO)
   ...
}

An empty string is added to the list of all available devices because in this particular experiment (it is a scientific software) the user may not want to select any device.
Initially, the last used device is selected. And when I select the empty string "" in the NSPopUpButton… the app crashes with a bad access in CFStringCreateCopy (see below).
If I replace  + [""] with  + ["-"] everything works fine.

Is it a bug or something I missed ? Is there something special with Swift empty strings that I should know?

Thanks,
Jean



-----------
Jean Suisse

Institut de Chimie Moléculaire de l’Université de Bourgogne
(ICMUB) — UMR 6302

U.F.R. Sciences et Techniques, Bâtiment Mirande
Aile B, bureau 413
9, avenue Alain Savary — B.P. 47870
21078 DIJON CEDEX




Jean Suisse

unread,
Apr 16, 2015, 1:47:57 PM4/16/15
to swift-l...@googlegroups.com
In my previous e-mail, I forgot to mention that if I declare:

dynamic var someDeviceName:NSString = ""

instead of :

dynamic  var someDeviceName: String  ""

the app doesn’t crash when selecting the empty string but the popupButton reverts to the previous selected string… (so the empty string can’t actually be selected)


On Apr 16, 2015, at 19:40 , Jean Suisse <jean....@gmail.com> wrote:

Dear all,

I have this ObjC / Swift application with a swift class that contains:

1. Variable & outlets & Bindings
 A NSPopUpButton and a member variable tied to the button’s selected value (File’s Owner.self.someDevicePopupButton)

@IBOutlet weak var someDevicePopupButton: NSPopUpButton!
dynamic  var someDeviceName: String ""

2. Initialization of the popup button in:
override func windowDidLoad()
{
   ...
   let sensors = deviceManager.listOfAllAvailableDevicesOfKind(DEVICE_SENSOR) + [""]
   self.someDevicePopupButton.removeAllItems()
   self.someDevicePopupButton.addItemsWithTitles(sensors)
   self.someDevicePopupButton.safelySelectItemWithTitle(the device that was last used, createIfNeeded: NO)
   ...
}

An empty string is added to the list of all available devices because in this particular experiment (it is a scientific software) the user may not want to select any device.
Initially, the last used device is selected. And when I select the empty string "" in the NSPopUpButton… the app crashes with a bad access in CFStringCreateCopy (see below).
If I replace  + [""] with  + ["-"] everything works fine.

Is it a bug or something I missed ? Is there something special with Swift empty strings that I should know?

Thanks,
Jean

<PastedGraphic-1.png>
<PastedGraphic-3.png>

<PastedGraphic-4.png>
Reply all
Reply to author
Forward
0 new messages