---
title: "Why do we need to use @Synthesize?"  
description: "Why do we need to use @Synthesize?"  
author: "Tarun Kumar"  
published: 2015-07-14  
updated: 2020-09-19  
canonical: https://www.mindstick.com/interview/2700/why-do-we-need-to-use-synthesize  
category: "iphone"  
tags: ["iphone", "ios", "objective c"]  
reading_time: 2 minutes  

---

# Why do we need to use @Synthesize?

when you create a property...

```
@property NSString *name;
```

Xcode will auto synthesise an iVar as if you had written...

```
@synthesize name = _name;
```

This means you can access the property with...

```
self.name;
// or
_name;
```

Either will work but only `self.name` actually uses the accessor methods.

There is only one time that auto synthesise does not work.

If you overwrite but the setter AND the getter method then you will need to synthesise the iVar.

You are fine if you just override the setter or if you just override the getter. But if you do both then the compiler won't understand it and you will need to synthesise it manually.

As a rule of thumb though.

Don't make iVars. Just use the property. Don't synthesise it.

## Answers

### Answer by Tarun Kumar

when you create a property...

```
@property NSString *name;
```

Xcode will auto synthesise an iVar as if you had written...

```
@synthesize name = _name;
```

This means you can access the property with...

```
self.name;
// or
_name;
```

Either will work but only `self.name` actually uses the accessor methods.

There is only one time that auto synthesise does not work.

If you overwrite but the setter AND the getter method then you will need to synthesise the iVar.

You are fine if you just override the setter or if you just override the getter. But if you do both then the compiler won't understand it and you will need to synthesise it manually.

As a rule of thumb though.

Don't make iVars. Just use the property. Don't synthesise it.


---

Original Source: https://www.mindstick.com/interview/2700/why-do-we-need-to-use-synthesize

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
