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