1

when I type like this :

func onAppOpenAttribution(_ attributionData: [AnyHashable : Any]!) {
    if let data = attributionData {
        if let link = data["link"]{
            print("link:  \(link)")
        }
    }
}

I got error "Initializer for conditional binding must have Optional type, not '[AnyHashable : Any]'" on this line if let data = attributionData

How to repair that?

Sarimin
  • 707
  • 1
  • 7
  • 18

1 Answers1

3
func onAppOpenAttribution(_ attributionData: [AnyHashable : Any]?) {

your attributionData should be optional type, if let data = attributionData if let case is used to safely unwrap an optional value. But currently you are passing a non optional value to it. So you have two options. Either to make attributionData as optional, or remove if let statement

Option 1:

func onAppOpenAttribution(_ attributionData: [AnyHashable : Any]?) {
    if let data = attributionData {
        if let link = data["link"]{
            print("link:  \(link)")
        }
    }
}

Option 2:

func onAppOpenAttribution(_ attributionData: [AnyHashable : Any]) {
    let data = attributionData 
    if let link = data["link"]{
       print("link:  \(link)")
     }
  }
}
Keshu R.
  • 5,045
  • 1
  • 18
  • 38
  • after use ?, the warning still exist – Sarimin Jan 22 '20 at 05:18
  • Parameter of 'onAppOpenAttribution' has different optionality than expected by protocol 'AppsFlyerTrackerDelegate' replace ? with "" after that I got error "Initializer for conditional binding must have Optional type, not '[AnyHashable : Any]'" on this line if let data = attributionData again – Sarimin Jan 22 '20 at 05:20
  • Thats a different error. Its something in your code logic. For you current question, i have given the answer. If you have another error, ask a new question instead and we would help you there :) – Keshu R. Jan 22 '20 at 05:23