title: Convert CFString to NSString - Swift
body: <p>I'm trying to write a program that will scan for available serial ports and present them in a popup menu. Why can I not take the <code>CFString</code> straight from the <code>IORegistryEntryCreateCFProperty()</code> function and add it to the menu via string interpolation in the next line? For some reason my variable declaration is met with the error:   </p>
  
  <blockquote>
    <p>"NSString is not a subtype of CFString".</p>
  </blockquote>
  
  <pre><code>import Foundation
  
  import Cocoa
  
  import IOKit
  import IOKit.serial
  
  
  @objc class Serial {
  
      init() {
      }
  
      @IBOutlet var serialListPullDown : NSPopUpButton!
  
      func refreshSerialList(defaultprompt: String) {
  
  
          let masterPort: mach_port_t = kIOMasterPortDefault
          let classesToMatch: CFDictionary =     IOServiceMatching(kIOSerialBSDServiceValue).takeUnretainedValue()
          var matchingServices: io_iterator_t = 0
  
          // remove everything from the pull down list
          serialListPullDown?.removeAllItems()
  
          // ask for all the serial ports
          let kernResult = IOServiceGetMatchingServices(masterPort, classesToMatch, &amp;matchingServices)
          if kernResult == KERN_SUCCESS {
              // success
              while (io_object_t() == IOIteratorNext(matchingServices)) {
                  var serialport = IORegistryEntryCreateCFProperty(io_object_t(), kIOCalloutDeviceKey, kCFAllocatorDefault, 0)
  
                  serialListPullDown?.addItemWithTitle("\(serialport)")
              }
          }
          else {
              // error
          }
  
      }
  }
  </code></pre>