How to add/remove custom Code snippets in Xcode 11 and above - ios

How to drag and drop a custom code to code snippets and use a shortcut text for auto-fill as we did in Xcode < 10
And how to remove the snippets?

How to add
In Xcode
select line or code to be added in code snippet and then
Option1
Goto Editor
choose the Create code snippet
Option 2
Select Code you want to add to snippet
right click and choose create code snippet
How to Remove
Choose any snippet and press backspace
How to Edit
If you want to edit already added code snippet it is easy. just open code snippet library list (from right corner) from the list select code snippet you want to edit and press SPACE BAR button
Warning : My Xcode crashes randomly couple of time during removing or adding code snippet make sure you save your work (Xcode 10 BUG) :]
Hope it is helpful

Update for Xcode 11
Add code snippet
Same way as before:
Select code
Right click on it
Create Code Snippet
Edit and Delete code snippet
Type cmd + shift + L and you will see the following UI:
For more information about Xcode code snippets check this article.

To add new code snippet in XCODE 10, you can just:- select the codes that you want to create snippet- then right-click on those selected codes - choose Create code snippet.
And to remove the code snippets:
- Just click on the {} icon on the top right nav
- Then select on the code snippet you want to delete
- Press Backspace

If you still want to use Drag & Drop way to create a new code snippet as we did until Xcode 9, you can open Library dialog (shortcut: [Command] + [Option] + [Shift] + [L]) and drag the source code into the dialog.

To edit the snippet
Click on the show panel icon on top right of the Snippet popup
window.
Window will expand to show the code and also the Edit button
Click on panel icon
Edit button now visible

Related

I renamed ViewController.swift and now nothing appears in the Assistant editor in Xcode 11

I renamed ViewController.swift to PickViewController.swift and now it doesn't appear in the Assistant editor.
I guess this is because PickViewController.swift is no longer related to the image in Main.storyboard.
Any idea how to fix this?
In XCode 11, you can use option(alt) + click on the file (in your case PickViewController.swift) that you want to view in assistant editor.
You should rename the class from the identity inspector to PickViewController as well:
Note that you can use refactor option to make the process more automated by command + click on the controller's name and select rename:
Or from the menu:

My main.storyboard is not showing up on Xcode

So here are the steps that I do when opening Xcode to make a basic application. I first click on "create a new Xcode project" then I tap on "single view app" for "ios" then I fill out the information such as the name of the app and if I want to use core data etc.. and when I finish and tap on "create" I see no main.storyboard on the left side navigation panel... I do not know if I am doing something right. I initially did everything on the LaunchScreen.storyboard, but when I did something it did not allow me because something called segues..
Select Storyboard in User Interface as shown in the image
Please, select storyboard instead of SwiftUI, as with XCODE 11 by default the value of User Interface is set to SwiftUI and it doesn't include storyboard.

Xcode Auto Complete Code snippet , replace shortcut Text

As you can see, I have added a custom code snippet and a shortcut.
Problem is that my snippet is //ABC and my snippet shortcut is //
Now when i select the snippet from the autocomplete feature in Xcode, it does NOT replace the shortcut text, and it becomes this
`////ABC`
Now in other in build classes/functions in Xcode, autocomplete works in a different way. When we write a wrong spelling and select the autocomplete from Xcode, it replaces the shortcut text. I want to know how to apply this in Custom snippets. I have gone through the edit portion of the snippet but replacing shortcut text is not found. How is this possible? if it is
I am using XCode 8.3, and my OS is macOSSierra.

Custom class not automatically showing up - Swift 3 iOS 10.2 Xcode 8

So I have my app set up with two view controllers. The first one is my initiation screen, where the app starts, and the second is one the user can navigate to. I added the second one later on in my development, but when I went to the right column under the identity inspector, my new Cocoa Touch Class file is not populated for me to select. Now if you ask me to just type it in, I've tried that, it does not seem to connect. I've tested it by printing a simple line in the viewDidLoad() of the new second class when it is loaded in the simulator, but nothing is printed. Any help would be greatly appreciated!! Thanks!
EDIT
Easy fix is:
Select the activity indicator on storyboard and go to identity inspector and copy the object id. as image: ObjectID_ActivityIndicator
Right click the storyboard file which has the view controller you are working at.
Open as > Source Code
Press command + F to find and look for the id you copied previously
Paste this: customClass="yourclassname" customModule="moduleNAme" customModuleProvider="target"(don't change this target word, you can choose desired module from identity inspector if any).
Command + S to save it and again right click on storyboard file > openAs> Interface builder
Now select activity indicator again and go to identity inspector. You will now see it there. You can also change it as per requirement.
Enjoy. I faced this problem today and found no help online. My class and module field were greyed out. Tried this fix and it worked.
Note: Make sure your custom class is accessible and is in app directory i.e it's not highlighted in red color but gives a normal look.
I have seen a problem like this where the solution was to change the "Module" to a specific value, close the storyboard, reopen it and delete the "Module" setting (assuming it was originally blank or restore it to its original value). This happened in project with many targets and their names may have changed.

Xcode shows two windows side by side

Hello My xcode is showing the screen in half and also not showing storyboard interface builder. below is the screenshot
I have tried to reset the xcode settings as well
defaults delete com.apple.dt.Xcode
But it didn't work. Please tell me how can I fix this
These three buttons up here switch your view. Select the left one.
You're actually stuck in the version editor (which looks at your version repository compared with your current code.)
Because storyboard UI can't be viewed with the interface, it shows the underlying xml.
Also the keyboard shortcut is command + enter (credit to farzadshbfn)
Try click on "Show Standard Editor" button:
Main Storyboard > Right click > Open As > interface Builder - Storyboard
Click First button to show your view controller.

Resources