TSMessages
TSMessages copied to clipboard
Swift: showNotificationInViewController does not work
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?
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)
You can also explicitly cast the raw value of the enum to NSTimeInterval:
NSTimeInterval(TSMessageNotificationDuration.Automatic.rawValue)