简体   繁体   中英

Xcode 8 End Closure Autocompletion Issue

Relatively new to IOS & Xcode from an Android background, I've found in a few tutorials pressing return on an ending closure and Xcode formatting it in a special way. In my case however, this does not always work.

What happens before and after Enter is pressed for Me 在此处输入图片说明 在此处输入图片说明

What I've seen and would like it to do. 在此处输入图片说明

Another Example as mentioned by this video(Start 13.06, End 13.16) https://youtu.be/v9JtVJUxX7k?t=13m6s

Compared to other IDE's Xcode is very buggy currently so its hard to tell if this is just a bug or if I'm doing something wrong. Is anyone able to guide me on how I can go about acheiving this or why its happening?

It appears for Xcode 8.1 autocomplete for trailing closures must be taken care of before any other placeholders. Switching to Xcode 8.2 also solved this problem.

For Example within the image, the trailing closure would have to be autocompleted before the request placeholder was edited to acheive the desired effect. 在此处输入图片说明

It's hard to tell for sure from your screenshot, but it looks like you aren't hitting the Return key while the completion handler placeholder is actually selected . You have to either tab to it, or click on the placeholder. In your color scheme I believe the placeholder background color will become more saturated and the text color inside the placeholder block will become dark instead of light. In this selected placeholder state, pressing the Return key creates the trailing closure syntax you are hoping for.

For what it's worth, I typed the exact same code you have in your example above in Xcode 8.2 beta 2, and when I select the placeholder block and press Return, I get the trailing closure syntax as expected 5 out of 5 times.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM