Native Shopify Mobile App with 20 new features
Kickstart your hyperlocal marketplace in Corona pandemic with a starter guide
Android App Development
iOS App Development
Cross Platform App Development
Hire on-demand project developers and turn your idea into working reality.
Big thanks to Webkul and his team for helping get Opencart 126.96.36.199 release ready!
Owner and Founder. Opencart
As we have checked in our previous blog, we learned about some higher-order functions in swift.
In this blog, we are going to explore more Higher-Order functions in swift.
If you have not read our previous blog, please do check that blog as well from here.
forEach will iterate through all elements in an array. And unlike for in you can’t use a break and continue statement to exit from the closure for forEach.
Output: 1 3 8 5 6
As in our previos blog we have already learned about map, in this blog we will understand the types of map, i.e. compactMap and flatMap
The compactMap(_:) will iterate through all elements in an array and will remove nil values from the input array. It’s basically used when we are working with optionals.
Output: [1, 3, 5, 6]
flatMap converts 2D array to one-dimensional array.
Output: [1, 2, 3, 4, 5, 6, 7, 8, 9]
sort(by:) will sort all elements according to the condition written inside the body of the closure in the same array.
Output: [8, 6, 5, 3 ,1]
sorted(by:) will sort all elements according to the condition written inside the body of the closure and returns a new array.
numbers: [1, 3, 8, 5, 6]
sortedArray: [8, 6, 5, 3 ,1]
For more understanding of higher-order functions please check here.
For more interesting blogs check out here – https://mobikul.com/blog/.
Thanks for reading 🙂
Your email address will not be published. Required fields are marked*
Save my name email and website in this browser for the next time I comment.
Be the first to comment.
Very good company, we did get app extension for Magento 2 website. The support was very good they help us through the process. Webkul team is very supportive, I would recommend them.
Enquiry or Requirement
If you have more details or questions, you can reply to the received confirmation email.