Search code examples
iosswiftuiactivityviewcontroller

UIActivityViewController init method in Swift doesn't play nice


I've this bit of code

var dataToShare = "My score is \(currentScore). Come and play with me!"
var act: UIActivityViewController = UIActivityViewController(activityItems: dataToShare, applicationActivities: nil)

But there's this bugging error that keeps me crazy- "Incorrect argument labels in call (have 'activityItems:applicationActivities:', expected 'nibName:bundle:')" Now this code seems to work everywhere else except in my code. I've tried deleting DerivedData, to no avail. What can be the problem?

Thanks!


Solution

  • Thats because activityItems needs to be passed as an array:

    var act = UIActivityViewController(activityItems: [dataToShare], applicationActivities: nil)