Xcode 5 indentation issue - ios

I get indentation issues when I copy few lines and paste it. Xcode does not copy indentation properly or applies another indentations.
As shown in below images, I copied first function and pasted which is second function. Indentation are reapplied except for first line.
I played with Xcode indentation settings but could not solve it neither do I have any clue why this happens.
Below are 2 indentation settings I tried.
Do anybody see anything wrong in above settings?

In Xcode preferences, Key Bindings tab, redefine ⌘-V to "Paste and Preserve Formatting" and ⌘-option-shift-V to "Paste". Then ⌘-V will do "Paste and Preserve Formatting" which is what you want.

Try turning off Auto-Indentation. That way, Xcode doesn't remove formatting.

That was when i customized indentation in Swift and then get back to Obj-C. Nothing with changing preferences helped. Just fully restart xcode.

With cut and paste, you have to actually tell xcode to indent after the pasting.
⌘ A and then Control I.
The first one select the whole class contents (when the cursor is inside) and the second one indents it based on your indent preferences.
Hope this helps.

I just checked Xcode settings in another mac and made changes to match that and solved the issue. Sorry I don't remember what were they as it has been too long.

Related

Seeing small dashes under Button's title in Xcode 8.1

I was creating a simple app in Xcode 8.1 with swift 3 and I got this problem (picture): dashes under buttons symbols.
How can I fix this issue?
Thanks.
So Nirmit dagly (https://stackoverflow.com/users/3401707/nirmit-dagly) has given the exact solution and it works perfectly.
He says: "You need to check button style on your iPhone device's setting. To check please go to General -> Accessibility -> Button Shapes. If it is enabled, then make it disable and run the app again. It'll hide the underlines from buttons."
I do thank him for his helpful answer and I has republish it here for the benefit of others.
Thank you again Nirmit and I prefer if we can get other independent solutions(not linked to the parameters of the phone user.).

The document "Main.storyboard" could not be be opened

I'm using Git and we are 2 people coding together. I pulled my friend's code, run it and it worked as it should be. Then I merged our parts and cleaned conflicts (almost all of them were in storyboard). Since i'm doing this merge process for a while, i'm not all stranger for these details.
However, when i run the merged version of code, i get the error:
The document "Main.storyboard" could not be opened. The operation
couldn’t be completed. (com.apple.InterfaceBuilder error -1.)
I can't open storyboard as interface builder either. When i try it, I get the same error. I read previous post about this error but as I mentioned, I can open and run both versions of code in my XCode before merge. Thus, there is not a font or attributed string problem.
What may be the problem?
I got this issue, after I solve the conflicts which is merged by svn.
I could only see the source code of my storyboard, I could not open my storyboard as interface builder. So, after my struggle,
1)I delete the topside space line in my storyboard source code
2)and close my Xcode and simulator
3)restart my project
it becomes regular, oops, the space line on the source code will affect our storyboard !
there are conflicts in Storyboard. You can take last working code of storyboard from github. select storyboard select version editor and copy last working storyboard and replace xml with existing xml.
I guess your storyboard still have confliction.View your storyborad as source code, then fix all conflictions. After all, open it again as Interface builder
For me the only thing that worked was to create a new storyboard file, open the old and the new storyboards as source code, and copy the xml from the old to the new storyboard. I didn't take the whole xml, just the scope of the <scenes> </scenes>
I had to create a new Storyboard file. Then cut and paste the "scenes" tags from the old and put into the new. I then had to delete the old Storyboard from the project in order for the project to build successfully!
I guess the problem is that storyboards don't merge very well, I think it is better to init your UI from code so there will be no troubles during merges. Anyway you should try to rollback and merge it again.
As other mentioned, there are likely merge conflicts in the storyboard file.
If you can't easily solve the conflict by either picking --ours or --theirs, you will have to perform the merge manually in the storyboard file.
What I do is open in in a text editor (e.g., TextEdit.app - but make sure it opens documents as plain text, in Preferences).
Then, locate any occurrence of the git conflict markers (or a portion thereof, e.g., "<<<<<"), and pick the code fragment that you want to leave (and remove the other, of course).
EDIT: As Cong Tran mentioned (and I forgot), you can open storyboards as source code from within Xcode itself (see his answer).
Fast way to fix
Copy the storyboard Id shown on the error prompt window
Right click on your storyboard
Choose Open as => Source Code
Search the id and delete one of the duplicateID and you are done!
i would suggest , right click on any of the files and click on finder then you will have what you need and drag and drop

Xcode custom fonts not showing up in Storyboard

