Post

Replies

Boosts

Views

Activity

iTunesLibrary - Swift
I started dabbling with the iTunes library for Swift and came across the example below on line for reading data from the library on MacOS. However, I keep getting hit with a "Type of expression is ambiguous without more context" error on line 6. I can't think of what is causing the error, any ideas ? func ListTunes(){     if let library = try? ITLibrary(apiVersion: "1") {                 print(library.applicationVersion)                 for artist in library.allMediaItems                     .filter({ $0.mediaKind == ITLibMediaItemMediaKind.kindSong })                         .group(by: { $0.artist?.title }){                             print(artist.key)                     for album in artist.value.group(by: { $0.album.title }) {                         print(" \(album.key) (\(album.value.first!.year))")                     }                 }             } }
1
0
477
May ’21
actionSheet failing to appear
I created a view (headerView) that contains an 'info' button, this view sits at the top of the screen and various views are shown beneath it. When pressed an actionSheet should appear, everything was working fine but suddenly the actionSheet refuses to appear, when pressed, the button is changing the state variable to true as expected and even the phone vibrate triggers, the only thing not working is the actionSheet appearing. Swapping actionSheets for an alert gives the same issue. Here's the code to generate the view and the actionSheet:     struct headerView: View {         @State var showInfo : Bool = true         var body: some View {             HStack(alignment: .bottom){                 Image(systemName: "info.circle")                     .padding(.trailing)                     .font(.title)                     .foregroundColor(.blue)                     .foregroundColor(.blue)                     .frame(width: 35.0, height: 35.0)                     .hidden()                                 Spacer()                 Image("Icon")                     .resizable()                     .frame(width: 45, height: 45)                     .cornerRadius(5.0)                 Image("TextHeader_light")                     .resizable()                     .frame(width: 107.0, height: 39.0)                 Spacer() // info button                 Button(action: {                     showInfo = true                 AudioServicesPlaySystemSound(kSystemSoundID_Vibrate)                     print (showInfo)                 }) {                     Image(systemName: "info.circle")                         .resizable()                         .padding([.bottom, .trailing])                         .font(.title)                         .foregroundColor(.blue)                         .frame(width: 35.0, height: 35.0)                 }             }             .actionSheet(isPresented: $showInfo)  {                 ActionSheet(title: Text("Title Text"),                             message: Text("My text goes here"),buttons: [.cancel {showInfo = false; print(showInfo)}])             }         }     }
3
0
516
Apr ’21
Omit items from List without leaving a gap in produced list
I'm working on an app in SwiftUI, Xcode 12.4 / iOS14. In one view I need to produce a list - but the data for the list is subject to an if / else condition - if a condition is met then the item should be omitted from the list. This works - but the list now has gaps in it from where items have been omitted. Question is - is there a way to produce a list and omit the gaps or would I need to rebuild a new set of data using the if / else condition and then pass that to the list to avoid gaps ?
4
0
687
Apr ’21
Data between views
Hi I am writing a small app mainly for practice and am having difficulty JSON data retrieved from a remote server between views. Using the code below I am able to retrieve my data from the server decode it etc and make a list - import SwiftUI import Combine import Foundation struct FlightView: View {     @ObservedObject var fetcher = FlightFetcher()          var body: some View {         NavigationStack{             VStack {                 List(fetcher.flights) { flight in                     NavigationLink(destination: DetailView(flightDetail: Flight)) {                         Text(flight.station_code)                         Text(flight.fltno)                     }                 }             }         }     } } public class FlightFetcher: ObservableObject { @Published var flights = [Flight]()     init(){         load()     }     func load() {         let url = URL(string: "my address")!              URLSession.shared.dataTask(with: url) {(data,response,error) in             do {                 if let d = data {                     let decodedLists = try JSONDecoder().decode([Flight].self, from: d)                     DispatchQueue.main.async {                         self.flights = decodedLists                     }                 }else {                     print("No Data")                 }             } catch {                 print ("Error")             }         }.resume()     } } struct Flight: Hashable, Identifiable, Codable {     var id: Int     var station_code: String     var ac_type: String     var fltno: String     var delay_incurred: String     var nightstop: String     var delay_mins: Int     var date: String     var delay_defect: String     var std: String     var atd: String     var delay_count: Int     var regn : String     var call_type : String     var movement_ind : Int } Okay, so that fetched the data and makes the list as we'd expect. The difficulty comes when trying to use the navigation link to take me to a detailed view. I cannot seem to be able to pass the data to the DetailView view. import SwiftUI import Combine import Foundation struct DetailView: View {    // @EnvironmentObject var flights: FlightFetcher     var flightDetail: Flight     var body: some View {         VStack{             Text("Flight Details:")             Text(flightDetail.fltno)         }     } } I have tried various methods, including @EnvironmentObject (commented out above) to pass the data from the FlightView to the DetailView so that the other parameters of the Flight struct can be shown in the view (ac_type, date etc...) I'm not sure where I'm going wrong on this one.
2
0
359
Jun ’22
Archived App won't distribute for Development or Ad Hoc.
Suddenly an app that I am developing will not download from my website when I try and distribute it after archiving, either for Ad-Hoc or development options. It used to work but suddenly now the icon will appear on the iOS device and initially say 'waiting' then nothing, the icon just sits there greyed out. If you tap the icon you get the error "xxx cannot be downloaded right now, try again later" From what I can see I haven't changed any settings on the app since I last uploaded it and it downloaded / worked. (just minor bug fixes in the interface) I did delete the app fully from the iOS device before trying to reload it. My developer account is still valid and I am sending the 'app.ipa' and 'manifest.plist' files to an HTTPS location. Anyone have any experience of this and any fixes ? Xcode 12.4, Mac mini M1.
1
0
915
Mar ’21