• Home
  • About
  • Our Apps
  • Learn
  • Contact
Login

Register

Login
Seemu Apps Seemu Apps
  • Home
  • About
  • Our Apps
  • Learn
  • Contact

Swift check if an element is in an array

Home ios Swift check if an element is in an array

Swift check if an element is in an array

Apr 12, 2016 | Posted by Andrew | ios, swift, tutorial, xcode |

Checking if an element is an an array in swift is easy, with no special code required. In the example below we search our array the number “3” and print out “yes” if it is found:

        let elements = [3, 6, 9, 1, 7, 9]
        if elements.contains(3) {
            print("yes")
        }

Since our array does in fact contain the number 3, it will print out “yes” to the console. This can be used for objects other then numbers like the integers in the example above. Strings, booleans and other data types can be used to see if the array contains the value.

DownloadSourceCode

 

Tags: arraycontainsnumbersearch
1
Share

About Andrew

Andrew is a 24 year old from Sydney. He loves developing iOS apps and has done so for two years.

You also might be interested in

Swift – Filter Bar Tutorial

Mar 9, 2017

In our previous tutorial we implemented a search bar for[...]

Swift – Search Bar Tutorial

Mar 5, 2017

In this tutorial we are going to implement a search[...]

Swift Extensions – speed up app development

May 24, 2017

Swift Extensions are quite a powerful feature and Swift and[...]

Welcome

Hi I am Andrew and welcome to Seemu Apps! Have a look around, we provide tutorials for primarily iOS apps.
Bluehost website hosting discount

Seemu’s Studio Setup

Blue Yeti Microphone
Rode Stand
Spider Shock Mount
Mac Keyboard Cover
Screenflow - recording software

Contact Us

We're currently offline. Send us an email and we'll get back to you, asap.

Send Message

Footer

:)

© 2025 · Your Website. Theme by HB-Themes.

  • Home
  • About
  • Our Apps
  • Learn
  • Contact
Prev Next