我可以访问文件系统上的xcassets目录吗? [英] Can I access an xcassets directory on the filesystem?

查看:239
本文介绍了我可以访问文件系统上的xcassets目录吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在xcassets目录中动态加载所有图片。这些文件命名为StockPhoto#其中#是列表中的数字。如果我可以访问我的StockPhotos.xcassets在运行时计数所有的目录中的文件,我不会手动加载文件每次我添加新的股票照片。

I would like to dynamically load all images in an xcassets directory. The files are named StockPhoto# where # is the number in the list. If I can access my StockPhotos.xcassets at runtime to count all the files in the directory, I won't have to manually load the files each time I add new stock photos.

如果这个问题还有其他解决方案,我也很开心,但我也很好奇文件系统如何处理xcassets - 只是引用一组文件,或者实际上是自己的目录。

If there are other solutions to this problem, I'm open to that but I'm also just very curious how xcassets are handled by the file system- whether they're just reference to a set of files, or actually their own directory. Information on this is sparse.

推荐答案


如果这个问题还有其他解决方案,打开到

If there are other solutions to this problem, I'm open to that

问题是在运行时没有内省到资产目录:它不是一个东西你可以看到到Objective-C和Cocoa Touch。

The problem is that there is no introspection at runtime into an asset catalog: it isn't a "thing" you can "see" as far as Objective-C and Cocoa Touch are concerned.

这种问题的通常解决方案是将一个包含图像的文件夹拖到项目中则在对话框中选择为任何添加的文件夹创建文件夹引用 - 为任何添加的文件夹创建组。结果是文件夹被复制到您的应用程序包中,现在您可以使用普通的文件系统方法来说这个文件夹中的每个文件。

The usual solution to this kind of problem is to drag a folder full of images into your project at the outset, and when you do, choose "Create folder references for any added folders" in the dialog - not "Create groups for any added folders". The result is that the folder is copied into your app bundle, and now you can use ordinary file system methods to say "every file in this folder".

这篇关于我可以访问文件系统上的xcassets目录吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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