如何将文件添加到项目并引用它? [英] How to add file to a project and reference it?

查看:282
本文介绍了如何将文件添加到项目并引用它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的是iOS开发的新手,所以这个问题可能很愚蠢,但是我没有找到答案.

I'm really new to iOS development, so this question might be silly, but I didn't find an answer for it.

我在iOS设备的swift中有一个项目,我想在项目中包含一个csv文件,然后在代码中使用它,如何将这个文件添加到项目中,然后在viewController类中使用它?

I have a project in swift for iOS device and I want to include a csv file in my project and then use it in code, how can I add this file to the project and then use it in viewController class?

这是我的项目结构(是的,非常简单)

this is my project structure (yes, it's very simple)

这就是我要在代码中尝试做的事情,但这是行不通的.

and this is what i'm trying to do in code, but it doesn't work.

谢谢:)

推荐答案

您可以通过拖放将资源文件添加到项目中.这样做时,将出现一个弹出窗口,您需要在其中选择目标以将其与当前目标链接.

You can add a resource file to project by just drag and dropping. When you do so, a popup will appear, you need to select your target in it for linking it with your current target.

在您上面的代码中有一个错误.您只需在pathForResource:方法中指定不带扩展名的文件名即可.

In your above code there is a mistake. You only need to specify the filename without extension in pathForResource: method.

代替:

let file = "europe_dancing.csv"

您只需指定:

let file = "europe_dancing"

这篇关于如何将文件添加到项目并引用它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