From the course: iOS Development Tips

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Overriding operators

Overriding operators

- [Instructor] From your first programming experience you've used operators such as plus and minus. For example, in my playground here I have addition and concatenation using the plus operator. In Swift, you can customize this for any type. Let's learn how. I have up here a modified version of my familiar menu model I use in many of the tips in the SwiftUI Essential Training course. It contains an array of menu items which are structs with multiple values in it, which you can see here in menu item. To make an array of menu items from two menu items, I could do this using the arrays plus operator, and what you're going to do is it'll start with static, and then func, and then this is a function which has plus as its identifier, and then two values. The first one'll be item one, which will be a menu item. And the second one will be item two. And that will return an array of menu item. Now, somewhere in the function I must…

Contents