Labels vs no labels in parameters (p124)

On p124 you see the line:
webView.loadData(htmlData, MIMEType: “text/html”, textEncodingName: “UTF-8”, baseURL: baseURL)

The first parameter does not have a label, but the subsequent ones do. Why is this? I’d expect it to have “data:” before it.

It’s a holdover from how Objective C functions were named. The ‘data:’ you’re looking for is the ‘Data’ in the name ‘loadData’.

That said: this is going to change in Swift 3. The first argument will no longer be an exception to the rules which apply to the others.

1 Like

Thank you for the response, narrativium. So leaving it off was to make it read better (instead of saying loadData(data: htmlData… In Swift 3 the “data:” label would be used?

The equivalent Objective C function in the UIWebView class looks like this:
-(void) loadData: MIMEType: textEncodingName: baseURL:
(called like this:)
[webView loadData:htmlData MIMEType:"text/html" textEncodingName:"UTF-8" baseURL:baseURL];

In Objective C there’s no distinction in the function call between the name of the function and the first argument. In Swift there is, but they decided not to require developers to type it out as loadData(data: ... because they’d have to type the word ‘data’ twice.

Excellent, thank you narrativium, it clears up a lot for me!

BTW, after getting into iOS Apprentice Tutorial 2: Checklists, I see that this issue is covered on pages 31-32. :slight_smile: