Which folder to put the App and Scene Delegate files in Swift? - swift

I am having a problem to decide on which folder to put the app and delegate in.
My project structure is like this.
Should I create a folder for each of them with their names or create a folder called "Supporting files" ? Can someone give me an advice ?

I usually keep them in my root folder as the rest of the app goes into their own folders.
This is a question of preference I believe that there is no wrong answer here as long as the code inside the files is correct.

Related

Xcode Build Input File Cannot Be Found

I decided to move my controller to a folder inside of the controller folder for better organization. After doing so, I am getting a "Build input file cannot be found '/Users/.../Xcode/Development/.../.../Controller/ProfileController.swift'
I looked for an answer to this thinking this has happened a lot but the only thing turned up was missing info.plist files which I believe this is different. I moved my file to '/Users/.../Xcode/Development/.../.../Controller/Dashboard/Profile/ProfileController.swift' which caused this issue.
Any idea how to resolve this? I'm assuming you can nest folders and that shouldn't be an issue.
This looks like your Xcode project is referencing a file with an absolute path instead of relative path.
Check on "build Phases" -> "Compile Sources" if the file is listed and maybe greyed-out or duplicated. Remove all those entries from the list, remove the file from the project tree (without trashing it) and re-drop it into the project.
Check again the file in the "Compile Sources". Now there should be once. Build.
Not sure why it resolved itself but after restarting my Mac, I created another TestController inside of the new folder I wanted to reference, assigned that controller to the storyboard and finally I removed the TestController and placed my ProfileController back into the storyboard it started working.
Just thought I would post my solution for others in case it is helpful.

How to correct the Xcode bug of creating lproj folders in the en.lproj folder?

I had a Localizable.strings file in my project for which I wanted to add more localizations.
So I went to the Project Settings and clicked the "+" to add languages. Somehow I cannot do that anymore on the right panel as there is no "+" button.
Xcode creates the cn.lproj folder inside the en.lproj folder in the file system which is messy but some other lproj folders such as de.lproj do get created where they belong.
How can I move an xx.lproj folder to where it belongs without breaking everything in Xcode? I am afraid leaving them where xcode is putting them can cause errors at run time because cn.lproj should not be a sub-folder of en.lproj.
As it turns out it's an Xcode bug, but fortunately it can be resolved.
First step is to backup your project. Then move the wrongfully placed lproj folders out of en.lproj and if you want, put all of them in a localized subfolder.
Then delete all the link-broken files (red) from the Project Navigator. For the stacked files that have an arrow you will have to delete the root item. Do not choose "Move to Trash". Then make sure in the Project Settings you have all the localizations you want. Drag the "localized" sobfolder containing all the lproj folders into Xcode wherever you want it to be, and make sure it gets added to the current target (Add to target checkmark must be checked in the list). In my case everything was functional as expected after doing this. And as a nice side effect I got rid of these annoying stacked files with the arrow and instead have a very clear group structure consisting of a localized and several lproj folders which makes much more sense to me.
The correct way to add a localization would be through your Project Info pane in Xcode.
It looks like this:
I would think trying to do it any other way might be asking for trouble (or hassle).
I think, you should have a folder en.lpoj for English.
Now if you click "+" and choose xx as language you should get another one named "xx.lpoj" nearby of the old one (on the same level so to say) and NOT inside the en.lproj.
So delete this wrong sub-folder and do it again ...

Way to shrink Resources folder?

I have 100 pictures in my Resources folder and they can really be annoying when trying to find some other resource. Is there a way I could "create another resource folder" to put the 100 pictures in?
Or do I just have to deal with scrolling and scrolling when trying to find another resource?
You can put files wherever you want in your project-- Resources is just a default folder that gets created for you. You could create a sibling folder to Resources, or a subfolder inside of it.
You can do this in two ways: One by right clicking on the project and creating a new group for the images. This will create the logical folder, but won't actually create a subdirectory on disk. If you want the layout on disk also, create the folder on the command line or with Finder and then drag it into Xcode.
I totally agree with #quixoto ans,
one thing more you can categories your folders according to any visible form.And use proper hierarchy for folders.because when you having number of folder and files then this necessary to make hierarchy also naming conventions are necessary for quick understanding and quick search. (e.g. Make images folder for images and in this folder sub folders, for backgrond image,button images,tab images etc.).so it helps you in quick search.

Maintaining Directory Structure when loading local files into UIWebview on iPhone

