Assets cannot be found

Prior to xCode 9, when I wanted to create a UIImageView with an image, I would drag the image onto the project panel and create a UIImage with the name of this file. It worked and everything was fine.

However, this will not work with Xcode 9. He will not be able to find this file, even if it is in the main set. I needed to put the image in the Assets folder, and then he was able to find the image and show it in UIImageView.

Similarly, when working with the Sprite Kit, I would create a folder on my desktop with the extension .atlas, drag all my images into it and drag the folder .atlas into the project. Then I will create SKTextureAtlas with the folder name .atlas, and it will work. However, with Xcode 9, this did not work again. I would get the message "Texture Atlas" foo "could not be found" in the console. So I went to the Assets folder, clicked the Add icon and selected the New Sprite Attribute, renamed this folder and dragged my images into it. A texture atlas with this name has now been created.

What I'm trying to do now and have problems creates SKVideoNode using init (filedNamed: "foo.mov"), and you guessed it no longer works if you dragged the file to the sidebar project. So I thought, maybe I need to do it again somehow through the Assets folder. I found that when I add my .mov file to the Assets folder, it is created as a “Data Type” (“Data” is displayed in the upper right corner of its window in the “Assets” folder). Now I can do the following:

let d = NSDataAsset(name: "foo") // 'foo' is the .mov file in Assets
d.data // the underlying content

It turns out d is not null, which was good news, but the only way to access the underlying content is simply using .data, and you cannot create SKVideoNode with data. I also wanted to download the sound file that I used for this:

let a = SKAction.playSoundFileNamed("bar.mp3", waitForCompletion: false)

" :" bar.mp3 ".

+4
1

, .

" ", , " " enter image description here

+3

Source: https://habr.com/ru/post/1686662/


All Articles