Xcode 8 Image Completion - ios

In Xcode 8, you have images autocompleted while typing.
Question is : Why?
I tried to init UIImage with the suggested result, but it doesn't work.
Does anyone know how to use it ?

Xcode 8 will automatically recognize any images you’ve got in an Asset Catalog and offer them up as a suggestion inside of a UIImage initializer.
So basically what you need to do is just the following (as you have done in your question, but there must be something else that´s disturbing it):
let i = voiture // image name
And then just use i when you want to set an image.
Under the hood it’s creating code that looks like this: #imageLiteral(resourceName: "voiture.png"). But inline in the source editor, you’ll just see the file name of the image. The #imageLiteral syntax is only recognised on Swift 3 or later.
Here is a demonstration video link where I do this and here is a link to a sample project that I created.
Note that you need to click on the instellisense suggestion so that you see a thumbnail of the image in the code and then the image name.
Update 1
This functionality remains in Xcode Version 9.0 beta 6 (9M214v)
Update 2
Xcode 11.2.1, this is not appearing anymore.

An image literal already is a UIImage, you don't need to pass it to a UIImage to initialize one.

I'm unable to find an "official" source for it, but from my personal testing it appears that while the autocomplete works in both Swift 2.3 and Swift 3.0 projects, image literals will only work correctly in a Swift 3 project.
Give it a try in a Swift 3 playground and you'll find it works just fine.

