TSMessages icon indicating copy to clipboard operation
TSMessages copied to clipboard

Swift: showNotificationInViewController does not work

Open danshev opened this issue 10 years ago • 2 comments
trafficstars

The Good News:

TSMessage.showNotificationWithTitle("Hey",
  subtitle: "You", 
  type: TSMessageNotificationType.Success)

Working fine.

The Bad News:

TSMessage.showNotificationInViewController(self, 
  title: "Hey", 
  subtitle: "You", 
  image: nil, 
  type: TSMessageNotificationType.Success, 
  duration: TSMessageNotificationDuration.Automatic, 
  callback: nil, 
  buttonTitle: nil, 
  buttonCallback: nil, 
  atPosition: TSMessageNotificationPosition.NavBarOverlay, 
  canBeDismissedByUser: true)

Error: Cannot invoke showNotificationInViewController with an argument of list type ... yada yada

Suggestions?

danshev avatar May 19 '15 04:05 danshev

As mentioned in this thread: http://stackoverflow.com/questions/27640326/tsmessage-extra-argument-image-in-call

"It turns out, TSMessageNotificationDuration enums don't cast property to NSTimeInterval."

So, instead of using TSMessageNotificationDuration.Automatic, one can use a variable such as:

var automatic:NSTimeInterval = 0

So the full usage would be:

var automatic:NSTimeInterval = 0
TSMessage.showNotificationInViewController(self, 
  title: "Hey", 
  subtitle: "You", 
  image: nil, 
  type: TSMessageNotificationType.Success, 
  duration: automatic, 
  callback: nil, 
  buttonTitle: nil, 
  buttonCallback: nil, 
  atPosition: TSMessageNotificationPosition.NavBarOverlay, 
  canBeDismissedByUser: true)

danshev avatar May 20 '15 21:05 danshev

You can also explicitly cast the raw value of the enum to NSTimeInterval:

NSTimeInterval(TSMessageNotificationDuration.Automatic.rawValue)

koraktor avatar Jul 03 '15 13:07 koraktor