我只是在阅读有关协议初始值设定项要求的 Apple Swift 4 文档并在协议扩展中提供默认实现。
import UIKit
protocol Protocol {
init()
}
extension Protocol {
init() {
print("SDf")
self.init() // Line 1
// Compiler error occured if this is omitted
//"'self.init' isn't called on all paths before returning from initializer"
}
}
struct Structure: Protocol {
init(string: String) {
}
}
Structure() // Line 2
Run Code Online (Sandbox Code Playgroud)
现在如您所见,执行将进入循环,因为默认情况下该结构没有实现 for init(),因此将调用提供的协议 init 并再次调用自身,因此进入无限循环.
现在,知道了这一点,如果我删除第 1 行,编译器就会给出错误。
Q. 为什么强制我self.init()在1号线使用,如何摆脱这种情况?
当我尝试使用命令安装mysql-server时,这是终端输出 -
sudo apt-get install mysql-server
Run Code Online (Sandbox Code Playgroud)
终端o/p
Setting up mysql-community-server (5.7.18-1ubuntu16.04) ...
update-alternatives: using /etc/mysql/mysql.cnf to provide /etc/mysql/my.cnf (my.cnf) in auto mode
AppArmor parser error for /etc/apparmor.d/usr.sbin.mysqld in /etc/apparmor.d/usr.sbin.mysqld at line 7: Could not open 'abstractions/mysql'
Job for mysql.service failed because the control process exited with error code. See "systemctl status mysql.service" and "journalctl -xe" for details.
invoke-rc.d: initscript mysql, action "start" failed.
? mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) …Run Code Online (Sandbox Code Playgroud)