Wrox Programmer Forums
BOOK: Swift iOS 24-Hour Trainer
This is the forum to discuss the Wrox book Swift iOS 24-Hour Trainer Abhishek Mishra; ISBN: 978-1-119-07355-0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Swift iOS 24-Hour Trainer section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old June 11th, 2016, 01:41 PM
Registered User
Join Date: Jun 2016
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Parameters in function calls

I'm an experienced C, C++, and Java programmer looking to port an app to the iOS environment. I'm learning Swift by using three sources: the Swift iOS 24-hour Trainer, the Apple documentation at https://developer.apple.com/library/...age/index.html, and testing using a playground on my Mac Mini.

I'm finding Swift's handling of parameters in function calls bizarre. I think neither the book nor the Apple pages explain it well.

From what I've been able to suss out, function parameters may be either positional as in myPositionalFunc(1,2,3) or named as in myNamedFunc(x:1,y:2,z:3). The name MUST NOT appear in the call if the parameter is positional, and the name MUST appear if the parameter is named, i.e., there's no choice about whether or not to include the name in the call.

The first parameter is different from the second and following parameters. The first parameter is positional by default, but it is named if the function definition is declared with an external name.

The second and following parameters are named by default, but they are positional if the function definition is declared with an external name of "_".

init() seems to be a special case. All parameters are named by default.

Is there anywhere in the book or the Apple documentation I can go to see if my analysis of this behavior is correct?
Old June 15th, 2016, 03:32 PM
Wrox Author
Join Date: Jun 2016
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts

Hi JerryAgin,

The manner in which parameters will be handled in Swift 3 is different from that in 2.2. Swift 3 will be released along with Xcode 8 and iOS 10 in fall this year.

If you still want a Swift 2.2 answer, please let me know. If you'd rather wait for Swift 3 then I can answer your question a few days later.
Old June 16th, 2016, 11:22 AM
Registered User
Join Date: Jun 2016
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts

I'm doing some further reading. https://developer.apple.com/library/...015214-CH3-SW1 pretty much verifies what I thought about how args work.

I'm getting the impression that Objective-C also works that way. Since I'm coming from a different programming background, it's something I didn't expect to see.

So they're going to change the language? Sounds to me like an even bigger can of worms!

Similar Threads
Thread Thread Starter Forum Replies Last Post
Nesting tags / function calls possible? Obsidian3d XSLT 4 March 30th, 2007 03:46 PM
VB code that calls a function mikefemi Beginning VB 6 1 January 11th, 2006 06:12 AM
object parameters to remote method calls DotNetJunk General .NET 1 April 29th, 2005 04:02 AM
function calls ricmar Access VBA 3 September 24th, 2004 09:15 AM
XSL calls java function - prob vetrikam XSLT 2 October 9th, 2003 10:33 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.