Crash with empty string in NSPopupButton & Bindings

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Crash with empty string in NSPopupButton & Bindings

Jean Suisse
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

T: +333-8039-9037 
F: +339-7232-2604
E[hidden email]





--
You received this message because you are subscribed to the Google Groups "Swift Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/6BD03A14-6929-43EC-9484-0FB90F7F58DE%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Crash with empty string in NSPopupButton & Bindings

Jean Suisse
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 <[hidden email]> 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>
-----------
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

T: +333-8039-9037 
F: +339-7232-2604
E[hidden email]






--
You received this message because you are subscribed to the Google Groups "Swift Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/F8E06996-0C89-4977-A7A9-B6939C8A76E9%40gmail.com.
For more options, visit https://groups.google.com/d/optout.