Add images in project in new Xcode 9 - ios

In new Xcode 9 I want to add images in project. But If I add images and try to use it in code or in storyboard my images not showing in simulator. But in Xcode 8 all works fine. How to fix it?

Note : This Problem does not Exist Anymore in newer XCode
If you have dragged image in your project, you must select Copy If Needed While adding any file into your project.
After Adding Image take a look at your image if it is available to target, I have face similar issue with other file types too.
In xcode9 it was not selected by default even after selecting copy if needed.

Yes - this is super annoying. With XCode 9, now in addition to dragging a new image into the XCode Project Navigator (the left-hand list of files), you now have to go into Targets for your project, go to "Build Phases" and manually add the image file to "Copy Bundle Resources" using the "+" button at the bottom of the list of files.
This is required for any object you used to have to just drag into the project, including third-party frameworks and bundles.
PS: in dragging the image into your project you don't have to have "Copy Item if needed" selected if the image file is already somewhere in your project folder or a subfolder thereof.

If you have to handle multiple images, it is probably more convenient to copy the resources to your target app in the General Settings > Build Phases > Copy Bundle Resources
Copy Bundle Resources
This does the same as checking Target Membership for the resource – but you can add multiple images to your target app at once.

Check release notes of XCode 9.1:
Adding files to a project now adds them to the selected targets. (34551617)
https://developer.apple.com/library/content/releasenotes/DeveloperTools/RN-Xcode/Chapters/Introduction.html

Related

Unable to find style.json when Implement Google Maps Styling JSON for iOS [duplicate]

I'm trying to add some new resource files to a project which was build by another person on another mac. I think that the project has the provision of the previous person.
Using right click->Add Files to "MyProject" doesn't provide the expected result. After I compile the project, the added file is not visible in the application.
How can I add new resources in my project?
PS: I'm trying to learn Objective-C in a macincloud.com account.
It might be that the file you added was not added to the project build. Click your project > App target > Build Phases
And check that the file exists in Compile sources (if it needs to be compiled), otherwise check Copy bundle resources. If the file does not exist there, drag it there and it should be fine, (from what I understand of your question).
EDIT
You can also check wether a file is added to the target by clicking the file and opening the "File Inspector" (View > Utilities > Show File Inspector, or ⌥ + ⌘ + 1), and check the Target Membership section.
Example:
Adding to Copy bundle resources worked for me
Just drag the resource file (from a finder window) into your project files area (left side) and drop in supporting files.
Once you drop, a dialog will prompt you which targets to add it for. Select all that are appropriate. Thats it.
Just had a similar experience with Xcode Version 11.7 (11E801a), which I mention as it may help others from wasting a day and a half.
In addition to the other answers explaining how to add the resources:
For me the problem was I had my resources listed in Developer Assets under the target's General tab, but also in the Build Phases/Copy Bundle Resources. This worked fine running through Xcode in simulators and even on devices, but when I came to Archive the app, the resources were not being copied. Deleting my resources from the Developer Assets list, but keeping them in Build Phases worked.
And in the end it turns out I only need the resources in the Build Phases section for either running through XCode or Archiving !

Could not load the image referenced from a nib in the bundle with identifier

Copy items if needed -> Done
Case sensitiveness -> Taken care
Image is inside the project folder.
What can be the problem here?
Xcode version 9.0
I solved it by importing the image into assets (Assets.xcassets) and referencing it from there.
Looks like the build process in Xcode 9 no longer copies the images outside of xcassets into the bundle by default, so simply drag & drop doesn't work
As an alternative, although more cumbersome in my opinion, you could add them manually in the project Build Phases > Copy Bundle Resources
I had the same error , Click on a picture file in Xcode. in attribute, on bottom you'll see Target membership. Check the box and it is gonna work. it worked for me . try it once .
Select image in Xcode, then on right side go to File Inspector check the target as follow image:
https://4.bp.blogspot.com/-_Ixa-3TkOR0/Wcn02iGYxJI/AAAAAAAADZE/DaOs9eutj4IH_lOl7DxMtF14btsw8oCpQCEwYBhgL/s1600/Screen%2BShot%2B2017-09-26%2Bat%2B11.55.37%2BAM.png

How can I add file to project in Xcode 9?

