I am trying to add 2 swift files to my Xcode project. They are located on my desktop currently. When I open them up, they look like this:
However, when I add them to my Xcode project, they look like this:
How can I add these files without the text messing up? Thanks!
That looks suspiciously like some kind of PNG file, not a text file. ("PNG" followed by "IHDR", specifically.) Are you sure that's a Swift file and not a screenshot of a Swift file or something?
That's also a very strange title in the titlebar of your screenshot. Perhaps that is related.
Either way, seems pretty clear that these allegedly Swift files are actually some format which is not plain text. Copy the text out of it into a new file created from scratch by Xcode, and that will fix whatever the problem is.
Related
When I right click to add a new file (or do File -> New -> File), I don't get a dialogue box asking me which Template I want to use. It just creates a blank file like this:
I tried renaming it to a .swift file and adding in all the necessary code to start off, but two things happen:
First, the autocomplete function is one step behind. So when I've already typed import UIKit and moved on, it starts trying to autocomplete UIKit. And when I've already typed class className: UICollectionViewController {
} and moved on, it starts trying to autcomplete UICollectionViewController
After I manually type in the bare minimum needed to make a swift file into a UICollectionViewController with a colored background, I can't reference it in my other files.
I can only assume this is because of the lack of a template dialogue box, but maybe I'm wrong. Is there any way to toggle this template dialogue box on or off?
This problem is only happening with this particular project since I updated to Xcode 10.1
I can't seem to find anyone else online who's already had this issue. The only similar questions I found online were referring to creating reference folders rather than groups. I didn't find anything regarding the file template dialogue box not showing up.
I fixed this and I'll post the answer in case anyone else comes across this problem.
It was tedious, but I:
Created a new project
Initialized my podfile, added what was in the previous one, and installed it
Opened up the new workspace
Added each file one by one
Maybe there's an easier/quicker way to do it, but after looking through all the settings and not finding anything, I ended up doing this and it worked.
Check that in the left hand pane displaying your project structure you are adding the new file to a folder which comes under your application (identified by a blue Xcode application icon) instead of a general folder as your top level (identified by a blue folder icon). I can't add images yet so please see link.
I can see that this is a recurring problem with all sorts of Xcode versions. I'm using the latest non-beta build (9.2 9C40b).
I have already localized in Spanish. Doing that involved successful exports and imports of xliff files, with same Xcode. So what changed?
I am now trying to localize to another language. This is a showstopper. Any hints? I have looked through all the posts about previous versions crashing, and have not found anything that works.
(And before you mention it, I am done and over with genstrings. If it exists anymore.)
I've discovered that large .xliff files (more than about 6,500 lines or 1,200 <trans-unit> elements) cause Xcode 10.1 to crash consistently near the end of an import operation.
The work-around is to manually split the .xliff file into two distinct .xliff files, each containing a subset of the <file> elements in the original file. You can then import the two resulting .xliff files into Xcode separately without crashing.
Do not translate "bundle name"
I wanted to translate to Greek Language and every time I was importing xliff files, Xcode was crashing.
I realized that the problem was, that I was also translating "bundle name".
If you did the same mistake, open xliff file, find:
<trans-unit id="CFBundleName">
<source>NameOfYourApp</source>
and delete the line
<target>...</target>
After that everything worked perfect for me!
Here's a workaround. Select your project icon in the Project Navigator. Select Info at top (as opposed to Build Settings). Under Localizations, click the + button and add your new language.
Xcode will create the new .strings files and fill them up with pre-existing translations. (If there are any.) Strangely, for me, some of the new .strings files were filled in with English, some with Spanish.
In any case, you have the new .strings files and can manually paste in the translations for the new language. If your app doesn't have too much user-facing text, this isn't onerous.
But really, with this problem going back to Xcode 4 (!) one would think it would be fixed by now.
it's a late answer I know, and I'm using Xcode Version 10.1 (10B61) already.
In my scenario, I added Chinese Hong Kong (zh-HK) language under Project > Info > Localization and exported successfully then sent to the agency for translations. After few days they sent to me Chinese translated text within. At that point, everything seems correct for me by eye. But I've tried 10 times to import file and it crashes 10 times without exception! Which makes me sick. I use to checked to see the difference between 2 document via Apple's File Merge App. I understand that agency geniuses added few missing <\target> tags. Hmmm, that means while exporting Xcode didn't add for some translations <\target> tag. Interesting...
I removed those unnecessarily translated tags and checked everything was equal in 2 documents except translations of the words to the Chinese language.
Tried to import again. Then BOOM! It works like a charm! I was surprised by this. It's so weird that Xcode never shows me a descriptive message about my mistake. Probably, It's just a parse error for Xcode.
Whatever, I hope this will work for someone else.
Best.
Alright, so I've had this issue before and have looked everywhere for answers. There are similar questions on here, one being this exactly, but with no answer and it seems to have been abandoned.
The issue is that all the code in my GameScene.swift seems to have no effect on what's being ran in my project. Everything that I built using the interface builder on my GameScene.sks file appears just as it is supposed to, but changes in labels, impulses or other changes to objects that I've put in my .swift file seem to be ignored.
To test this, I went into my didMovetoview section of my GameScene.swift and simply put a: print("hello"), to see if it would run in the console and that there were other issues, but it completely ignored it. I have also created a label on the .sks interface builder and used the .swift file to change the text, which also didn't affect it at all.
I have made sure that the class name "GameScene" that is in the .swift file is also the correct custom class that's referenced in the .sks file. I've made sure the GameViewController is my initial view controller and that it sets the scene to the correct GameScene.sks.
After doing some research, I have done things such as copying the GameScene.swift and .sks files and deleting them, cleaning and building the project, replacing the files and then running it. (This has worked for me once in the past when I had the exact same issue) I have heard that deleting the derived data for my project specifically can help with little issues so I went and did that to see if it would help, but it also didn't.
I am clueless as to what to do now and I can't find anything online that specifically gives a solution or a few possible solutions to fix this.
Thank you in advance for any possible solutions
Alright! So I tried something that solved this issue for me.
Similar to Pierce's response, what I did was instead of using the same project and replacing the files with themselves and cleaning the product, what worked for me was just making an entirely new project and using the same GameScene.swift and .sks files.
Although they seemed like the two things wouldn't make a difference when it comes to solving the issue, creating a new project and using the same files was better than using the same files and changing things around on my current one.
I just had to re-replace all my asset-images.
If you create next to the already existing sks file a new sks for for another device type you need to add the "GameScene" class to the newly created sks file under the tab "Custom Class"enter image description here
In XCode, you can browse Objective C Header/Documentation Files using Command + Shift + O.
For example, if you type in UISegmentedControl, only the Obj C version comes up.
If you Command click UISegmentedControl anywhere in code, the Swift version exists.
Is there a way to see Swift version through the Search Shortcut?
It seems to work if you open it from within a Swift file you've created. Maybe then it's showing a bridging header or something?
While in the Swift ViewController generated by a test project, I can Cmd-Shift-O and select UISegmentedControl.h, or UITableView.h and the result shows up only in Swift.
But, if I then try to open a different file from within that one, even though the current file is in Swift, it only shows Obj-C. The language of the file doesn't seem to be as important as the .swift extension.
Seems to be the same if you Cmd-click and view the documentation - it'll show whichever language you came from. XCode6 seems to still be a bit screwy w/this though - about 2 steps in I keep getting "Symbol Not Found" even for basic things like UIView :\
Might as well just look at SwiftDoc.org.
Click on the Swift logo bird at the right of the cmd+shift+o window so it turns blue, congrats you've turn on "Swift generated interface" if possible for the searched files
I'm pretty green, but I'm trying to modify a simple program to fit my own needs. You may remember the "BirdWatching" app from "Your Second iOS App: Storyboards" in the iOS Developer's Library.
Anyway, I've refactored most of the names, etc., successfully (it still worked), but then I tried to get rid of a file that kept appearing, even though its name had been expunged (or so I thought) through refactoring. Shows up in the Assistant Editor, right next to the file to which it was refactored.
Now I've got a mess. I tried to move the entire project into it's own folder, but now the compliler won't recognize the info-plist file (says it doesn't exist, and two other files are showing up in red, depending on their position in the navigator. However, it's the WMDG-info.plist that the complier complains about. Specifically, it appears to be following the old path to the file, even after it's been moved and re-added.
I've tried quitting and restarting xCode, re-adding the files, etc. I've searched under every keyword I can think of, but can't find a solution.
Please help!
Thanks!
--Tim