5 TeaCode expanders for Swift to increase your coding productivity
Swift, the programming language, is one of the languages that does not require lots of typing. It’s quite snippy. However, there are still some fragments of code that - with the use of certain tool - could be written even faster. And this tool is TeaCode. Below you can find five most useful expanders that will certainly speed up your code writing.
gl for guard-let-else
guard let
- else return
is certainly one of the most often used statements. We need to check if the certain variable is set. Otherwise return. It’s lots of typing. In TeaCode you can actually write gl variableName
and you’ll get:
guard let variableName = variableName else {
return
}
Yes, it’s that simple.
f for function
Functions are another example of repeatable code. With TeaCode you just need to write: -f functionName
to get:
private func functionName() {
_
}
or +f functionName
to get:
public func functionName() {
_
}
TeaCode also places cursor in the right place, so you can start implementing the function right away. The funny thing is -f functionName
and +f functionName
is one expander with switch-variable for -
, +
, f
and o
. And the optional part, so you can write: -f functionName(hello: String, world: String)
and you’ll get:
private func functionName(hello: String, world: String) {
_
}
set for setting variable values
In initialisers the often used pattern is setting the field value:
init(hello: String, world: String) {
self.hello = hello
self.world = world
}
It’s just setting the value, but if you have several parameters you’ll notice that it could be done more quick. Just type set hello
and you’ll get:
self.hello = hello
Special comments
Xcode offers a few special comments like:
// MARK: - Section Name
// TODO: thing to do
// FIXME: fix this thing
// !!!: important text
// ???: a good question
And again, we can type all these comments quicker. Just type:
m Section name
and you’ll get:
// MARK: - Section name
It works similar for the rest type of comments. To get more information press shift+cmd+space for and type Special Comments
. Press return and see how to use this built-in expander.
Localization
When working on an app, every string that users sees should be localized. It’s a good practice to always prepare the app for future translation. Even if for now it’s not translated. So basically you write:
NSLozalizedString("text to be translated", comment: "Comment for the translator")
And yes, it could be simpler, too. With TeaCode you just need to write: _text to be translated_Comment for the translator
.
More?
TeaCode comes with over 50 built-in expanders (snippets) for Swift to increase your coding productivity. However, the power of the app is that everyone can make their own custom expanders with the use of variables (including switch variable), optional expressions, subexpressions and filters. And creating new ones is extremely easy!