I created a new project in xcode 9.
I want to add image file to project.
When I delete this file from desktop,
Image file appears in red?
But in project folder, I find this image file.
In Xcode 8 its working fine,
Any idea?
It is an Xcode9-beta (9M136h) bug. I don't know if it has been resolved in beta3 or not. Copy items if needed copies the file to your project directory but still links to the original file.
What I do is, after dragging the file to my project, I select the folder icon (see red circle in the image below) from File Inspector and point to the copied file in the project directory.
#pesch's approach works too. First copy the image to your project folder and then drag it to Xcode.
Xcode 9 allows to have folders in Xcode synced with folder in your Finder structure. I assume this is a bug since Xcode 9 is still in beta and you are "ticking" the Copy items if needed.
Try moving the image to your project folder yourself and drag it from there to Xcode.
This is what you would do to leave the Copy items if needed box unticked since you are doing it yourself.
It looks like a XCode 9 bug. If you check the Full Path of your image file in Identity and Type Tab, it would show the location of the deleted file, hence the deleted(red) color.
You can delete that reference and can use Add File To.. option to add the reference of (already) copied image from your source folder.
Although this is not resource related (images, etc). The issue that I'm currently facing with the Xcode 9.0 GM build is that adding the items to the project does not actually added them to my targets, although I selected them.
Step 1 - Add Files to Project
Add New Files and Select your targets
Step 2 - View Files in File Inspector
You can clearly see in the file inspector that it is not added to those targets accordingly.
Step 3 - [Fix] Add New Added File to Targets
To Fix this, just check the targets that the files should be added to and you should be good :)
I have seen this issue in Xcode 9.0 GM (build 9A235, same as the current release). It's intermittent; sometimes 'Copy items if needed' is honored, sometimes not.
In one case it seemed to be triggered by the presence of source control. I was working through an online tutorial where the provided project had no source control. Adding files here did honor the 'copy items' checkbox, but if I made the provided project a git repository first, adding files ignored the checkbox every time.

Xcode 6: No Frameworks Folder in Project Navigator

I am using Xcode 6 and following an Xcode version 4 tutorial so things are different here and there.
There doesn't seem to be a Frameworks folder in my project navigator and so when I downloaded some .framework files and added them manually in the build phase of my project editor, I had no Frameworks folder to save them in and just let them fall into the top of my project navigator. So they are there, just not in a special folder, and it doesn't look good.
So should Xcode 6 have a frameworks folder automatically, or do I need to create one myself? And if so, how can I do that? (I've only added new files so far).
In Xcode 6, the Frameworks folder is not added by default. You can drag and drop your .framework files into the project navigator (tick 'Copy items if needed'), then select them all > right click > "New Group from Selection" and name the folder 'Frameworks'.
Also, make sure the frameworks are added into the Project > Build Phases > Link Binary With Libraries. If not, drag them there from your newly created 'Frameworks' folder.
In short, no, you shouldn't need to create a Frameworks group yourself as Xcode is doing stuff automatically for you...
Apple are slowly, gently pushing developers in the direction of newer Clang features with the goal of making native iOS development more approachable for newbies who don't have previous experience of compiling and linking with C-based languages.
You'll find that Objective-C projects created with Xcode 6 have new build settings enabled by default including Link Frameworks Automatically (CLANG_MODULES_AUTOLINK) and Enable Modules (C and Objective-C) (CLANG_ENABLE_MODULES).
Suggested reading:
Modules (Clang documentation)
#import vs #import - iOS 7 (excellent Stack Overflow answer)
I found the other answers too confusing (where am I supposed to get .framework files?)
It's way simpler in Xcode 6. Just go to Capabilities and turn Maps on. That's it... really.
I would recommend using drag and drop feature to move files into Xcode. Xcode show you the Choose options for adding these files window [Copy items if needed] [Added folders]
For example Xcode can automatically add relative path ($(PROJECT_DIR)/) to:
Build Settings -> Library Search Paths if you drag and drop a library
Build Settings -> Framework Search Paths if you drag and drop a framework

How to update a framework in an iOS app?

I'm writing an app using Nuance's SpeechKit framework. I've just downloaded a newer version of the framework that contains new methods in some of the classes. To upgrade, I deleted the framework and the re-added the new one. When I right-click on the framework in Xcode and click "reveal in finder", it shows the new framework. When I open up the "Headers" subfolder of the framework in Xcode, I see the new methods.
The problem is that my class seems to still be referencing the header file in the old location, as the new methods are not visible within my application.
How do I upgrade a framework properly? Is there somewhere else in Xcode that contains a path reference to the SDK?
You need to delete Derived Data for the project - it is an option of the project in the XCode Organizer, on the projects tab. It will remove the cached build of the framework, forcing XCode to use the new one.
Choose Window/Organizer from the top menu
Click "Projects" pseudo-tab-thing, along the top of organizer window (icon looks like an XCode project file"
Select the project from the list on the left
Click "Delete" next to "Derived Data" in the area immediately below the project info header.
List item
EDIT: as of XCode 12 (should work with Xcode 8 and above), you can delete derived data like this:
Go to File > Workspace Settings if you are in a workspace environment or File > Project Settings for a regular project environment.
Then click over the little grey arrow under Derived data section and select your project folder to delete it in Finder.
I found what cause this issue for us.
When you build a new version you must update "Current Library Version".
There is also a "Compatibility Version"
In Xcode selector your framework target and in build settings search for linking and you will se this setting there.
We created a build script to bump this version number every time we build.
Xcode caches the frameworks and uses the cache if possible. That's why you need to change this number.
If you are using CocoaPods, run pod update [PODNAME].

Resources