I'm noticing a minor annoyance when working with local files in a UIWebview and hoping there is a simple workaround. As a simplified example lets say in my xCode project I have a folder called "WebProject" that contains an html file and a subfolder called "images" where the images reside. The html file references the images as you'd expect: src="images/MYIMAGE.jpg" for example, which works just dandy if this where are normal webpage. When you load the html file in a UIWebview, however, this image would not show up because it seems that all of the files are just thrown into one big bundle folder (so the image link is actually: src"MyIMAGE.jpg"). Is there anyway to enforce the directory structure of these files in the main bundle, so that this sort of thing does not happen? Thanks!
Just create the structure you want in the filesystem (using finder or whatever) and import that whole tree into your project. Make sure you select "Create folder references for any added folders"
You'll notice these folders are blue instead of the normal yellow used for groups. This folder structure will exist in the bundle and so your relative references will work as you expect.
Hope that helps.
See this page and this tech note for how to add resources, and maintain directory structure. Make sure you select the radio button that says "Create folder references for any added folders." Then when you go to write your code, folder-relative paths to the bundle will resolve just as if they are sub-directories. Because they are, even in your app's resources.

Problem removing and re-adding an image file into my iOS4 app bundle

My problem is something that should be so simple it is mind boggling. When I change the look (in PhotoShop) of an image file that is being stored in my app bundle. My method for replacing the old image in the bundle with the new one is this:
1) remove the old image from the app bundle (choosing to also move to trash)
2) drag the new image into my file hierarchy in xcode (choosing to copy to app directory)
when I do this, the app cannot find the image no matter what I do. The new images have the same name as the old images but none of the image loading methods (imageNamed, imageWithContentsOfFile, nibs) work. (Although I believe nibs also load with imageNamed, i'm not sure).
Is there something that I am missing here? I feel like it should be a relatively simple process but I am having all kinds of trouble. I also make sure to delete the app off of the target device and clean all targets before rebuilding and running after changing the image files just in case.
Any help would be appreciated.
Thanks
Your problem is probably that the image is not copied to the target. In xcode groups & file pane, fine the node for targets, expand your app target and you'll see Copy Bundle resources expand it and you'll see all the files copied to the default resource bundle when you deploy your app to the sim/device. Only the resources found there will be available to your app. If you don't see your image there you can just drag it there and everything will work.
Now, in order to understand why this might happened we need to look at the different options for adding files to xcode.
When you're adding a file to xcode you are presented with a dialog that includes a few interesting and sometimes overlooked option.
The first - Should the file be copied to the project folder, or should it just point to the file original location. The safest way will be to always copy the files to the project's path. However for images (such in your case) I do it differently. I maintain a separate graphics folder for every app, I save images there (both sources, and final png). When I add an image I do not copy it to the project folder, rather xcode just points to its location. That way I can just edit the image in photoshop, do a rebuild, and the updated image will show up on the phone. Whats important to understand that the directory structure of files you include in the project have almost no meaning, files that appear in the Copy Bundle Resources for the target will always be copied to a single (and flat) bundle/"directory" on the phone. The only exception for this is if you actually add directories to xcode (Personally I recommend against it).
The second option when adding files, is to which targets to add the file. This is the list with checkboxes on the bottom, if when you added the image, your app target wasn't checked the file won't be included in the target Copy bundle resource, and won't be available for the phone.
A few caveats - When using references to files in other location, that location is relative to the project's path, so it's a good idea to keep all the files in directories below the project's root directory. That way you can still copy the entire project to a different location and it will still work.
Great advice above: I thought I would add more for future searches on this topic:
I was adding and removing images to the project just like above:
Remove the old image from the app bundle (choosing to also move to trash).
Drag the new image into my file hierarchy in xcode (choosing to copy to app directory).
However when I tried to drag the new image with the same name to my file hierarchy in xcode I was getting an error that this was not allowed.
Turns out when I was removing the old image Xcode was removing it from the project file hierarchy but the actual file wasnt being removed from the project's root directory.
I solved my problem by removing the image from the project's root directory and added the image again!
Do you put your images in a custom sub-folder? If you just drag in images into the Xcode project tree, if you copy them, the images will be copied to the root of the project directory, instead of the "Images" or other folder you might have set up.
Note that you can right-click on the image in your bundle, select "Get Info..." and reset its location, if it has been moved or copied to a folder you didn't expect.