ios - 初始化方法的参数具有默认值时的问题

标签 ios xcode init

我正在我的项目中为某个类创建一个 init 方法,基本上我想包装一个本地 Notification 类。

因为我的本地通知只有一种声音,我想在类初始化时将其设置为默认值,如下所示:

    override init(notificationTitle:String, subtitle:String, sound = UNNotificationSound.init(named: AppSettingManager.share.loadFocusNotificationSound()), categoryId:String ) {

    super.init()
}

因为声音参数的值存储在 NSUserdefault 中,我想在类初始化时设置声音的值。

然而,Xcode 提示为

Unnamed parameters must be written with the empty name '_'

enter image description here

我该如何解决这个问题?还有其他方法可以解决这个问题吗?提前致谢。

最佳答案

sound = 更改为 sound:

override init(notificationTitle:String, subtitle:String, sound: UNNotificationSound.init(named: AppSettingManager.share.loadFocusNotificationSound()), categoryId:String ) {
    super.init()
}

关于ios - 初始化方法的参数具有默认值时的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44867771/

相关文章:

ios - NSNumberFormatter 用于格式化货币不适用于 float

ios - 'AnyObject' 没有成员 "contactUID"即使 Intelitype 说它有?

ios - Storyboard预览不同于模拟器

objective-c - Objective-C : NSError in initialiser

bash - 如何让 bash 脚本永远作为系统后台进程运行?

c - 实现用户级线程库但代码不断出现段错误,有什么想法吗?

ios - 需要从 XML 文件中获取属性

iphone - 如何通过网络更新 iOS 应用程序

ios - 单元目标测试构建失败 xcode objective-c

objective-c - 如何让 UIScrollView 跟踪某些东西?