Add custom code snippets inside Xcode — Swift 4

ANANTHA KRISHNAN K G
Swift Dynamics
Published in
2 min readOct 20, 2018

If you want to reuse a code in future where will you store it ? Local file or GitHub? Well, you can store your custom code snippets in Xcode for reusing them.

In Xcode you can store your custom code snippet very easily . Select the code you want to add in code snippet and right click. From the options click on create Code Snippet and add title, summary and other fields.

Done!. Your custom code snippet is ready to use.

To use it just open the custom code view and drag and drop the code inside any file you need.

In my example I have added this code ,

func modifyView() {
self.layer.shadowColor = UIColor.black.cgColor
self.layer.shadowOffset = CGSize(width: 0.0, height: 2.0)
self.layer.masksToBounds = false
self.layer.shadowRadius = 1.0
self.layer.shadowOpacity = 0.5
self.layer.cornerRadius = frame.width / 2
}

Here we can keep placeholders instead of giving real values . The placeholder syntax is very simple. Add the placeholder inside <#-------#> . The above example can be saved like this,

If you like my post and want to get future update, do click 👏👏👏, follow me on medium and here . Happy coding 💪 💻

--

--