I am writing the app using latest Swift 4.1.2 and Xcode 9.4.1 for iOS 11.4. So I want to use vector images in my app in PDF format. I made the simple app which showing the problem, please, look:
This app only show only one image, but if you rotate the screen, rendering happens and picture becomes beautiful.
So the question is: how to force Xcode render vector images in Main.storyboard without touching the code? So app upload already rendered images?
Go to -> Images.xcassets and select the image. From the attributes inspector, make sure that preserve vector data is checked as following:
I hope it solves your problem.
Xcode 9 changes situation for vector data by allowing you to choose to treat the image as a vector at runtime. This means the image can smoothly scale to arbitrary sizes. The only change you need to make is to tick Preserve Vector Data for the PDF image in the asset catalog.
Xcode 10 Release Notes: "Code Completion for Swift image literals has been removed in Xcode 10"
So it's not a bug that I couldn't add images in the code (and run older projects). How do we then add images from now on in the code as just typing UIImageView(image: won't accept any png or jpeg.
let cellImage: UIImageView = {
let image = UIImageView(image: ???))
return image
}()
System: macOS Mojave
Xcode: Xcode 10 Beta 4
In Xcode 10 and Swift 4.2, only the code completion function (or auto-complete) of the Xcode IDE has been discontinued for the old way. Here is the new way:
Just type image literal and it will complete with default icon.
Double click on this icon and it will open the media library right side of it.
Just choose your imagem and it work like before!
Found the Shortcut to open the Media Library Tab:
⇧+⌘+M
At this point the official documentation does not cover some use cases at Xcode 10 beta so I'm not able to find a way to move the media part to the old position.
You can use Media Library in Xcode to add image literal to your code:
And then choose image from library and drag&drop it to your code
It will create image literal
For the benefit of others with legacy code that utlizes Swift Image Literals, the code and syntax of the image literal function themselves are still valid and work perfectly fine in Xcode 10 with Swift 4.2.
There is no need to rollback or refactor existing code that utlizes these image literals, and they can still be used as follows:
imageView.image = #imageLiteral(resourceName: imageNameString)
Only the code completion function (or auto-complete) of the Xcode IDE has been discontinued.
UPDATE
The difference in image-literal representation in previous and current versions or Xcode/Swift:
image = #imageLiteral(resourceName: "flower.jpg")
As the extract illustrates, image literals were represented in-line with thumbnails of their actual image. However, now, only a generic icon is used in its place. Presumably, this goes towards reducing the burden on the IDE, by eliminating the overheads of handling and displaying the in-line thumbnails.
TIP: To fix three resolutions after add a literal image in code.
1. Remove another, keep only one image
2. Comment your line code with literal image, then will appear literal image in code, like: #imageLiteral(resourceName: "image#2x.png"
3. in resourceName value, remove #2x and file extension, like .png, keep only image name: #imageLiteral(resourceName: "image")
4. Uncomment! Image will be showed in code.
In Xcode 11, the media library is now under View > Show Library (SHIFT+CMD+L).
If anyone using Xcode 11 then you can find all media using below option:
Using
UIImage(imageLiteralResourceName: 'imageName')
won't return an optional and works just fine
Just use #imageLiteral(
It will work
i'm using Xcode 10 beta 4 and i have the same problem !
Resolved using the old way to pass an image
PizzaModel(
nome: "Marinara",
ingredienti: "Pomodoro, Aglio",
calorie: "729",
img: UIImage(named: "marinara")!
)
you can use this code in Xcode 14.1
"UIImageVievName".image = #imageLiteral(resourceName: "imageName")
and then you can click the photo icon, you can chose what you want to add the image.
Just type command+shift+L , you will get the option for image addition.
We used to have an option "Always use Y-Up axis" toggle in Xcode (until Xcode 7 at least, I think).
It's gone in current Xcode 8.2.1, and probably gone since 8.1 or even 8.0. Why? Or is it hiding somewhere else? Any workarounds?
Update: I found a related quote from a WWDC speech, way back in 2014:
The way you add 3D assets to your game is just SceneKit asset
catalogs.
SceneKit asset catalogs are new feature in Xcode 6, SceneKit asset
catalogs are new feature in Xcode 6, and they allow you to organize
and optimize your 3D assets.
The structure of SceneKit asset catalogs is preserved when they are
copied into your target.
Also, they automatically track files that are added to them or removed
from them on disc.
They are really convenient because they can optimize your 3D assets
for you.
For instance, they help with up axis conversion.
SceneKit follows the up axis conversion, which means that the positive
y axis is the one that looks up.
This is a convention that is followed by many other applications and
frameworks, but some exporters do things differently and use a z up
axis convention.
With SceneKit asset catalogs, you don't have to think about that.
We automatically and transparently convert all the animations and
geometries in your scene so that they follow the up axis convention.
Taken from http://asciiwwdc.com/2014/sessions/610
Video at https://developer.apple.com/videos/play/wwdc2014/610/
The above seems to describe the scene kit asset catalog when it was introduced. It doesn't actually answer my question here; why that feature is removed from current Xcode. I can also confirm that no conversion happens behind the scenes. A model exported from Blender is always going to move closer to or away from camera if its Y position is changed. At run-time it is the same.
In Xcode 8, you can Ctrl-click on the .scnasset folder and Open As > SceneKit Catalog. If you make any changes, it will write out a Settings.json file. This may be what you are looking for.
I was wondering if anyone knew if the XCAsset symbols provided in autocompletion can be used in any way, I imagine something but it didn't worked.
Xcode propose all the images, it looks really interesting but if it's just to "show" I would be sad :(
What you're seeing there is an image literal. It's not the name for the image, it is the image — so using one is equivalent to the entire UIImage(named: "icon-stack") call, not just the "icon-stack" string within that call.
If you assign one of these directly to a var or let, you'll see that its inferred type is UIImage (or NSImage if targeting macOS):
we are a bit confused how device cache is working and how it is suppose to be working. Images with an original resolution smaller than what is specified in the request do not seem to be cached at all and every time we call RequestImageForAsset looks like the image is always pulled from the cloud.
When it happens, it also shows an interesting behavior that we did not see it documented. Although RequestImageForAsset callback does not return an error, the expected produced UIImage is nil. The only way to get an image is to request it again with a smaller size.
Photos showing this behavior are shown in "Photos app" with a white dot. Only after forcing a zoom in by double clicking it, that dot disappears and only after that moment we are able to request it properly through RequestImageForAsset.
Any help is welcome
cheers
Manuel
The caching behavior (due to my testing) depends on many factors:
1) if the user has set "Optimize Storage" or "Keep originals" in the Photos Settings
2) How much space is available on the device.
In short: I would not assume any caching behavior. Just use the supplied methods of PhotoKit to request the data/image of the asset.
I have to disagree with you. You have to understand how local cache works to:
1 - according to what you are doing in your app, take some decisions like if you should cache photos yourself
2 - understand the difference between a bug an a feature. Photokit looks nice. However, its implementation has been showing a lot of issues (true bugs) and things like changing from 8.0 beta 5 to 8.0 release master recently added / camera roll which exposes some internal confusion