Post

Replies

Boosts

Views

Activity

Reply to Swift - AVPlayer - Stop player in another cell when a new player starts
Do you still get the error on line 93 ? If so, try the following: @IBAction func playPodcast(_ sender: Any) { if let collectionView = self.superview as? UICollectionView { let visibleCells = collectionView.visibleCells for cell in visibleCells { if let podCell = cell as? PodcastViewCell { print("cell is PodcastViewCell") if podCell.player != nil { print("podCell.player found") } else { print("podCell.player NOT found") } } else { print("cell is NOT PodcastViewCell") } } } And tell what you get exactly on console. Or simply change: if let collectionView = self.superview as? UICollectionView { let visibleCells = collectionView.visibleCells for cell in visibleCells where cell is PodcastViewCell { if (cell as! PodcastViewCell).player != nil { } }
Topic: Programming Languages SubTopic: Swift Tags:
May ’21
Reply to Wait until transaction is finished
It would help to know the exact error and the exact line where the error occurs. Where do you call purchase() ? public func purchase(product: Product, completion: @escaping () - Void) { guard SKPaymentQueue.canMakePayments() else { return } guard let storeKitProduct = products.first(where: { $0.productIdentifier == product.rawValue }) else { return } Utilities.purchaseFailed = Bool() let paymentRequest = SKPayment(product: storeKitProduct) SKPaymentQueue.default().add(self) SKPaymentQueue.default().add(paymentRequest) completion() } public func restore(completion: @escaping () - Void) { SKPaymentQueue.default().restoreCompletedTransactions() completion() } func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) { transactions.forEach({ transaction in switch transaction.transactionState { case .purchasing: //No op break case .purchased: handlePurchase(transaction.payment.productIdentifier) Utilities.purchaseFailed = false SKPaymentQueue.default().finishTransaction(transaction) break case .failed: Utilities.purchaseFailed = true Utilities.restoredPurchases = false SKPaymentQueue.default().finishTransaction(transaction) break case .restored: print("purchases restored") handlePurchase(transaction.payment.productIdentifier) Utilities.restoredPurchases = true SKPaymentQueue.default().finishTransaction(transaction) break case .deferred: break @unknown default: break } }) } private func handlePurchase(_ id: String) { UserDefaults.standard.setValue(true, forKey: id) print("id = \(id)") if id == "JokesRUs.RemoveAds" { Utilities.ShowAds = false } if id == "JokesRUs.Icons.Summer" { print("summer bought") IconChange.setIconPurchased = true IconChange.summerIconUnlocked = true IconChange.numUnlocked = IconChange.numUnlocked + 1 UserDefaults.standard.setValue(IconChange.numUnlocked + 1, forKey: "numUnlocked") UserDefaults.standard.setValue(true, forKey: "summerIconUnlocked") } if id == "JokesRUs.Icons.Taco" { print("taco bought") IconChange.setIconPurchased = true IconChange.tacoIconUnlocked = true IconChange.numUnlocked = IconChange.numUnlocked + 1 UserDefaults.standard.setValue(IconChange.numUnlocked + 1, forKey: "numUnlocked") UserDefaults.standard.setValue(true, forKey: "tacoIconUnlocked") } if id == "JokesRUs.Icons.Pizza" { print("pizza bought") IconChange.setIconPurchased = true IconChange.pizzaIconUnlocked = true IconChange.numUnlocked = IconChange.numUnlocked + 1 UserDefaults.standard.setValue(IconChange.numUnlocked + 1, forKey: "numUnlocked") UserDefaults.standard.setValue(true, forKey: "pizzaIconUnlocked") } if id == "JokesRUs.Icons.HotDog" { print("hotdog bought") IconChange.setIconPurchased = true IconChange.hotdogIconUnlocked = true IconChange.numUnlocked = IconChange.numUnlocked + 1 UserDefaults.standard.setValue(IconChange.numUnlocked + 1, forKey: "numUnlocked") UserDefaults.standard.setValue(true, forKey: "hotdogIconUnlocked") } if id == "JokesRUs.Icons.Hamburger" { print("hamburger bought") IconChange.setIconPurchased = true IconChange.hamburgerIconUnlocked = true IconChange.numUnlocked = IconChange.numUnlocked + 1 UserDefaults.standard.setValue(IconChange.numUnlocked + 1, forKey: "numUnlocked") UserDefaults.standard.setValue(true, forKey: "hamburgerIconUnlocked") } if id == "JokesRUs.Icons.Doughnut" { print("doughnut bought") IconChange.setIconPurchased = true IconChange.doughnutIconUnlocked = true IconChange.numUnlocked = IconChange.numUnlocked + 1 UserDefaults.standard.setValue(IconChange.numUnlocked + 1, forKey: "numUnlocked") UserDefaults.standard.setValue(true, forKey: "doughnutIconUnlocked") } }
Topic: Programming Languages SubTopic: Swift Tags:
May ’21
Reply to MKMapView: Why are my MKPolyline(s) invisible?
Just repeat the answer from the other thread, to keep a reference here, before you close the thread: Did you set color and line width for the poly line ? You should do this in func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) - MKOverlayRenderer { if let routePolyline = overlay as? MKPolyline { let renderer = MKPolylineRenderer(polyline: routePolyline) renderer.strokeColor = UIColor.blue.cgColor renderer.lineWidth = 2 return renderer } return MKOverlayRenderer() } Get more details here: https://stackoverflow.com/questions/58013956/mapkit-draw-poly-line-from-coordinates-swift-5
Topic: Programming Languages SubTopic: Swift Tags:
May ’21
Reply to MKPolyline 'inside' an MKOverlay: How do I access the points that construct the line?
Did you set color and line width for the poly line ? You should do this in func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) - MKOverlayRenderer { if let routePolyline = overlay as? MKPolyline { let renderer = MKPolylineRenderer(polyline: routePolyline) renderer.strokeColor = UIColor.blue.cgColor renderer.lineWidth = 2 return renderer } return MKOverlayRenderer() } Get more details here: https://stackoverflow.com/questions/58013956/mapkit-draw-poly-line-from-coordinates-swift-5
Topic: Programming Languages SubTopic: Swift Tags:
May ’21
Reply to How to declare a scope in code ?
Which version of Xcode ? Which version of MacOS ? AdvancedSettingsView is only available for MacOS 11.0 + It seems you copied this code: https://developer.apple.com/documentation/swiftui/settings?changes=l_3_7 But it is different: var body: some View { TabView { GeneralSettingsView() .tabItem { Label("General", systemImage: "gear") } .tag(Tabs.general) AdvancedSettingsView() .tabItem { Label("Advanced", systemImage: "star") } .tag(Tabs.advanced) } They do not show it, but they have to define struct AdvancedSettingsView: View { } as they defined struct GeneralSettingsView: View { }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
May ’21
Reply to EXC_BAD_ACCESS crash
At first glance, you have a thread issue. Where are you calling crystalAPIObjecta ? Maybe some handler should be declared @escaping, otherwise you call objects which have already disappeared. More code would be necessary to confirm.
Topic: Programming Languages SubTopic: Swift Tags:
May ’21
Reply to Swift - AVPlayer - Stop player in another cell when a new player starts
OK, I missed it, you have effectively some cell with active player. It is surprising in the first run that you have 2 found, as none has yet been created What are exactly the cells you hit ? Could you add yet another print: @IBAction func playPodcast(_ sender: Any) { print("Title", self.title) if let collectionView = self.superview as? UICollectionView { let visibleCells = collectionView.visibleCells There is also a case cell is NOT PodcastViewCell What cell is this ?
Topic: Programming Languages SubTopic: Swift Tags:
May ’21
Reply to UICollectionView Layout Error: nil layout parameter
In the crash report, can you follow the track to see where exactly ? Is it inside setUpContactsCollectionView ? You can also track step by step in debugger to see where it crashes. Or add several prints in setUpContactsCollectionView, to see which is the last to print. Could you also show the full class, to understand better the context.
Topic: UI Frameworks SubTopic: UIKit Tags:
May ’21
Reply to Picker View Data used elsewhere
With the present code:   let data = ["Aluminum 100", "Aluminum 80", "Aluminum 63", "Aluminum 50", "Steel 120", "Steel 100", "Steel 72"] when you test:     if data == ["Aluminum 100"]{ you test in fact:     if ["Aluminum 100", "Aluminum 80", "Aluminum 63", "Aluminum 50", "Steel 120", "Steel 100", "Steel 72"] == ["Aluminum 100"]{ So that is false. OOPer explained how to solve. Note that you can streamline your formulas: consumptionAir = (Double(plannedDepth.text!) + 33) / 33 * 1.4 But you need to make it more robust: if text is empty or nil, you'll crash let depthText = plannedDepth.text ?? "0" // Handle nil textField let value = depthText == "" ? 0.0 : (Double(depthText) ?? 0.0) // Handle empty textField: value is zero ; and if text is not a num (eg: "abcd", also zero consumptionAir = (value + 33) / 33 * 1.4 // No more risk of crash For timeOutput.text, you should at least show the unit and better convert to hours and minutes.
Topic: Programming Languages SubTopic: Swift Tags:
May ’21