小编CK *_*vir的帖子

Firebase Google登录(网络)流程

引用此链接

大家好。这是我的代码,我有两个问题

首先,我想知道我的登录流程是否正确?

我的逻辑是当用户进入我的索引页面时

我将首先检查用户登录状态

如果用户未登录,则要求用户登录。

    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)

javascript web firebase firebase-authentication

3
推荐指数
1
解决办法
2839
查看次数

覆盖Swift的可用初始化程序

这是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)

xcode ios swift

2
推荐指数
1
解决办法
2660
查看次数

Vim转到多个文件的下一个搜索结果?

当我之前使用源洞察时,当我搜索某些单词时,我可以按"向前搜索"按钮跳转到所有项目文件的下一个匹配.

例如:

  1. 搜索"苹果"
  2. Source Insight列出所有项目包含"apple"字样(例如:15结果)
  3. 按"搜索前进按钮"
  4. 光标跳转到下一个搜索结果,根据需要重复以查看所有15个结果

但是使用带有cscope的vim,我需要这样的东西:

  1. :cs找到"苹果"
  2. cscope list 15结果
  3. 输入"1"并跳转到第一个结果
  4. :cs找到"苹果"
  5. cscope list 15结果
  6. 输入"2"并跳转到第二个结果

这非常复杂.

在Vim中有更好的方法吗?

vi vim

2
推荐指数
1
解决办法
2737
查看次数

Swift类添加"@objc"为什么

这是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添加到类之间有什么不同?

xcode ios swift

1
推荐指数
1
解决办法
1186
查看次数

标签 统计

ios ×2

swift ×2

xcode ×2

firebase ×1

firebase-authentication ×1

javascript ×1

vi ×1

vim ×1

web ×1