I added my two fonts to my project folder:
I added them to info.plist:
I can not see them in my custom font list in the storyboard:
What have i done wrong?
I know this is a pretty old question, but I ran into the same issue. And the above tips didn't work for me. Apart from the standard checks (present in bundle, restarting XCode, the thing that fixed my issue was that my label text type was marked as "Plain" and hence some fonts were not showing in the dropdown in the Storyboard. As soon as I changed the text type to "Attributed", all the fonts appeared in the dropdown.
Hope this'll help someone stuck with the same issue.
This drop-down box shows the system-wide installed fonts. So you need to install your custom font on your system first so it's appearing in that drop-down box. You can do that by double-clicking it, the FontBook.app opens and asks you whether you want to install the font.
This was a huge headache for me but I simply fixed it by:
I fixed the issue by restarting my Mac.
Then restarting Xcode.
I Installed the font in the system as per DarkDust solution and i am able to see the font in attributed type.
Then i changed the type to plain and i able to see the Custom font in the font types drop down.
Had the same problem but this SO answer by user Saranjith solved it while the other solutions in this thread didn't: Xcode 8 custom font doesn't show up in interface builder
Basically in Font Book select "Computer Fonts" and then hit the + button and re add the Fonts.
This is happened to me after moving to Xcode 11 in Catalina from Xcode 10 in Mojave.
Well, silly mistake on my part, but I didn't realize my font was named something way different from the file name.
Double-clicking the actual font file opened it in the font book, and that showed the actual font name. It was in the dropdown all along.
I solved my problem when i used font name. Do not use file name. I was used like this [UIFont fontWithName:#"appFont" size:17] but it is wrong.
Upload your font file to https://fontdrop.info/ and use the name
My font file name is appFont.ttf but when i uploaded i saw Roboto Regular.
[UIFont fontWithName:#"Roboto Regular" size:17]
Sometime I go to another file and come back, then my custom fonts are arrived. I think this is an issue of Xcode and will be solved in following version.
In my case I just turn the text from plain to attributed then turn it back again to plain then it showed up., hope this help anyone.
I ran into the same issue and fixed with below steps
Closed storyboard
Cleared derived data
Cleaned the project and open the story board
If this is not working then restart the Xcode.
Thanks
For me it was case sensitive issue with the font file name. Not sure if it's always for this reason...
In my case my fonts were in woff2 formats. Although woff2 is supported in iOS, the fonts don't appear or get rendered in Storyboards.
If Xcode showed your custom font before but stopped to do it at some moment, try to readd font files to your project. It solved the problem for me. Other answers weren't helpful.

uppercase label in xcode storyboard not wanted

I'm using xcode 6 with storyboard for ios app development.
I have a problem with UILabel in view controllers in storyboard: the text is simple and inlower case, but when I run the app in the simulator or in the device I see the Label text in UPPERCASE.
Labels have no outlets, and cannot be modified programmatically.
some one has a solution? I'd prefer not using IBOutlet and setting text by code..
I had somewhat similar problem. In my case everything(title, lables, button texts, etc.) was in upper case. I found out that "Localization Debugging" was on, so when I had language on iphone which was not supported by localization, it turned words automatically to upper case. When I disabled it, everything worked fine again.
Just go to "Product > Scheme > Edit Scheme" and there select "Run" and disable "Localization Debugging". (Sorry, I don't have enough reputation to post images, otherwise I would put here screen)
Hope it helps
I answer myself fot other people.
Nothing to do with this strange thing. It seems a xcode bug. Sometimes the labels appears uppercased, other times are ok.
I discover a trick that was using the attributed text in storyboard. in this way it works correctly.
Another way is to use a outlet and setting the uilabel.text by code.
Bye

StoryBoard Assistant Editor stopped showing associated file

Xcode storyboard assistant editor stopped showing related files.
"Automatic" is selected and "Class" is filled in Identity Inspector.
It was working before, but know it has stopped.
"Auto" or "CounterPart" modes are still woking for other files except StoryBoard.
A few days ago, I tried to update from Xcode 5 to 6, but later on gave up.
Would that have something to do with it?
With XCode 11 onwards, you can option(alt) + click on the file that you want to view in assistant editor.
Simple Fix.
Found the solution (at least worked for me), it's the same bug that causes you not to be able to create new outlets. You must delete the [DerivedData] folder:
Close the project you are working on with.
Delete the【DerivedData】folder of you project. (This folder may inside your project's folder, or inside
~/Library/Developer/XCode/DerivedData/(your project)/ ) or somewhere
else that were setup by you.
Restart Xcode.
see here.
In same case this worked for me:
Right click on ViewController file(on left pane) and choose Delete -> Remove Reference.
Right click on folder where this ViewController file was and choose Add files to .. and add this ViewController file which your just deleted.
Profit.
Deleting the Derived Data didn't work for me nor force quitting Xcode and restarting it.
The only thing that worked was deleting both the class and the storyboard (only the reference to them) and adding them back to the project.
Hope to help someone.
If anyone is wondering how to find Assistant editor in XCode 11 then
please find the steps from the below image. You can show this options
in storyboard or Xib files on upper left corner.
Maybe it's too late but just with the keyboard, you can launch a reset for associated files.
Use the keyboard :
command + option + shift + z
You can find it in the menu Xcode->View->Assistant Editor->Reset Editor.
Click first on the assistant window, then click on 'option'+'alt' and right click on the view controller that you want.
I have Xcode 13.1 and none of these solutions is working for me, but this simple solution works for me every single time. With your Storyboard and (empty) Assistant Editor open, in the upper right of the Editor window click the "Add Editor on Right" icon Editor On Right Icon, and just as promised, it will open a new editor to the right of your Storyboard and (broken) Assistant Editor, only the Assistant in THIS window will be working! Just find the "Close Window" x on your broken editor, close it, and in its place will be your shiny new working Assistant!
Full Editor View of where to click to open the new Editor On Right
Tried all the above methods whereas after simply running the app Command + B fixed this issue and I was able to select the screen under automatic.
This command on terminal fixed my issue:
defaults write com.apple.dt.XCode IDEIndexDisable 0
simply exiting and reopening Xcode worked for me.
For Xcode 8+ versions
Check at top process indicator that if Xcode is "indexing" files... if yes, then, please wait until it finishes. Once it get finished. Your file will automatically appear as counterpart in Automatic section.
If Xcode is not showing "indexing" in process bar, then perform as #Anna Chiara's Answer
I deleted ~/Library/Developer/XCode/DerivedData -> didn't work
Xcode->View->Assistant Editor->Reset Editor is disable
Finally, I figured out that the class name of File's Owner of .xib file is incorrect (the class doesn't exist). I corrected it and Assistant Editor works again.
Hope this helps you
I had the same problem. Finally this is what worked for me.
Changing the name of the ViewController File.
Change the name of the class to the new name via the Refactor tool
Refactor tool
The only thing that ended up working for me was copying over the code from the offending ViewController files and completely deleting them, then creating new ones with the exact same name and pasting in the previous code.
The assistant then linked up to the new ViewController files with no issue.
None of these answers worked for me w/ XCode 13. However, the following worked:
Rename the ViewController class to ViewController2
Update the reference in the storyboard to ViewController2
This made the assistant editor appear.
Change the name of the class back to ViewController. Change the reference in main.storyboard back to ViewController and hit enter (Step 2)
I had same issue and spent almost 2 hours of trying different aproaches finally I found something to solve problem.
I've created two or more VC at the same swift file and I think that's why IDE confused about the files.
So I suggest that you should delete your viewcontroller class and clean than reassign class.
I hope it works for you too.
For what it is worth, this was happening to me for the last couple days on 9.3 . I had just added a new build schema for an alternate debug symbol on testflight. It was not until I removed the new schema and then deleted Derived Data and restarted did it start working again. I have re-added the new schema back in and it continues to work. Not sure what the issue was, but that is what solved it for me.
In case anyone is watching I had a bizarre instance of this (Xcode 11): I deleted a View Controller that I'd done incorrectly; dropped in a new one, created the UIView and associated. BUT I didn't bother to create the outlet from the View Controller on the previous screen. Strange that it let me work for a few minutes, then after I had turned off the assistant editor to do something else, turned it back on and only had the UIResponder.h file. Edit - this happened again. Had to delete the 'wire' to the next screen, then recreate - then option to get to the correct .m and .h files reappeared.
I faced a similar issue and here's what I did
I had a swift file and a xib file with its class connected to the swift file like so inside a group folder, and it doesn't show that they're connected.
But when I take them off the folder the assistant works somehow, so I took them off the folder and made an outlet from a UILabel then put them back inside the folder then they're permenantly connected.
Quite Xcode and reopen it. This is solve my problem.
I had the same problem. But my problem was about having the VC's under "View Controller" folder. When I move VC's to main folder instead of "View Controller" folder, I was able to reach the assistant without problem. If you have the same issue like mine, you can solve by deleting all the VC's and create again under your sub folder.
Just add the Class on right side of your story board which you want to open in assistant

Resources