Code Examples

Swift Code Examples and Snippets

To receive Free Weekly Video Tutorials on Mobile App Development with Swift Programming Language, please subscribe to this blog. And yes :), book mark and share this page with your friends because new swift code snippets are being added every day. Please subscribe, let’s stay in touch!

Classes in Swift 

Functions in Swift

Swift Closures

Dictionaries in Swift 

Arrays in Swift

Strings

Storing Data, Writing and Reading in Swift

Error Handling in Swift

Date and DateComponents

Background Threads in Swift

Buttons in Swift

Working UITextField in Swift

UITextView

UISwitch in Swift

UISlider

Working with UIView

UIStepper

UISegmentedControl

UINavigationBar

UIImageView & UIImage

UIWebView

UIDatePicker

UIImagePickerController

UIActivityIndicatorView

UITabBarController

UIAlertController or Dialog messages in Swift

UITableView

UICollectionView

Presenting ViewController(s)

Network Communication  

Screen size and device orientation 

AVPlayerAVPlayerItem and AVPlayerLayer. Play Music. 


CoreLocation and MapKit

Amazon AWS

Facebook SDK for iOS

Touch ID Verification

Regular Expressions

Local and Remote Notifications

Determine Current iOS Device Model Name

  • Coração Tricolor

    Keep up the good work on iOS!

  • Tom Glodek

    Hi, Great Work.
    Do you have any code snippets that allow me to add or edit contacts programatically in swift 3 or 4, as well s select multiple contacts and populate them into a label ?

    • Hi Tom! Sorry, I did not do any code examples with Address book in Swift yet. May be I should look into it and make it one of my upcoming tutorials? 🙂

      • Tom Glodek

        That would be great. Another video you might consider is how to edit images , i.e. rotate, crop, change aspect 4:3, 16:9, change compression programatically from within an app.

        Thanks for the Great Work !

        • Thank you, Tom! I will add it to my todo list 🙂

  • Michael Rowe

    Glad to have found your blog, I Am trying to convert a Swift 2 app using SocailShare to a Swift 4 app and have to go to the FBShare and TwitterKit. Really struggling with both as my old app was very easy….

    if (sharingEnabled == 1) {
    let tweetSheet = SLComposeViewController(forServiceType: SLServiceTypeTwitter)
    tweetSheet?.setInitialText(message as String)
    self.present(composer, animated:true, completion:nil)
    } else if ( sharingEnabled == 2) {
    let fbSheet = SLComposeViewController(forServiceType: SLServiceTypeFacebook)
    fbSheet?.setInitialText(message as String)
    self.present(fbSheet!, animated:true, completion:nil)
    }
    Where message was a text message to share from within the app. Have you done anything like this with TwitterKit and FacebookShare? Keep up the great work on this blog.

    • Hi Machial! Not yet. But I have added SLComposeViewController to the list of my todo tutorials. I will have a look at it shortly and will publish a blog post and most likely video tutorial here on SwiftDeveloperBlog.com