3 Replies
      Latest reply on Dec 1, 2015 10:45 PM by jawbroken
      Gargoyle Level 2 Level 2 (70 points)

        If I implement MKMapViewDelegate like so:

         

            func mapView(mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
                guard let item = view.annotation else { return }
        
        

         

        and then I try to look at item.title, it's showing as a String?? instead of a String? in Xcode 7.1.1

         

        If I control-click on annotation it says it's an MKAnnotation? like I'd expect.  Control-clicking on that shows title defined like so, which looks correct to me.  Is this a bug I need to report?

         

        optional public var title: String? { get }
        
        • Re: MKAnnotationView has double optionals
          eskimo Apple Staff Apple Staff (11,835 points)

          You end up with two levels of optionality because:

          • within the MKAnnotation protocol, the title property is optional

          • if that property is implemented, the value it returns is optional

          I’m not sure if there’s a nicer way to access title but the following seems to work:

          if let os = item.title, let s = os {
              print(s)
          }
          

          Share and Enjoy

          Quinn "The Eskimo!"
          Apple Developer Relations, Developer Technical Support, Core OS/Hardware
          let myEmail = "eskimo" + "1" + "@apple.com"