为什么'自我'在课堂外使用?

时间:2023-01-16 12:14:57

I'm following this tutorial on GitHub on how to implement SwiftyDropbox in an iOS app. There's a point where it tells me to add this code to my ViewController

我在GitHub上关注如何在iOS应用程序中实现SwiftyDropbox的本教程。有一点告诉我将此代码添加到我的ViewController中

import UIKit
import SwiftyDropbox

func myButtonInControllerPressed()
{
    DropboxClientsManager.authorizeFromController(UIApplication.shared, controller: self, openURL: { (url: URL) -> Void in UIApplication.shared.openURL(url)})
}

I then get an error saying

然后我得到一个错误说

Use of unresolved identifier 'self'

Presumably this is because I'm declaring a function outside of a class. What am I doing wrong? Does anyone know of a tutorial/sample-app that actually works and is up to date with the latest Swift and Xcode that could teach me how to use SwiftyDropbox?

大概这是因为我在课堂外声明了一个功能。我究竟做错了什么?有没有人知道一个实际工作的教程/样本应用程序,并且是最新的Swift和Xcode可以教我如何使用SwiftyDropbox?

1 个解决方案

#1


2  

The paragraph before that snippet does say

该片段之前的段落确实说过了

You can commence the auth flow by calling authorizeFromController:controller:openURL:browserAuth method in your application's view controller.

您可以通过在应用程序的视图控制器中调用authorizeFromController:controller:openURL:browserAuth方法来启动auth流程。

为什么'自我'在课堂外使用?

So it is telling you to write that snippet INSIDE your View Controller (where using self makes sense).

因此,它告诉您在视图控制器内部编写该片段(使用self时有意义)。

Here's an example

这是一个例子

class Controller: UIViewController {

    func myButtonInControllerPressed() {
        DropboxClientsManager.authorizeFromController(UIApplication.shared,
                                                      controller: self,
                                                      openURL: { (url: URL) -> Void in
                                                        UIApplication.shared.openURL(url)
        })
    }

}

#1


2  

The paragraph before that snippet does say

该片段之前的段落确实说过了

You can commence the auth flow by calling authorizeFromController:controller:openURL:browserAuth method in your application's view controller.

您可以通过在应用程序的视图控制器中调用authorizeFromController:controller:openURL:browserAuth方法来启动auth流程。

为什么'自我'在课堂外使用?

So it is telling you to write that snippet INSIDE your View Controller (where using self makes sense).

因此,它告诉您在视图控制器内部编写该片段(使用self时有意义)。

Here's an example

这是一个例子

class Controller: UIViewController {

    func myButtonInControllerPressed() {
        DropboxClientsManager.authorizeFromController(UIApplication.shared,
                                                      controller: self,
                                                      openURL: { (url: URL) -> Void in
                                                        UIApplication.shared.openURL(url)
        })
    }

}