【问题标题】:Twitter.sharedInstance() does not exist swift TwitterKitTwitter.sharedInstance() 不存在 swift TwitterKit
【发布时间】:2018-06-05 03:49:52
【问题描述】:

我是 Xcode 和 swift 新手。

我已经开始使用 TwitterKit,我已经使用 cocoapods 将它安装在我的项目中,我遵循了这个教程:https://dev.twitter.com/twitterkit/ios/installation

问题是,当我尝试在 AppDelegate 中初始化 TwitterKit 时,我无法使用 Twitter.sharedInstace,因为 Twitter 不存在。 (我已经使用 import TwitterKit 在 AppDelegate 中导入了 TwitterKit)

这是我的 App Delegete 课程:

import UIKit
import TwitterKit
import Firebase
import FirebaseAuth

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        Twitter.sharedInstance().start(withConsumerKey:"********", consumerSecret:"*******") 
        //Here I get the error: Use of unresolved identifier 'Twitter'       
        return true
        }

我做错了什么?

【问题讨论】:

  • 使用cocoapods时,需要打开workspace而不是project。你这样做了吗?
  • 使用 cocoapods 时,您需要构建一次项目,以便创建框架,然后您可以开始使用 TwitterKit
  • 感谢阿卜杜勒!这解决了问题!

标签: ios swift twitter cocoapods twitterkit


【解决方案1】:

如果您使用 Swift 4,您几乎需要使用 Twitter.sharedInstance() 的 TWTRTwitter.sharedInstance(),因为 Twitter 类已被 TWTRTwitter 替换。使用对象 C,您就没有这个问题,因为有一个宏隐藏了这个变化。不幸的是,“dev.twitter.com”尚未更新。

【讨论】:

  • 是的,在目标 C 中,po [Twitter sharedInstance] 是一个无法识别的对象并给出错误,我想知道为什么,但 po [TWTRTwitter sharedInstance] 有效。你的回答帮助我知道尝试 TWTRTwitter
猜你喜欢
  • 2016-01-30
  • 1970-01-01
  • 2017-04-13
  • 2018-04-16
  • 2015-12-16
  • 1970-01-01
  • 2018-04-08
  • 1970-01-01
  • 2018-06-09
相关资源
最近更新 更多