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.
Related
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.
In swift 4 or even in previous version we can get the complete image though this code
ProfileImg.Image = marker.png
etc but In swift 4.2, we can only have
UIimage.init(named: "marker")
Is it a version mistake or removed by own.???
From the Xcode 10 beta release notes:
Code completion for Swift image literals was removed in Xcode 10. (38087260)
I imagine this was because the image literals were appearing in the completion list for everything and not just when the context involved UIImage, which was driving everybody crazy. Or maybe it's because the new editor can't accommodate the display of image literals.
The feature will either be restored in a future release or will be abandoned altogether. Time will tell!
When you started to write mar.. you ll see the picker that contains your image in the assets. You can pick from here directly.
HELLLPPPPP!!!!! I am programming in Corona SDK, and I am trying to insert a backround image, with the following code ---local backround = display.newImage("bluebackround.jpg")--- But it does not want to show up in the simulator. It keeps giving me the following message in the output, ---Failed to find image 'bluebackround.jpg'---. My image is saved in the project folder. I am using Microsoft Windows software. I have done another project using Corona, and I inserted images completely fine. Anyone know what's going on with my code and how to fix it? Thank you very much in advance.
_W = display.contentWidth;
_H = display.contentHeight;
local image = display.newImageRect(--[["Name", width, heigth]] "bluebackround.jpg",_W, _H)
image.x = _W/2;
image.y = _H/2;
The your image need to be in the same folder as main.lua in your case. On the same level. Moreover, I think you misspell name of your image. You write 'bluebackround' without letter g in middle. So check name of the file.
From Corona documentation
Image guildelines:
Corona supports PNG and JPG format,
Images should not contain an embedded ICC profile,
Avoid progressive JPG files since they will take much longer to load.
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):
Using Xcode 4.3.2 I am unable to add color values by rgb. The standard picker looks like this
Which does not offer any input for rgb or have any sliders allowing me to set anything else.
The custom picker at this location http://www.panic.com/~wade/picker/ instructs me to install at
/home/Library/ColorPickers.
However home is not editable. So I placed it into
/Users/username/Library/ColorPickers
which does nothing. (Is this correct?) Can anyone explain how to properly install this? Thanks
I use this tool and it works fine, /home is referring to /Users/Username so you did place it in the right folder.
If the tool still isn't working then you will need to restart Xcode and possibly even the computer.
After that you simply open the standard picker in Xcode, it isn't replaced, a new tab is added to it.
Additionally, you can always manually specify RGB values in code, for example:
[myLabel setTextColor:[UIColor colorWithRed:235.2/255 green:150.7/255 blue:35.1/255 alpha:1.0]];
The values are x/255 because UIColor expects a float value between 0 and 1 and this is an easy way to convert the standard RGB 255 values down to 0-1.
I had the same problem, and it's simply that your Toolbar is not showing. Go to View->ShowTool bar and you should now see a tab bar of color picker options. For more information on installing custom color pickers, visit https://developer.apple.com/library/mac/documentation/cocoa/conceptual/DrawColor/Tasks/AddingColorPickers.html