Xcode 10: Auto insert closing braces bug - swift

In Xcode (swift file), I'm facing an issue where automatic insertion of closing brace is not working anymore.
Ex: when I write
func myFunc() {
and hit Enter, Xcode will not insert the closing brace, and I need to do it by myself (and I'm very angry about it...)
Yet, my settings seem to be good:
Preferences -> Text Editing tab -> "automatically insert closing braces" == true
It seems to happen for each file containing commented code, especially this (very common) piece of comment : //}
Configuration: Xcode Version 10.0 (10A255)
Steps to reproduce on a new Playground:
Copy and paste the following comment : //}
Then type : func test() {
Then hit enter
It definitely seems to be a bug in the text editor. Already filed with Apple bug reporter.
Can everyone reproduce the bug or is it due to some configs ? And if so, what can I do to fix it ?

I'm using Xcode 10.3. I've discovered if I have comment blocks in a file, then Xcode won't auto insert a closing bracket in that file.
/*
Temporary fix. Replace this...
*/
//
// ...with this
//

The problem was fixed by Apple in Xcode 10.1 (10B61)

Related

DOCTYPE Emmet shortcut stopped working VS Code [duplicate]

Every other snippet is working, but !+tab is not.
! snippet is not working
other snippet is working
I am using Visual Studio Code. I'm using 1.69.0. It was working before, but I wanted to add net html file, named that new.html, because I had index.html already. After that this script stopped working on every html file, but other scripts like "a", "div" etc. is working.
The v1.69.2 recovery release is out now. Emmet in html is working as it should for me now.
Looks like it will be in the Recovery Release, see https://github.com/issues?q=is%3Aissue+label%3Acandidate+repo%3Amicrosoft%2Fvscode+repo%3Amicrosoft%2Fvscode-internalbacklog+repo%3Amicrosoft%2Fvscode-remote-release+milestone%3A%22June+2022+Recovery+2%22+.
Don't know when the recovery release to Stable - presumably v1.69.2 - will be released. The .1 release is out and the fix is not in it.
It has been fixed though, see https://github.com/microsoft/vscode/issues/154375, and should be in the Insiders Build tomorrow (07/13/2022).
Testing the latest Insiders: ! is working. As is ul>li*3 type expansions (although that never stopped working for me - but it has been reported elsewhere). Should be in the v1.69.2 release out soon.
It is a known issue with the v1.69 release, see html emmet suggestion not automatically display or https://github.com/microsoft/vscode/issues/154517 for example. Lots of issues on github on ! and * not working.
So the emmet snippet will not appear automatically when you type !, but you can press Ctrl/Cmd+Space (which is the command Trigger Suggest) to make it appear and select normally.
Try Ctrl/Cmd+Space for anything emmet-related nnnnnot working in vscode v1.69.
You could also go back to v1.68 to solve the issue.
Try to write "doc" instead of "!". "doc" works for me.
On Windows 10, this worked for me:
Go to "Settings" and type "emmet.trigger" in the search
A checkbox for "Emmet: Trigger Expansion On Tab" will appear
Check the checkbox for allowing Emmet to trigger expansion on tab
After I did that, it worked just fine for !+TAB and any type of mulitpliers (i.e. li*4+TAB).
You need to check this option or put "emmet.triggerExpansionOnTab": true in settings.json to use the emmet abbreviation pressing TAB. I realized this ones what is not working:
!, lorem, >, and .
Examples of use: ul>li, li3, ul>li*3
None of them shows the preview of the emmet, and you can't use them pressing TAB without enabling the option that I sayed above, and even checking the option you won't be able to see the previews, you'll need to know them by yourself and press the TAB even though nothing showing that it's a emmet abbreviation.
You can use CTRL + SPACE too.
Edition Windows 11 Pro
Version 21H2
VSCODE Version 1.69.0
I had the same issue with the ! not working. I found another shortcut that does the same thing: type html:5, and press enter.
Looks like a bug, I have the same problem with 1.69.1, the VSC team is aware and fixing it. Should be fixed with the next release soon.
Meanwhile, you can use either HTML:5 or doc
meanwhile use "HTML:5"
enter image description here
or use "doc"
enter image description here
While #Mark's answer works, another work around would be to use the html:5 snippet which still works as expected in v1.69
Yes, I am facing this issue too since the latest update.
Somehow the solution I have got is :
You can check the box “Emmet: Use Inline Completions”
In settings by typing “emmet” in the setting’s search.
You can see the suggestion now and choose it by pressing the tab.
This is the solution I have got till now but hoping that we could have the previous version back.

swiftc failed with exit code 1

extension SlideInAnimator: UIViewControllerAnimatedTransitioning {
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
// This works
UIView.animate(withDuration: 0.3, animations: { }) { transitionContext.completeTransition($0) }
// transitionContext.completeTransition causes the error
UIView.animate(withDuration: 0.3, animations: { }, completion: transitionContext.completeTransition)
}
}
Xcode isn't showing any errors but while compiling, it causes the error shown in the title (even after cleaning). Whenever I comment out the second animation, the error won't show up. Is this a bug or I'm just not allowed to use it like the second animation?
The swiftc failed with exit code 1 message indicates that the compiler crashed due to an internal problem. In my experience, that may or may not indicate that there's some type of syntax error with your code (although what you posted looks fine to me), but either way, the compiler can't handle it as you have it written.
The Swift toolchain is still very buggy unfortunately, and sometimes you have to "help it out" by trying a different syntax for whatever you're doing.
You may want to check https://bugs.swift.org and see if there's a bug already reported for it, and add one if not.
Simple Solution For This With xcode 8.2 and swift 3.0
Click top left of the project navigator (your project name ) and clean project with (cmd+shft+k).
Quite Xcode completely from tray too.
Open project again.
wait and let xcode done indexing of files.
Run project and thats it.
Enjoy Happy Coding!!!
I've just spent a couple of hours trying to identify the cause of a swiftc exit code 1.
After reading several posts, cleaning the project & restarting xcode several times, commenting out new chunks of code etc., I gave up and started to create a fresh project.
When I copied the first .swift file from old to new project I noticed that I had two .swift files with the same name in different folders. I tidied up my files and the project compiled OK.
In summary, as has been stated in other posts, Exit code 1 seems to be a catchall for when the compiler finds something weird & unexpected that it doesn't handle properly.

How to make Xcode put starting brace on new line in Swift?

I have noticed that the coding style in Swift appears to be to put braces on the same line as a method signature or if statement etc. Without getting into a debate about which is right or wrong, my aim is simply tom get Xcode to put the braces on a new line when it does its auto completion and for the new file templates.
I've tried the advice here and it doesn't work: https://forums.developer.apple.com/thread/23087
I'm using Xcode 8.1 on Sierra.
Has anyone else been able to get this to work?
Thanks,
Alan
You can use below methods in conjunction to accomplish this task.
ClangFormat and Uncrustify
Above method will only change the default statement templates and not the inbuilt methods formatting. (i.e autofilled viewDidLoad() method will still have the braces in the same line.) For this you should consider using these plugins. They have options to save the file with specified format.
(UPDATE Snippet Edit no longer works)
Snippet Edit
Snippet Edit is a small program that is used to edit the Xcode's standard code snippets. We have to do this way because there is no direct way to change the code style in Xcode settings and XCCodeSenseFormattingOptions is not supported since Xcode 4
You can follow below screenshot for reference. Remember to restart Xcode once you are done with editing.

Xcode 6 Beta / Swift - Playground not updating

I was playing around with the Playground feature of Xcode 6's first beta - and I notice half the time the Playground doesn't update (simply doesn't display the result calculation or how many loop iterations are happening) simple code/loops/functions that are in there. Even the Swift Tour https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/GuidedTour.html
has several lines of code that don't show up in Playground. If you mess with the code sometimes it will show up, by moving the code around or placing it elsewhere. Anyone else? Any fixes? Is this just a beta problem?
Make sure you haven't inadvertently added an error to your Playground code. Unfortunately, there is no inline notification of an error, and after an error is created, nothing in the Playground will update.
To help with this, open up the Assistant Editor (File > View > Assistant Editor > Show Assistant Editor), which should include a Console Output box. If there are any errors in your Playground, they will show up there. Once corrected, your Playground should hopefully update once more.
That said, it can be a bit slow depending on the complexity of your Playground and its size.
This answer (Undeclared Type 'NSView' in Playground) did it for me (restarting Xcode and the machine didn't help):
rm -rf "$(getconf DARWIN_USER_CACHE_DIR)/org.llvm.clang/ModuleCache"
Had the same strange errors after upgrading to xcode 6 beta 6. For me the problem got fixed with a Product -> Clean. And if that does not fix the errors hold down option key and click again on Product in the Menubar then you will see in the dropdown menu Clean Build Folder... click on that. Or you could download Watchdog app from appstore. This little helper automatically cleans your xcode projects.
You have to be very careful with swift. the language is very case sensitive so while using playground make sure all things are spaced out.
The following code will NOT give you a syntax error but it will stop processing the rest of your code in playground :
for index in 1...5 {
if index %2 !=0{
continue
}
println(index)
}
The error in the code above is in line 2. The code has to be written
for index in 1...5 {
if index % 2 != 0 {
continue
}
println(index)
}
Hope that answers your question :)

Rename a class in Xcode: Refactor... is grayed out (disabled). Why?

Why is Refactor... grayed out (disabled) in Xcode?
I'd like to rename a class.
Select the class's symbol in its header file - i.e. the bit just after #interface. Then the refactoring stuff should be enabled.
If you are using Objective-C++ (i.e. mix Objective-C with C++ code) then refactoring is disabled in xcode since it does not support refactoring of C++ code.
Refactor might also be disabled if affected files (most likely the file with your class in it) are not saved.
I've been using Xcode for 5 years now, and refactoring has never worked correctly (even xcode 4.6 has major bugs where it WILL corrupt your source code!).
The workaround has always been (still works 100%, even in cases where Apple's code fails)
use shift-command-f to find all uses of the file
select "replace" in the search settings
"replace-all"
do the following for the .h file, and REPEAT IT FOR THE .m FILE (if you have one):
right click the original file, and select "show in finder"
delete the file from xcode (select "delete references only" when asked)
rename the .h (and .m if you have one) in Finder
in Xcode, select "Product -> (hold down Alt) -> Clean Build Folder"
quit xcode (you can usually get away with not doing this - but NOTE: there are some other MAJOR bugs in Xcode where it crashes itself if you don't do this)
re-open xcode
drag/drop the .h and .m back into Xcode
wait a few seconds (some of Xcode's core methods are asynchronous - allowing it to corrupt your project)
finally, when it seems to be doing nothing (and your hard disk isn't making any noise any more): cmd-b to re-build
I have a 100% success rate with this method. I just tried refactoring with Apple's "Refactor -> Rename" in latest xcode and it failed - again!
(this time with the incorrect error: "Unable to determine the language of", one of those error messages where Apple put the wrong text in place)
I'm going to my project at finder, then change files name by get info.
After that, at xcode -> Project Navigator I delete the files.
At end, I click right on the class and Add files to ..., and add these files again.
It worked for me.
For me I realized Refactor was disabled because the Xcode project I had opened was referencing a Base SDK that was missing. Edit Project Settings and in the Build tab set the Base SDK to one that you have (like for me this was iOS 4.2). This enabled Refactor for me.
Also, it could happen that you renamed the filename for the class, either outside xcode or by ctrl-clicking the filename and then renaming it.
xcode refuses to refactor if filename does not match with the class name.
Go to your class' header file and find the line that looks similar to this:
#interface YourClassName
Right click on the class symbol (e.g. YourClassName) and you should be able to select Refactor -> Rename...
I just tried this and it works in Xcode 5.
This may be a bit late, but I stumbled across this post because I was unable to refactor my "ViewController.swift" file to "WhateverViewController.swift". I tried selecting the file in the Project Navigator and then selecting "Editor -> Refactor" from the top menu, but 'rename' is always greyed out.
Instead, what worked was selecting the ViewController name from the editor. So if you have:
class ViewController: UIViewController {
// Code here...
}
Highlight the "ViewController" word and then select Refactor from the menu or right-click and select Refactor -> rename.
Hopefully that helps...
Had this problem as well. I ran through trying to find missing SDKs, saving files, and looking for Objective-C++ code as mentioned above, and all it took to fix my machine was rebooting XCode.
Seems a little buggy still.
BTW, this was for XCode 4.0.1
Refactoring works If you first change the file name in the project navigator.