# Swift App example on GitHub

**URL:** <https://community.particle.io/t/swift-app-example-on-github/12733>\
**Category:** Developer Tools\
**Created:** [June 22, 2015, 12:22pm UTC](https://community.particle.io/t/swift-app-example-on-github/12733 "2015-06-22T12:22:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bendrix](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/bendrix/32/5001_2.png) [@Bendrix](https://community.particle.io/u/Bendrix)\
**Post date:** [June 22, 2015, 12:22pm UTC](https://community.particle.io/t/swift-app-example-on-github/12733/1 "2015-06-22T12:22:11Z")

</div>

I've put up an example Swift App and the corresponding Core/Photon firmware on GitHub. My username is BendrixL. It has been forked and vetted by another forum member so I'm reasonably sure it will work for you. To use the app you should have the latest version of Xcode/Swift. Follow the instructions posted here to install cocoa pods on your Mac.

> [@Mobile SDK Install - Detailed help for Cocoapods install](https://community.particle.io/t/mobile-sdk-install-detailed-help-for-cocoapods-install/11920/18):
>
> I found that there is help for Pod if entered as Pod --help. From there I learned that you can create a Podfile in the currently pointed to directory by typing Pod init. I did that and it created a second Podfile in my project root directory, right alongside the one I created. The file created with init is listed as a text file. The one I created is listed as a TextEdit Document. Neither has an extension but somehow they are different, which might explain why pod install could not find a po…

You only need to take those instructions as far as the cocoa pods install on your Mac. The pods install to the project is all done and will come down with the fork from GitHub.

This app uses your username and password to log into Particle, and then your device name to access your core/photon. The app reads two variables and activates one function. Each operation is under the control of a single button on the UI. The code is reasonably well documented and as far as the access to the Mobile SDK, it is line for line what @ido posted on the help page.

You can run it as is, with the corresponding firmware (also on GitHub), or change the names of the variables and function to match something you've got running on your device.

If you have questions, problems, or suggestions, please contact me here.

The data displayed in the example is raw sensor data. I removed the math I used as I would not know what your circuit might be. Add some math to make sense of the sensor data.

Challenge: After you look at the code, you might say, wouldn't it be nice to update the variable each time I run the function. You might consider cutting and pasting the variable code into the class with the function call. The problem is that you won't get the current reading, you'll be one reading behind because the function will not have run before the variable is accessed. The two closures are asynchronous. Here is the challenge. Add code to read the variable after the function is run but force the variable read to wait until the function returns. I've been poking around Stack Overflow and other sources but not been able to come up with something that works. Lots of people have made suggestions, but nothing yet has worked. Good luck!

---

<div class="post-metadata">

**Author:** ![sazp96](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/sazp96/32/4153_2.png) [@sazp96](https://community.particle.io/u/sazp96)\
**Post date:** [June 22, 2015, 7:49pm UTC](https://community.particle.io/t/swift-app-example-on-github/12733/2 "2015-06-22T19:49:48Z")

</div>

@Bendrix thank you for building and sharing this app. It worked on the first run. Very cool stuff.

Also, thanks for the detailed installation guide. This being my first time playing with iOS, I needed a guide like yours.

Cheers!

---

<div class="post-metadata">

**Author:** ![N2B8](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/n2b8/32/7522_2.png) [@N2B8](https://community.particle.io/u/N2B8)\
**Post date:** [October 16, 2015, 6:06am UTC](https://community.particle.io/t/swift-app-example-on-github/12733/3 "2015-10-16T06:06:52Z")

</div>

This helped me so much! Thanks for saving me from many more hours of frustration.
