Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

What is the technical term for less-than/greater-than symbols when used in a function definition?

I have seen the use of less-than/greater-than symbols when defining a function in the WWDC 2015 video "Protocol-oriented Programming in Swift" and in many other places. Here is an example of what I am talking about:

func swap<T>(inout a: T, inout with b: T) { (a, b) = (b, a) }

I've looked in the Swift Programming Guide on Apple's website and can't find any examples so far. Can anyone point me to where it's described in the documentation and/or tell me what the use of less-than/greater-than is called?

Hope that made sense :)

2 Answers

Hello:

The example you are showing is a function using in-out parameters, which swap parameter values.

The value in the parameter a is swapped to parameter b. The symbol your are looking at = is the assign operator. You can read all about it Here.

You can also find information about the "Comparison Operators" Here

Comparison Operators

/*
- **Equal to (a == b)**
- **Not equal to (a != b)**
- **Greater than (a > b)**
- **Less than (a < b)**
- **Greater than or equal to (a >= b)**
- **Less than or equal to (a <= b)**
*/

Hope you find this information useful

Good luck.

Thanks, Jhoan! I just noticed a problem with my original question. My greater-than/less-than's were stripped out of my question because I didn't wrap my code in pre tags. I actually just now found the answer as well. They're called type parameters in generics. Here is the function I meant to post: <pre> func swap<T>(inout a:T, inout with b:T) { (a, b) = (b, a) } </pre>

Thanks again for your reply!!!

https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Generics.html