Reputation: 41
I am getting error as:
"Type of expression is ambiguous without more context swift4"
I am making local notification reminder page for iPhone app. I am using Xcode 9 and Swift 4.
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate
{
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool {
// Override point for customization after application launch.
if(UIApplication.instancesRespond(to: Selector("registerUserNotificationSettings:"))) {
UIApplication.sharedApplication.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: .Alert | .Badge, categories: nil))
}
return true
}
func application(_ application: UIApplication, didReceive notification: UILocalNotification) {
application.applicationIconBadgeNumber = 0
}
Upvotes: 1
Views: 1651
Reputation: 24341
The issue you are facing is because the syntax of code is not correct. The code you posted here is in Swift-2
which is why it is giving you syntax error.
Use the below code in Swift-4
:
UIApplication.shared.registerUserNotificationSettings(UIUserNotificationSettings.init(types: [.alert, .badge], categories: nil))
Let me know if you still face any issues.
Upvotes: 1