简体   繁体   English

使用未解析的标识符'PFUser'-Swift / Xcode / Parse

[英]Use of unresolved identifier 'PFUser' - Swift/Xcode/Parse

I am trying to query the users in my Parse DB into my Table View Controller in my app in Xcode. 我正在尝试将我的Parse数据库中的用户查询到Xcode应用程序中的Table View Controller中。

I am a beginner, but I have posted my code snippet from my added .swift file to my project. 我是一个初学者,但是我已将添加的.swift文件中的代码段发布到我的项目中。 I am trying to query the user in the .swift file but it is not recognizing 'PFUser' from my View Controller. 我正在尝试在.swift文件中查询用户,但无法从我的View Controller中识别“ PFUser”。

Do I need to declare the PFUser as something in my .swift file before first calling it in my ViewDidLoad method? 在首先在ViewDidLoad方法中调用PFUser之前,是否需要在我的.swift文件中声明PFUser?

Any ideas? 有任何想法吗?

Code snippet: 程式码片段: 程式码片段

You need to import the Parse-Framework in your project. 您需要在项目中导入Parse-Framework。 Check this quickstart-guide how to do it . 查看此快速入门指南如何操作

If you've done it already, you need to import Parse in your File like that: 如果已经完成,则需要这样在文件中导入解析:

import UIKit
import Parse

Like you/Xcode has already done that with the UIKit. 就像您/ Xcode已经使用UIKit一样。

  1. First put Parse SDK into the folder into your project navigator area of Xcode. 首先将Parse SDK放入Xcode项目浏览器区域的文件夹中。

  2. You will get a Dialogue, You will need to check the box that says copy items if needed and then click Finish. 您将获得一个对话,如果需要,您将需要选中显示复制项目的框,然后单击完成。

  3. The next thing we need to do to connect our Swift app to parse.com is create a bridging header. 将我们的Swift应用程序连接到parse.com的下一步是创建桥接头。 To do this you need to create a new File (File -> New -> File) of type Objective-C File. 为此,您需要创建一个Objective-C File类型的新文件(File-> New-> File)。 Call this whatever you like. 随便叫这个。 Here I have just called it testDataCustom. 在这里,我刚刚将其称为testDataCustom。 You will see another Dialogue that looks like having this Line at the top "Would you like to configure Objective C bridging Header?" 您将在另一个对话框中看到该对话框,该对话框的顶部是“您要配置Objective C桥接标题吗?”。 Click on Yes. 单击是。

  4. Now it will add some new files to your project. 现在它将为您的项目添加一些新文件。 Click on the File: testData-Bridging-Header.h. 单击文件:testData-Bridging-Header.h。 You should see this: 您应该看到以下内容:

      // Use this file to import your target's public headers that you would like to expose to Swift. 

5.Underneath this comment code we need to add an #import so that our project knows to use the Parse iOS SDK. 5.在此注释代码下,我们需要添加#import,以便我们的项目知道使用Parse iOS SDK。 To do this we simply add a line into this file, like so: 为此,我们只需在该文件中添加一行,如下所示:

#import <Parse/Parse.h>

Now you can successfully use Parse methods and properties. 现在,您可以成功使用Parse方法和属性。 Referred from this Link 从此链接引用

You have to import the proper Parse file. 您必须导入正确的解析文件。 :) :)

I don't know Swift but I assume that of you type 我不了解Swift,但我认为您输入

 Import Parse.h 

It will autocomplete for you. 它将自动为您完成。

From what I know in objective-c, you might need to import 根据我在Objective-C中了解到的情况,您可能需要导入

Import <Parse\Parse.h>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM