What does @synthesize window=_window do?

Your properties almost always have a backing variable. What

@synthesize searchBar = _searchBar;

does is declare that the backing variable for your search bar will be called _searchBar. This allows you to decouple the name of the property from the name of your variable. In fact, if you don’t use @synthesize you don’t need to have a backing variable at all.

As for why people do this, everyone has different reasons. Personally, I do it to

  1. avoid clashes with variable names and
  2. make it clear when I’m using a local variable and when I’m using an instance variable.

Leave a Comment