Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Mobile Development > BOOK: Swift iOS 24-Hour Trainer
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old June 11th, 2016, 02:41 PM
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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?
Reply With Quote
  #2 (permalink)  
Old June 15th, 2016, 04:32 PM
Wrox Author
Points: 21, Level: 1
Points: 21, Level: 1 Points: 21, Level: 1 Points: 21, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2016
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.
Reply With Quote
  #3 (permalink)  
Old June 16th, 2016, 12:22 PM
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2016
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Nesting tags / function calls possible? Obsidian3d XSLT 4 March 30th, 2007 04: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 05:02 AM
function calls ricmar Access VBA 3 September 24th, 2004 10:15 AM
XSL calls java function - prob vetrikam XSLT 2 October 9th, 2003 11:33 PM



All times are GMT -4. The time now is 08:57 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.