Synthesize By Default

In 2012 Apple introduced Synthesize By Default in Xcode. You no longer have to synthesize instance variables. Just declare them as you normally would in the .h file and the compiler will automatically synthesize them for you. I learned how to use Xcode before the transition so I just learned about this by accident. If you haven’t done so, watch these two videos from WWDC 2012: Session 405 – Modern Objective-C and Session 413 – Migrating to Modern Objective-C.

Synthesize By Default is not available for NSManagedObjects so if your header file contains something like this:


@interface WordList : NSManagedObject

You’ll have to synthesize.

You can still manually create setters or getters and the compiler will automatically create the other accessor.

One caveat. I stopped supporting iOS4.3 and still have code that is compatible with iOS4. Since doesn’t have the weak indicator, you need to change assign to weak, then delete the ‘__unsafe_unretained id delegate;’ line. Then you can delete the @synthesize. If you still want to support iOS4, you’ll need to synthesize these variables.

Before


@implementation PracticeSightWords
@synthesize delegate = _delegate;


@interface PracticeSightWords : UIViewController {
    
    __unsafe_unretained id <PracticeSightWordsDelegate> delegate;
}

@property (nonatomic, assign) id <PracticeSightWordsDelegate> delegate;

After


@interface PracticeSightWords : UIViewController 

@property (nonatomic, weak) id <PracticeSightWordsDelegate> delegate;

I have my compiler warnings Turned up to 11 so I needed to turn off the warnings for “Implicit Synthesized Properties” in the ‘Warnings-Objective C’ section of the build settings.

New Icons and Launch Images for iOS7

iOS7 requires new images for the icons and launch image and Xcode now provides a new way of validating that you have all of the required images.

Just to see what Xcode would do, I created a new app from scratch and looked at the images it requires.

Launch Images

I then took a look at what an existing app looks like. The first thing I noticed is that I forgot to include the 100×100 iPad retina image. Then I noticed that the last four launch images are the same as the ones that I already have.

Launch Images

I manually added the Portrait Non-Retina and it automatically found the retina version. Then I added the Landscape Non-Retina and it found the retina. I looked in the .plist for the app and Xcode had added lines for the new files. Since I have over 20 apps I didn’t want to repeat this 20 or more times so I right-clicked on the file, opened the .plist as source, then copied the following lines.


<key>UILaunchImages~ipad</key>
  <array>
    <dict>
      <key>UILaunchImageMinimumOSVersion</key>
      <string>7.0</string>
      <key>UILaunchImageName</key>
      <string>Default-Landscape</string>
      <key>UILaunchImageOrientation</key>
      <string>Landscape</string>
      <key>UILaunchImageSize</key>
      <string>{768, 1024}</string>
    </dict>
    <dict>
      <key>UILaunchImageMinimumOSVersion</key>
      <string>7.0</string>
      <key>UILaunchImageName</key>
      <string>Default-Portrait</string>
      <key>UILaunchImageOrientation</key>
      <string>Portrait</string>
      <key>UILaunchImageSize</key>
      <string>{768, 1024}</string>
    </dict>
  </array>

I pasted these lines into the same place in each of the .plists.

While I was at it, I added a line to my pre-iOS7 images list for the file I forgot to include. That section now looks like this:


  <key>CFBundleIconFiles</key>
  <array>
    <string>Icon.png</string>
    <string>Icon@2x.png</string>
    <string>Icon-72.png</string>
    <string>Icon-72@2x.png</string>
    <string>Icon-Small-50.png</string>
                <string>Icon-Small-50@2x.png</string>
    <string>Icon-Small.png</string>
    <string>Icon-Small@2x.png</string>
  </array>

I then used Xcode to add the new images. (Note: As far as I can tell, you can name them anything you want. I followed a logical extension of the old rules.) I used the same image for Spotlight iPad Retina and iPhone Retina (80×80) so I name it Icon-402x.png.
Xcode added an iPad section to the .plist. The .plist now looks like this:


<key>CFBundleIconFiles</key>
  <array>
    <string>Icon-40</string>
    <string>Icon-iPhone-60</string>
    <string>Icon.png</string>
    <string>Icon@2x.png</string>
    <string>Icon-72.png</string>
    <string>Icon-72@2x.png</string>
    <string>Icon-Small-50.png</string>
    <string>Icon-Small-50@2x.png</string>
    <string>Icon-Small.png</string>
    <string>Icon-Small@2x.png</string>
  </array>
  <key>CFBundleIconFiles~ipad</key>
  <array>
    <string>Icon-40</string>
    <string>Icon-iPad-76</string>
    <string>Icon-iPhone-60</string>
    <string>Icon.png</string>
    <string>Icon@2x.png</string>
    <string>Icon-72.png</string>
    <string>Icon-72@2x.png</string>
    <string>Icon-Small-50.png</string>
    <string>Icon-Small-50@2x.png</string>
    <string>Icon-Small.png</string>
    <string>Icon-Small@2x.png</string>
  </array>

Xcode has a new folder type for Asset Catalogs. I did not convert my icons to asset catalogs, but it looks like a good way to manage assets.