IOS Swift Tutorial 22 question

+1 i k · November 11, 2015
Hi, In this tableview code I do not understand the swift syntax:

func tableView( tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

}

I'm confused about the numberOfRowsInSection section: Int part. I thought that in Swift you have parameters as "name : type", but now we seem to have "two names : type" ? Is section a Int? But what does numberOfRowsInSection indicate here? The same question arises in the next function, this time with "cellForRowAtIndexPath indexpath : NSIndexPath"

br,

Post a Reply

Replies

Oldest  Newest  Rating
0 Aju Antony · November 19, 2015
Hi, 

In Swift the parameters can me declared in two different ways "name: type" as you already know, and also "externalParameterName localParameterName: type".

The 'externalParameterName' is used when the function is called, and the 'localParameterName' is used as that variable name inside the current function.

for example,

func registerName (firstName firstEntry: String, lastName nextEntry: String) {
  firstEntry = //Do Something with firstEntry
  nextEntry = //Do Something with nextEntry
}

...

registerName(firstName: "Aju", lastName: "Antony")


and those functions are protocols for TableView Delegates. You can look into Protocols in Swift here,
https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Protocols.html

Hope that clears it up for you :)

For more information on Functions in Swift, check here,
https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Functions.html

Happy Coding :D
  • 1

iOS Development / Swift

107,109 followers
About

This forum is for questions, comments, and general discussion about iOS Development and Swift.

Links
Moderators
Bucky Roberts Administrator