Back to Mobile App

iOS Swift Tutorial

Master Swift and SwiftUI to build native iOS applications. Learn modern iOS development with Apple's latest frameworks.

Video Tutorial ( Check his full course on YT)

Introduction to Swift and iOS Development

Swift is Apple's powerful and intuitive programming language for iOS, macOS, watchOS, and tvOS. Learn the basics of Swift and Xcode to start building iOS apps.

Examples:

// Swift Basics
var greeting = "Hello, iOS!"
let appName = "My First App"
var version = 1.0

print(greeting)

// Functions
func greetUser(name: String) -> String {
    return "Welcome, \(name)!"
}

print(greetUser(name: "Developer"))

// Arrays and Loops
let frameworks = ["SwiftUI", "UIKit", "CoreData"]
for framework in frameworks {
    print(framework)
}

Basic Swift syntax and fundamentals

SwiftUI Basics

SwiftUI is Apple's modern framework for building user interfaces across all Apple platforms with declarative Swift syntax.

Examples:

import SwiftUI

struct ContentView: View {
    var body: some View {
        VStack(spacing: 20) {
            Text("Hello, SwiftUI!")
                .font(.largeTitle)
                .fontWeight(.bold)
                .foregroundColor(.blue)
            
            Text("Build amazing iOS apps")
                .font(.subheadline)
                .foregroundColor(.gray)
            
            Button(action: {
                print("Button tapped!")
            }) {
                Text("Get Started")
                    .padding()
                    .background(Color.blue)
                    .foregroundColor(.white)
                    .cornerRadius(10)
            }
        }
        .padding()
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

Basic SwiftUI view with text and button

State Management

Learn how to manage state in SwiftUI using @State, @Binding, and @ObservedObject property wrappers.

Examples:

import SwiftUI

struct CounterView: View {
    @State private var count = 0
    
    var body: some View {
        VStack(spacing: 20) {
            Text("Count: \(count)")
                .font(.largeTitle)
                .fontWeight(.bold)
            
            HStack(spacing: 20) {
                Button(action: {
                    count -= 1
                }) {
                    Image(systemName: "minus.circle.fill")
                        .font(.largeTitle)
                        .foregroundColor(.red)
                }
                
                Button(action: {
                    count += 1
                }) {
                    Image(systemName: "plus.circle.fill")
                        .font(.largeTitle)
                        .foregroundColor(.green)
                }
            }
            
            Button("Reset") {
                count = 0
            }
            .padding()
            .background(Color.gray.opacity(0.2))
            .cornerRadius(8)
        }
        .padding()
    }
}

State management with @State property wrapper

Lists and Navigation

Create scrollable lists and implement navigation between views in SwiftUI.

Examples:

import SwiftUI

struct Item: Identifiable {
    let id = UUID()
    let title: String
    let description: String
}

struct ListView: View {
    let items = [
        Item(title: "SwiftUI", description: "Modern UI framework"),
        Item(title: "UIKit", description: "Classic UI framework"),
        Item(title: "CoreData", description: "Data persistence")
    ]
    
    var body: some View {
        NavigationView {
            List(items) { item in
                NavigationLink(destination: DetailView(item: item)) {
                    VStack(alignment: .leading) {
                        Text(item.title)
                            .font(.headline)
                        Text(item.description)
                            .font(.subheadline)
                            .foregroundColor(.gray)
                    }
                }
            }
            .navigationTitle("iOS Frameworks")
        }
    }
}

struct DetailView: View {
    let item: Item
    
    var body: some View {
        VStack {
            Text(item.title)
                .font(.largeTitle)
            Text(item.description)
                .font(.body)
                .padding()
        }
        .navigationTitle("Details")
    }
}

List view with navigation

Networking and API Calls

Learn how to fetch data from APIs and display it in your iOS app using URLSession and Codable.

Examples:

import SwiftUI

struct Post: Codable, Identifiable {
    let id: Int
    let title: String
    let body: String
}

class NetworkManager: ObservableObject {
    @Published var posts: [Post] = []
    @Published var isLoading = false
    
    func fetchPosts() {
        isLoading = true
        guard let url = URL(string: "https://jsonplaceholder.typicode.com/posts") else {
            return
        }
        
        URLSession.shared.dataTask(with: url) { data, response, error in
            if let data = data {
                if let decodedPosts = try? JSONDecoder().decode([Post].self, from: data) {
                    DispatchQueue.main.async {
                        self.posts = decodedPosts
                        self.isLoading = false
                    }
                }
            }
        }.resume()
    }
}

struct PostsView: View {
    @StateObject private var networkManager = NetworkManager()
    
    var body: some View {
        NavigationView {
            Group {
                if networkManager.isLoading {
                    ProgressView()
                } else {
                    List(networkManager.posts) { post in
                        VStack(alignment: .leading) {
                            Text(post.title)
                                .font(.headline)
                            Text(post.body)
                                .font(.caption)
                                .foregroundColor(.gray)
                        }
                    }
                }
            }
            .navigationTitle("Posts")
            .onAppear {
                networkManager.fetchPosts()
            }
        }
    }
}

Fetching and displaying API data

Quick Reference

Essential Tools

  • Xcode - Official IDE for iOS development
  • SwiftUI - Modern UI framework
  • UIKit - Classic UI framework
  • CoreData - Data persistence

Best Practices

  • ✓ Use SwiftUI for new projects
  • ✓ Follow Apple's Human Interface Guidelines
  • ✓ Use property wrappers effectively
  • ✓ Test on real devices when possible