-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
Swift High Performance
By :
Because Swift is a static and strongly typed language it can read, understand, and optimize code very well. Swift tries to remove the execution of all unnecessary code. For a better explanation let's have a look at a simple example:
class Object {
func nothing() {
}
}
let object = Object()
object.nothing()
object.nothing()We create an instance of the Object class and call a nothing method. The nothing method is empty and calling it does nothing. The Swift compiler understands that and removes those method calls. After this we have only one line of code:
let object = Object()
The Swift compiler can also obviate the creation of objects that are never used. It reduces memory usage and unnecessary function calls, which also reduces CPU usage. In our example the object instance is not used after removing the nothing method call and the creation of Object can be dispensed with as well. This way, Swift removes all three lines of code and we end up with no code to execute...
Change the font size
Change margin width
Change background colour