1

I want to implement iAd to my Swift app with this code:

bannerView = ADBannerView(adType: .banner)
bannerView.translatesAutoresizingMaskIntoConstraints = false
bannerView.delegate = self
bannerView.isHidden = true
view.addSubview(bannerView)

let viewsDictionary = ["bannerView": bannerView]
view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|[bannerView]|", options: [], metrics: nil, views: viewsDictionary))
view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:[bannerView]|", options: [], metrics: nil, views: viewsDictionary))

but in the view.addContraints lines is this error:

Cannot convert value of type '[String : ADBannerView?]' to expected argument type '[String : AnyObject]

I'm not sure what to do.

Daniel Storm
  • 18,301
  • 9
  • 84
  • 152

1 Answers1

1

It seems that your bannerView variable is an optional, while your dictionary is expecting non-optionals (AnyObject not AnyObject?). You need to unwrap the optional:

let viewsDictionary = ["bannerView":bannerView!]

However, as others noted in the comments, the iAd network is shutting down from the end of June 2016 so no advertisements will be delivered to your app after this date. You may want to investigate alternate advertising frameworks.

Paulw11
  • 108,386
  • 14
  • 159
  • 186