Posts

Post not yet marked as solved
1 Replies
2.3k Views
I have a view controller, embeded in a navigation controller which has large title navigation bar enabled with this code :self.navigationController?.navigationBar.prefersLargeTitles = trueself.navigationItem.largeTitleDisplayMode = .alwaysThe view controller has a scroll view and when I scroll down the bar gets small as expected , but when I scroll back up it doesn't get big again . What should I do ?
Posted
by Dave19.
Last updated
.
Post not yet marked as solved
4 Replies
3.8k Views
I've created a new xcode project in Xcode 11, I've removed the scene delegate from the info plist and replaced the app delegate methods with some from Xcode 10 .When I run the project in the iOS 13 simulator the app work completly fine, but when I run it on an older iPhone on iOS 12.4 the app crashes and I get this in the logTerminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UINavigationBar 0x143d13aa0> valueForUndefinedKey:]: this class is not key value coding-compliant for the key ibShadowedLargeTitleTextAttributes.'*** First throw call stack:(0x238e8a98c 0x2380639f8 0x238da7e10 0x2398738fc 0x2397e7e1c 0x2398051a4 0x265454384 0x265454a3c 0x265455970 0x265454b74 0x2651ea590 0x2651ea6e0 0x265c2cfc4 0x23d3c7c60 0x23d3ccc08 0x23d32f3e4 0x23d35d620 0x2657ae85c 0x238e1c578 0x238e1be7c 0x238e16ee0 0x238e167c0 0x23b01779c 0x265795c38 0x100181b4c 0x2388da8e0)libc++abi.dylib: terminating with uncaught exception of type NSExceptionHow should I solve this ?
Posted
by Dave19.
Last updated
.
Post not yet marked as solved
0 Replies
495 Views
As I said in the title I have a core data container created in a custom class static var context: NSManagedObjectContext { let context = persistentContainer.viewContext context.automaticallyMergesChangesFromParent = true return context } // MARK: - Core Data stack static var persistentContainer: NSPersistentCloudKitContainer = { /* The persistent container for the application. This implementation creates and returns a container, having loaded the store for the application to it. This property is optional since there are legitimate error conditions that could cause the creation of the store to fail. */ let container = PersistentContainer(name: "App") container.loadPersistentStores(completionHandler: { (storeDescription, error) in if let error = error as NSError? { print("Unresolved error \(error), \(error.userInfo)") } }) let description = container.persistentStoreDescriptions.first description?.setOption(true as NSNumber, forKey: NSPersistentHistoryTrackingKey) container.persistentStoreDescriptions = [description!] return container }() // MARK: - Core Data Saving support static func saveContext () { let context = PersistanceService.persistentContainer.viewContext if context.hasChanges { do { try context.save() } catch { // Replace this implementation with code to handle the error appropriately. let nserror = error as NSError print("Unresolved error \(nserror), \(nserror.userInfo)") } } } And I’ve included the NSPersistentHistoryTrackingKey but the debug prints this error when saving : File is in Read Only mode due to Persistent History being detected but NSPersistentHistoryTrackingKey was not included.
Posted
by Dave19.
Last updated
.
Post not yet marked as solved
1 Replies
596 Views
I'm trying to use search for nearby points (https://developer.apple.com/documentation/mapkit/searching_for_nearby_points_of_interest) to display hotels nearby the user in a table view, but I didn't get how to do that from the documentation, I already managed permission for the user's location, how should I do it ?
Posted
by Dave19.
Last updated
.
Post not yet marked as solved
0 Replies
541 Views
I'm trying to get the sleep duration from the health app, I've authorised it, I've checked the code ,but whatever I do I always get "Not Found"Here is what I wrote : func getSleep() { // first, we define the object type we want if let sleepType = HKObjectType.categoryType(forIdentifier: .sleepAnalysis) { // Use a sortDescriptor to get the recent data first let sortDescriptor = NSSortDescriptor(key: HKSampleSortIdentifierEndDate, ascending: false) // we create our query with a block completion to execute let query = HKSampleQuery(sampleType: sleepType, predicate: nil, limit: 30, sortDescriptors: [sortDescriptor]) { (query, tmpResult, error) -> Void in if error != nil { // something happened return } if let result = tmpResult { // do something with my data for item in result { if let sample = item as? HKCategorySample { let value = (sample.value == HKCategoryValueSleepAnalysis.inBed.rawValue) ? "Not Found" : "Asleep" print("Duration : \(value)") DispatchQueue.main.async { self.stepsLbl.text = "Sleep : \(value)" } print("Healthkit sleep: \(sample.startDate) \(sample.endDate) - value: \(value)") } } } } // finally, we execute our query healthStore.execute(query) } }What should I do ?
Posted
by Dave19.
Last updated
.
Post not yet marked as solved
1 Replies
708 Views
I'm trying to add a Siri Shortcut to my app which would essentially update the UI in a view controller , but I've got two problems : 1. My app has a tab bar view controller and the activityVC is the third one in the tab bar, but when I run the Siri Shortcut , I get sent to the activityVC ,but without a tab bar 2. When I run the shortcut ,I get transitioned to the activityVC, but updateUI() doesn't runHere's what I wrote in my app delegate :func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool { switch userActivity.activityType { case "start": let sb = UIStoryboard(name: "Main", bundle: nil) let activityVC = sb.instantiateViewController(withIdentifier: Constants.Storyboard.activityVC) as! ActivityViewController let root = UIApplication.shared.keyWindow?.rootViewController root?.present(activityVC, animated: true, completion: nil) activityVC.updateUI() default: print("no shortcut") } return false }
Posted
by Dave19.
Last updated
.
Post not yet marked as solved
1 Replies
453 Views
Hi ,I'm trying to use encoding and decoding to save some UISwitch states .I've written this :override func encodeRestorableState(with coder: NSCoder) { super.encodeRestorableState(with: coder) coder.encode(self.runSwitch2.isOn, forKey: "runSwitchState2") coder.encode(self.runSwitch1.isOn, forKey: "runSwitchState1") } override func decodeRestorableState(with coder: NSCoder) { super.decodeRestorableState(with: coder) let runRestoredState2 = coder.decodeBool(forKey: "runSwitchState2") self.runSwitch2.setOn(runRestoredState2, animated: false) let runRestoredState1 = coder.decodeBool(forKey: "runSwitchState1") self.runSwitch1.setOn(runRestoredState1, animated: false) }and got the error Thread 1 : Signal SIGABRTWhat did I do wrong ?
Posted
by Dave19.
Last updated
.
Post not yet marked as solved
3 Replies
363 Views
Hi, I'm trying to save the state of some switches and restore it when the app launches again but when I wrote this :override func encodeRestorableState(with coder: NSCoder) { super.encodeRestorableState(with: coder) coder.encode(Int32(self.runSwitch1.state.rawValue), forKey: CodingKey.Protocol) }I got this error : Cannot convert value of type 'CodingKey.Protocol.Type' to expected argument type 'String'What should I do ?
Posted
by Dave19.
Last updated
.
Post not yet marked as solved
0 Replies
310 Views
Hi , I'm trying to make a function triggered by a button click to transition to a different view controller which has a scroll view (written programatically) with some elements ,when I run the project everything works ,but when I transition to that screen ,the scroll view doesn't show up ,neither does anything on it .The function with the button :@objc func buttonCliked(_ : UIButton) { let moreViewController = storyboard?.instantiateViewController(withIdentifier: "MoreVC") as! MoreViewController self.show(moreViewController, sender: UIButton.self) }The scroll view implementation : lazy var scrollView: UIScrollView = { let view = UIScrollView() view.translatesAutoresizingMaskIntoConstraints = false view.contentSize.height = 4560 view.backgroundColor?.withAlphaComponent(0) return view }() override func viewDidLoad() { super.viewDidLoad() view.addSubview(scrollView) setUpCards() }
Posted
by Dave19.
Last updated
.
Post not yet marked as solved
1 Replies
393 Views
Hi, I'm trying to make a constant containing the current users's uid using firestoreHere's the code : let uid = Auth.auth().currentUser!.uidBut it accesses the red uid not the blue one as it should (see picture),how should I fix this ?Picture : https://ibb.co/pRNz73F
Posted
by Dave19.
Last updated
.
Post not yet marked as solved
1 Replies
477 Views
I am trying to add an animated card to my app and I wrote the code below in the view controller , but when I run the project I can not interract with the card CODE :import UIKitclass HomeViewController: UIViewController { enum cardState { case expanded case collapsed } var goalCard:GoalCardViewController! var visualBlur:UIVisualEffectView! let cardHeight:CGFloat = 800 let cardHandleHeight:CGFloat = 110 var cardVisible = false var nextState:cardState { return cardVisible ? .collapsed : .expanded } var runningAnimations = [UIViewPropertyAnimator]() var animationInProgressWhenInterrupted:CGFloat = 0 override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. setUpCard() } func setUpCard() { visualBlur = UIVisualEffectView() visualBlur.frame = self.view.frame self.view.addSubview(visualBlur) goalCard = GoalCardViewController(nibName:"GoalCardViewController", bundle:nil) self.addChild(goalCard) self.view.addSubview(goalCard.view) goalCard.view.frame = CGRect(x: 0, y: self.view.frame.height - cardHandleHeight, width: self.view.bounds.width, height: cardHeight) goalCard.view.clipsToBounds = true let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(HomeViewController.handleCardTap(recognizer:))) let panGestureRecognizer = UIPanGestureRecognizer(target: self, action: #selector(HomeViewController.handleCardPan(recognizer:))) goalCard.handleArea.addGestureRecognizer(panGestureRecognizer) goalCard.handleArea.addGestureRecognizer(tapGestureRecognizer) } @objc func handleCardTap (recognizer: UITapGestureRecognizer) { } @objc func handleCardPan (recognizer: UIPanGestureRecognizer) { switch recognizer.state { case .began: // Start Transition startInteractiveTransition(state: nextState, duration: 0.9) case .changed: // Update Transition let translation = recognizer.translation(in: self.goalCard.view) var fractionComplete = translation.y / cardHeight fractionComplete = cardVisible ? fractionComplete : -fractionComplete updateInteractiveTransition(fractionCompleted: 0) case .ended: // Continue Transition func finishInteractiveTransition() { for animator in runningAnimations { animator.continueAnimation(withTimingParameters: nil, durationFactor: 0) } } default: break } } func animateTransitionIfNeeded (state:cardState, duration:TimeInterval) { if runningAnimations.isEmpty { let frameAnimator = UIViewPropertyAnimator(duration: duration, dampingRatio: 1) { switch state { case .expanded: self.goalCard.view.frame.origin.y = self.view.frame.height - self.cardHeight case .collapsed: self.goalCard.view.frame.origin.y = self.view.frame.height - self.cardHandleHeight } } frameAnimator.addCompletion { _ in self.cardVisible = !self.cardVisible self.runningAnimations.removeAll() } frameAnimator.startAnimation() runningAnimations.append(frameAnimator) let cornerRadiusAnimator = UIViewPropertyAnimator(duration: duration, curve: .linear) { switch state { case .expanded: self.goalCard.view.layer.cornerRadius = 12.0 case .collapsed: self.goalCard.view.layer.cornerRadius = 12.0 } } cornerRadiusAnimator.startAnimation() runningAnimations.append(cornerRadiusAnimator) } } func startInteractiveTransition (state:cardState, duration:TimeInterval) { if runningAnimations.isEmpty { //run animations animateTransitionIfNeeded(state: state, duration: duration) } for animator in runningAnimations { animator.pauseAnimation() animationInProgressWhenInterrupted = animator.fractionComplete } } func updateInteractiveTransition (fractionCompleted:CGFloat) { for animator in runningAnimations { animator.fractionComplete = fractionCompleted + animationInProgressWhenInterrupted } func finishTransition() { for animator in runningAnimations { animator.continueAnimation(withTimingParameters: nil, durationFactor: 0) } } }}
Posted
by Dave19.
Last updated
.