Category: Short Read

  • SwiftUI .tabItem deprecated in iOS 18.1 -> replace it with new Tab

    In the newest Xcode, you might see a deprecation warning if you try to use .tabItem view modifier.

    💡

    ‘tabItem’ will be deprecated in a future version of iOS: Use Tab (title:image:value:content:) and related initializers instead

    As shown on the Apple Developer documentation:

    You can easily fix this by using the new Tab view:

    You can also easily add a badge (that shows a number or a character text), and use the value parameter to control which tab is currently activated:

  • The repository Debian GNU/Linux 12 DVD does not have a Release file – how to fix

    Run the following to open the editor for

    sudoedit /etc/apt/sources.list

    And comment out the first line by adding # to the beginning

    Problem solved!

  • SwiftUI List control spacing between sections (listSectionSpacing)

    In SwiftUI List, you can use the listSectionSpacing view modifier for List view to control how much space is in between different sections.

    Base code

    We will use this code as a starting point:

    //
    //  ListSpacingControl.swift
    //  WhatsNewIniOS18
    //
    //  Created by Msz on 8/10/24.
    //
    
    import SwiftUI
    
    struct ListSpacingControl: View {
        
        let planets: [String] = ["Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune"]
        let closeGalaxies = [
            "Milky Way",
            "Andromeda Galaxy",
            "Large Magellanic Cloud",
            "Small Magellanic Cloud",
            "Triangulum Galaxy"
        ]
        
        var body: some View {
            
            List {
                
                Section("Planets") {
                    ForEach(planets, id: \.self) { planet in
                        Text(planet)
                    }
                }
                
                Section("Galaxies") {
                    ForEach(closeGalaxies, id: \.self) { planet in
                        Text(planet)
                    }
                }
                
            }
            .listSectionSpacing(.default)
            
        }
        
    }
    
    #Preview {
        ListSpacingControl()
    }
    

    Default spacing

    Here, you can set the default spacing using the .default as the input to the view modifier.

    Compact spacing

    You can set it to compact for relatively small spacing between different sections.

    Custom spacing

    You can set a custom spacing by providing a number.