Aleksandar • Vacić

iOS bits and pieces

Swift 3 migration tip: 'instance method ... nearly matches' warning

If during transition to Swift 3 in Xcode 8 you get a warning like this:

1
2
3
4
 Instance method 'application(_:didFinishLaunchingWithOptions:)'
 nearly matches optional requirement
 'application(_:didFinishLaunchingWithOptions:)'
 of protocol 'UIApplicationDelegate'

Don’t do any of the supplied fix-its. Instead, just type the same method again and you will see that the signature has changed:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// OLD
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?)
-> Bool {

  self.window?.makeKeyAndVisible()
  return true
}

// NEW
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil)
-> Bool {

  self.window?.makeKeyAndVisible()
  return true
}

Given fix-its only hide the issue, don’t really fix it.

WWDC16

In a few days, I’m going to my first ever WWDC. I expect it to be an interesting experience in itself, regardless of what Apple announces.

I’ll use this post as a quick dump of thoughts and things I hope to see / hear from Apple.

Masterclass: Code signing & Provisioning profiles

The voodoo.

The dark alley.

Never works.

Do not touch “Fix issues” ever, it will ruin everything!

I can list hundred more scary quotes that various iOS developers will tell you. And for years this was actually close to the truth, as Xcode’s integrated attempts to ease the management of the profiles were less than stellar.

This is extremely complicated and convoluted part of the iOS developer life. Apple recognizes this and Xcode and iTunes Connect / Developer Portal teams have worked for years to make this work seamlessly.

So next time when you are fed up with all the nonsense and just want to burn it all – go and do just that. Seriously, make a clean start.

Masterclass: Constants and Flags

You have probably seen something like this many times:

1
2
3
4
5
6
7
#define kMySegueIdentifier @"SegueMain"
#define reuseIdentifier @"TABLECELL"
#define FONT_SIZE 14.0f
#define CELL_CONTENT_WIDTH 320.0f
#define CELL_CONTENT_MARGIN 10.0f

CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:FONT_SIZE] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];

This is usually found in quick&dirty code samples, to define constants. You can also see it in many older APIs, where various constants were defined this way. This is bad. It works, but it’s lazy.

#define is pre-processor directive and should not be used to define numbers and strings that will then be used as part of the actual code. It’s a hard-coded value that lives in its own memory space, outside of your regular scope.

Use proper, modern stuff that Objective-C offers and Xcode supports very well.