O'Reilly logo

Swift Quick Syntax Reference by Matthew Campbell

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter    42

De-initialization

When an instance is no longer need, Swift deallocates the instance and frees up the instance resources. For the most part, this is an automatic process that you don’t need to worry about when you are using standard Swift types. However, if you are using resources that need to be manually freed up (such as open files), you can de-initialize these resources by overriding the deinit method (see Listing 42-1).

Listing 42-1. deinit Method

class Person {    var name: String = "Name"    var age:Int = 0    func profile() -> String {        return "I'm \(self.name) and I'm \(self.age) years old."    }    deinit {        //Remove any resources outside of standard        //types and objects here    }}

In Listing 42-1, you ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required