0
0
iOS Swiftmobile~20 mins

Certificates and provisioning profiles in iOS Swift - Mini App: Build & Ship

Choose your learning style9 modes available
Build: Certificate Manager
This screen helps users view and manage their iOS development certificates and provisioning profiles. Users can see a list of certificates and profiles, and tap to view details.
Target UI
----------------------------------
| Certificate Manager             |
----------------------------------
| Certificates:                  |
|  * Dev Cert 1                 |
|  * Dev Cert 2                 |
|                              |
| Provisioning Profiles:        |
|  * Profile A                  |
|  * Profile B                  |
|                              |
| [Refresh]                    |
----------------------------------
Display two sections: Certificates and Provisioning Profiles
Each section lists at least two items with simple names
Add a Refresh button at the bottom to reload the lists
Tapping an item shows an alert with the item name and type
Use a simple SwiftUI List layout with sections
Ensure accessibility labels for buttons and list items
Starter Code
iOS Swift
import SwiftUI

struct CertificateManagerView: View {
    // Sample data arrays
    let certificates = ["Dev Cert 1", "Dev Cert 2"]
    let profiles = ["Profile A", "Profile B"]

    var body: some View {
        NavigationView {
            List {
                Section(header: Text("Certificates")) {
                    // TODO: List certificates here
                }
                Section(header: Text("Provisioning Profiles")) {
                    // TODO: List provisioning profiles here
                }
            }
            .navigationTitle("Certificate Manager")
            .toolbar {
                // TODO: Add Refresh button here
            }
        }
    }
}

struct CertificateManagerView_Previews: PreviewProvider {
    static var previews: some View {
        CertificateManagerView()
    }
}
Task 1
Task 2
Task 3
Task 4
Solution
iOS Swift
import SwiftUI

struct CertificateManagerView: View {
    @State private var certificates = ["Dev Cert 1", "Dev Cert 2"]
    @State private var profiles = ["Profile A", "Profile B"]
    @State private var showingAlert = false
    @State private var selectedItem = ""
    @State private var selectedType = ""

    var body: some View {
        NavigationView {
            List {
                Section(header: Text("Certificates")) {
                    ForEach(certificates, id: \.self) { cert in
                        Button(action: {
                            selectedItem = cert
                            selectedType = "Certificate"
                            showingAlert = true
                        }) {
                            Text(cert)
                        }
                        .accessibilityLabel("\(cert), Certificate")
                    }
                }
                Section(header: Text("Provisioning Profiles")) {
                    ForEach(profiles, id: \.self) { profile in
                        Button(action: {
                            selectedItem = profile
                            selectedType = "Provisioning Profile"
                            showingAlert = true
                        }) {
                            Text(profile)
                        }
                        .accessibilityLabel("\(profile), Provisioning Profile")
                    }
                }
            }
            .navigationTitle("Certificate Manager")
            .toolbar {
                Button(action: refreshLists) {
                    Text("Refresh")
                }
                .accessibilityLabel("Refresh certificates and profiles")
            }
            .alert(isPresented: $showingAlert) {
                Alert(title: Text(selectedType), message: Text(selectedItem), dismissButton: .default(Text("OK")))
            }
        }
    }

    func refreshLists() {
        // Simulate refreshing by shuffling the lists
        certificates.shuffle()
        profiles.shuffle()
    }
}

struct CertificateManagerView_Previews: PreviewProvider {
    static var previews: some View {
        CertificateManagerView()
    }
}

This SwiftUI view shows two sections in a list: Certificates and Provisioning Profiles. Each section uses a ForEach to list items as buttons. When a user taps an item, an alert pops up showing the item's name and type.

The Refresh button in the toolbar calls refreshLists(), which shuffles the arrays to simulate reloading data.

Accessibility labels are added to buttons for screen readers, describing the item and its type. The UI uses a NavigationView with a title for clarity.

Final Result
Completed Screen
----------------------------------
| Certificate Manager             |
----------------------------------
| Certificates:                  |
|  * Dev Cert 2                 |
|  * Dev Cert 1                 |
|                              |
| Provisioning Profiles:        |
|  * Profile B                  |
|  * Profile A                  |
|                              |
| [Refresh]                    |
----------------------------------
Tapping a certificate or profile shows an alert with its name and type
Tapping Refresh shuffles the lists to simulate reloading
Screen reader reads item names and types due to accessibility labels
Stretch Goal
Add a dark mode toggle button that switches the app's color scheme between light and dark.
💡 Hint
Use @Environment(\.colorScheme) and a @State variable to toggle between .light and .dark modes.