I have been using this feature. Basically if I have an image that begins with "ic", I would type let i = followed by ic. At this point, Xcode 8 will show a dropdown of images and I then choose the correct image from the list. I have never bothered to actually type UIImage(. It works just like autocompleting code except that it uses the filename of the image.
In your case, there is probably some other issue causing the compilation to fail.

Related

Xamarin iOS Splashscreen not showing

If followed these instructions: https://learn.microsoft.com/en-us/xamarin/ios/app-fundamentals/images-icons/launch-screens?tabs=macos
The LaunchScreen never shows up. I am using VS2019 for Mac current build. Followed all instructions to the letter.
Update:
github sample project as requested.
https://github.com/tpitman/Xamarin-Forms-SplashScreenTest
I created a new cross platform forms solution. I downloaded an image of the Xamarin logo. The project already has a LaunchScreen.storyboard. It also already had an image view object, but I deleted that and added a new one because the steps on that link above said to add one. I also added the label just like those instructions say.
You will notice when you run it that the label shows up, but the image does not. That is the problem. In my app I don't have or need a label. I just have an image I want to show.
Update 2:
I deleted the above repo. Created a new project including Android this time (not sure that matters, but it represents my real situation).
I also changed the image I used from the stock one to my own in case that matters.
I then built it and it does NOT work as the original one didn't. Hopefully it won't work for you as well.
I also created a video of it not working. Here is the link to that video:
https://drive.google.com/file/d/1Uy0KfDq0_5IfrqDDaMVDNeGylibzUH5m/view?usp=sharing
Update 3:
In the end I am not sure what fix it. I removed and reimported the images. I have 3 projects and 2 of them work fine now using the Assets.xcasset method and the other one I couldn't get to work that way, but works with the images being in the Resources folder.
I think one thing that I did that seemed to make a difference was I did a clean and then build and that seemed to fix it.
I have checked the shared github sample project, it works in my local site. Both in VS for Mac (8.8.4) and VS for PC(16.8.3).
==================================Update================================
There is a workaround to solve that, you could add Image to Resouces directly.
Then use it in LaunchScreen.Storyboard, then it will show:

Is there a way to turn off Xcode 8's autocomplete for image names?

Xcode 8 has this new feature that is supposed to suggest image file names when you use UIImage(named:)
In my case it suggests image names even when it doesn't make any sense.
Example:
There is nothing in preferences. I wonder if there is some secret command to disable this part of autocompletion.
No this unfortunately can't be turned off, and nothing states that this is fixed in the Xcode 8.1 Release Notes.
It should either be fixed or you should have the opportunity to turn it off. The functionality is kind of good when it´s used for it´s purpose only, as I describe in this post.
But the issue is that Xcode 8 is inserting images inline in source when it can't possibly make any sense as you mention. For example, if you have a for iteration and type for x in to start a loop and you have any image in the project whose name matches "in" using this syntax.
Annoying issue, that I hope Apple will fix soon, because the feature is good when it´s used for images only.
Update:
Just confirmed that this is still an issue in Xcode 8.1 stable version.
Update:
This functionality remains in Xcode Version 9.0 beta 6 (9M214v)
Update
This seems to be fixed in Xcode 10 now.
It seems to me that the best way to deal with this issue is by using comments (commmand + /). Changing the code to become a comment seems to turn off the autocomplete for image names.
So, you would have basically to switch back and forth between commenting and uncommenting your code (e.g. you find an error, make your code as a comment, fix the error, uncomment your code, check if your changes fixed the issue, and so on.).
Example of the same code with and without being a comment.
Simply update to Xcode 10: the image autocompletion feature has been discontinued:
Code Completion for Swift image literals has been removed in Xcode 10. (38087260)
Source: the Xcode 10 Beta release notes (this note was removed in the final release notes)

Issue converting from Swift 2 to Swift 3 in Xcode 8

So I updated to Xcode 8 and when prompted to convert my source code to Swift 3 I said yes. I forget what I did after that, but for some reason my code is back to the way it was. Now when I try to convert it again, Xcode tells me that i already converted it so I cannot do it again. Is there any way to reset this convert feature or trick it to convert again?
There is no way if you are not using version control.
Follow this link (
How to Convert my Swift Code back to 2.3 ) for better understanding.
For anyone that is interested I found a workaround. First, create a new project and then copy your source code file(s) into it. Second, hit Edit -> Convert -> To Current Syntax. At that point either stay within the new project or copy your code back to your original project.

Cannot load PNG image as UIImage

I am trying to load a .PNG image located in my XCode project as UIImage - but the constructor of UIImage that takes file name returns nil.
Please see the screenshot for my setup:
Here are some details:
The project is in Swift
I am constructing the UIImage in global variable (lazyly)
The issue is pressent in simulator and on the device (iPhone 5S)
I have added same image several times with different names to make sure incorrect naming is not the cause (see all the names in left red rectange)
all images are added to EasyTypeShared target, which is a library project embedded into runeable EasyType project.
I did not do any axtra steps - just added the image files to my workspace (and the EasyTypeShared target) and run the app
EDIT: According to this blog the cause might be that workspace setup - more preciselly that the image is being loaded by framework. Not sure but in lack of better ideas I will follow this track. If you can cast some light on the matter I would by really thankful for any ideas.
The problem was caused by the fact that code loading the image from resources resides in framework. Main bundle does not contain resources for the framework, the corresponding bundle needs to be used. Working code:
private let imagePlaceholder = UIImage(named: "ImagePlaceholder.png", inBundle: NSBundle(forClass: CarretMoveController.self)
Are these part of the images.xcassets? If not they will have to be read using NSBundle and getting a path/URL for the resource and all that and a simple filename will not suffice.
You can add the files to the assets as per the Apple documentation here. Relevant section might be the 'Adding Image Sets' one.
If you do not have images.xcassets, you can add it to your project as per one of the answers given here.
in your project explorer I can see that images are not named properly.
it should be like this:
imagePlaceHolder.png
imagePlaceHolder#2x.png
notice the png at the end of the file name, and #2x before the file extension.

Extension project templates not appearing in Xcode 6

I'm not sure if I am the only one experiencing this program, but I have tried searching and have not been able to find anyone in my current situation. I downloaded Xcode 6 beta and was interested in Extension programming for iOS 8. However, I have been unable to locate the extensions in my project templates when creating a new project in Xcode, I saw a YouTube video (unrelated to extension programming) but I did notice that the option was not there for the said video. Now, I have had a look through the contents of the Xcode 6 beta package and have been able to locate the actual templates themselves, so I have no doubt they are present, it just seems that they are not actually being loaded.
For the record, I also downloaded some example custom keyboard code from GitHub in order to see whether Xcode will recognise it and it does, going as far as actually displaying the 'E' icon beside the build target. I should also mention that I do have a build of Xcode 5 also present on my machine.
Is anyone else experiencing this issue, or does anyone know how to overcome it?
Thanks
You create a extension by creating a new target in an existing project.
Check this link for more information
I had the same problem. The solution was to not try to add the extension in File/new/File... menu but in File/new/Target... menu.
You can add extension to any existing project.

Resources