大家好。这是我的代码,我有两个问题
首先,我想知道我的登录流程是否正确?
我的逻辑是当用户进入我的索引页面时
我将首先检查用户登录状态
如果用户未登录,则要求用户登录。
function google_login_in(){
var provider = new firebase.auth.GoogleAuthProvider();
provider.addScope('https://www.googleapis.com/auth/plus.login');
firebase.auth().signInWithPopup(provider).then(function(result) {
var token = result.credential.accessToken;
var user = result.user;
}).catch(function(error) {
var errorCode = error.code;
var errorMessage = error.message;
var email = error.email;
var credential = error.credential;
});
}
function print_user(user) {
user.providerData.forEach(function (profile) {
console.log("Sign-in provider: "+profile.providerId);
console.log(" Provider-specific UID: "+profile.uid);
console.log(" Name: "+profile.displayName);
console.log(" Email: "+profile.email);
console.log(" Photo URL: "+profile.photoURL);
});
}
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
print_user(user);
} else {
google_login_in();
} …Run Code Online (Sandbox Code Playgroud) 这是Swift教程的链接.在初始化 - 覆盖可用的初始化程序部分中 请注意,如果使用不可用的子类初始化程序覆盖可用的超类初始化程序,则子类初始值设定项不能委托超类初始化程序.
但是下面的例子:
class Document {
var name: String?
// this initializer creates a document with a nil name value
init() {}
// this initializer creates a document with a non-empty name value
init?(name: String) {
if name.isEmpty { return nil }
self.name = name
}
}
Run Code Online (Sandbox Code Playgroud)
和:
class AutomaticallyNamedDocument: Document {
override init() {
super.init()
self.name = "[Untitled]"
}
// This is nonfailable override superclass's failable
override init(name: String) {
// Why subclass initializer …Run Code Online (Sandbox Code Playgroud) 当我之前使用源洞察时,当我搜索某些单词时,我可以按"向前搜索"按钮跳转到所有项目文件的下一个匹配.
例如:
但是使用带有cscope的vim,我需要这样的东西:
这非常复杂.
在Vim中有更好的方法吗?
这是Swift教程的链接.
我读了协议部分,我知道协议是用@objc标记的:
@objc protocol CounterDataSource {
optional func incrementForCount(count: Int) -> Int
optional var fixedIncrement: Int { get }
}
Run Code Online (Sandbox Code Playgroud)
这意味着该协议用于指定可选要求,并且只能由类采用
但教程没有说为什么类需要用@objc标记?
@objc class Counter {
var count = 0
var dataSource: CounterDataSource?
func increment() {
if let amount = dataSource?.incrementForCount?(count) {
count += amount
} else if let amount = dataSource?.fixedIncrement? {
count += amount
}
}
}
Run Code Online (Sandbox Code Playgroud)
如果我从类中删除@objc,编译器也没有显示错误消息
那么将@objc添加到类之间有什么不同?