Looking for some advice. Developing a gym app where the user will enter reps and lbs lifted per set per exercise. The collection of SET (per exercise) is a collection view which scrolls left to right. Here is my problem – after 4 sets are added and you scroll left and right the indexPath seems to get corrupted such that set 4 might have the values from set 1. I think it has to do with reloading the visible values and reusable cells. After the 5th cell I get a crash because of a nil value in the indexPath. The data is dynamically entered by the user and can be accessed in the Constants.Other.setsFromCollectionView variable (until thst also get corrupted with te scrolling).
Really stumped on this one. Any help would be very much appreciated.
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CollectionViewCell", for: indexPath) as! CollectionViewCell
self.collectionView.isPrefetchingEnabled = false
print("Cell tag: ", cell.tag)
let i = indexPath.item / numberOfSets
let j = indexPath.item % numberOfSets
let item = j * 5+i
if Constants.view_specific_workout_from_homeScrren.posted_bool == true {
cell.repsText.text = "0"
cell.weightText.text = "0"
Constants.view_specific_workout_from_homeScrren.posted_bool = false
}
cell.initialize(withDelegate: self)
cell.layer.cornerRadius = 15.0
cell.layer.borderWidth = 0.0
cell.layer.shadowColor = UIColor.black.cgColor
cell.layer.shadowOffset = CGSize(width: 0, height: 0)
cell.layer.shadowRadius = 3.0
cell.layer.shadowOpacity = 0.8
cell.layer.masksToBounds = false //<-
cell.layer.borderColor = UIColor.systemBlue.cgColor
cell.setnumber.text = ("Set " + String(indexPath.row + 1))
return cell
}
Post not yet marked as solved
Evening,We had a previous app version developed in SWIFT and XCODE which utilizes the Apple Watch and healthkit. It was build last December and was working great. We dusted it off to do some updates and now we get a few errors. The one I think is causing it not to work is:App Store Connect Operation ErrorUnsupported Key. The Info.plist of bundle Awake.app/Watch/Heart Control WatchKit App.app/PlugIns/Heart Control WatchKit Extension.appex may not contain the UIRequiredDeviceCapabilities key.If we delete this ket in the Watchkit extensions the app fails to work on the watch. ANY help would be AWESOME! What has changed - google is being ineffective in solving this one.
Post not yet marked as solved
Looking for a few newbie Core Data examples. I am trying to develop my own golf scorecard and want to use Core Data. Is this the best approach?
Post not yet marked as solved
Evening Developers,I am developing an app that has a facial tracking element that detects eye movement. Everything seems to work well when we use a iPhone 11 but when we install it on a iPhone X the facial features appear to be offset almost like the constraints are not being recognized. The tracking and indications seem to work ok but the visual of the facial features are just off. Can help or direction to what might be causing this would be outstanding! -Bruce
Post not yet marked as solved
Looking for a little design advise. I am developing a gym app where my main screen is a list of major muscle groups (e.g., shoulders, back, biceps,...). After selecting one of these, the user will be presented with a listing of several workouts.I am trying to figure out the best decision to make in terms of that last screen example. The top box with History, Instrut - I want that to be a view container (I think) and make it common and just read the specific data into that container. I guess the Alternate workouts can be a table view. My question is how best to make this scale across say 50 different workouts to minimize the storyboard and code that I have to manage.Thanks,tekgeek1
Post not yet marked as solved
Here is my situation. I have some common processing code (function) in VC1 - this is common code that other view controllers will call. Basically, a user enters a value into say VC3 - VC1 will process the value. Since I have multiple VC's who do the same actions for a different activity (e.g, enter weight lifted for legs vs fly) I want to minimize th common code. It all works great as long as the VC2 and VC3 are directly wired to the VC1.I currently use the suegue approach but am stuck on this one.I suspect it is how I have the VC's wired and is simple to correct 🙂Help please! Can post eisting code if that would assist.
Post not yet marked as solved
So here is my issue.I have VC1....VC4 in which the user enters a value into a field on each VC (1 thru 4) so I wanted to have a common piece of code that would take those values from each VC and process them to either save in core or to retrieve them for display.VC1: A listing of weight lifting exercises (e.g., Chest, Legs, Back, etc) - this is where I want the common processing code to store and retrieveVC2: Chest VC where the user will enter a weight lifted -> call VC (via segue and delegate)So I can get the store and retrieve working but can not find a way to get the retrieved value back to VC2 to display. In VC1 the core memory is read fine ...just need to get that value BACK to VC2 and I AM STUCK.Help?-BruceVIEWCONTROLLER - has common functions called by other ViewControllers
import UIKit
import CoreData
class TimeSensitiveChestWorkout1: UIViewController, WeightProtocol {
var Pressed: String!
@IBOutlet weak var logo: UIImageView!
@IBOutlet weak var Workout1: UIButton!
@IBOutlet weak var Workout2: UIButton!
@IBOutlet weak var Workout3: UIButton!
@IBAction func didPressButton(sender: AnyObject) {
Pressed = "DumbbellPress"
}
@IBAction func inclineDumbbellPress(_ sender: Any) {
Pressed = "inclineViewController"
}
override func viewDidLoad() {
super.viewDidLoad()
logo.layer.cornerRadius = 25
logo.layer.masksToBounds = true
logo.layer.borderColor = UIColor.white.cgColor
logo.layer.borderWidth = 3
Workout1.layer.cornerRadius = 20
Workout1.layer.masksToBounds = true
Workout1.layer.borderColor = UIColor.white.cgColor
Workout1.layer.borderWidth = 2
Workout2.layer.cornerRadius = 20
Workout2.layer.masksToBounds = true
Workout2.layer.borderColor = UIColor.white.cgColor
Workout2.layer.borderWidth = 2
Workout3.layer.cornerRadius = 20
Workout3.layer.masksToBounds = true
Workout3.layer.borderColor = UIColor.white.cgColor
Workout3.layer.borderWidth = 2
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if (Pressed == "DumbbellPress") {
let destination = segue.destination as! DumbbellChestPress
destination.delegate = self
}
else if (Pressed == "inclineViewController") {
let destination = segue.destination as! inclineViewController
destination.delegate = self
}
else {
print ("******** No button press")
}
}
func updateDataGlobal(EntityVar: String, ExeriseNameVar: String, value:String){
guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else { return }
let managedContext = appDelegate.persistentContainer.viewContext
let fetchRequest:NSFetchRequest = NSFetchRequest.init(entityName: EntityVar)
fetchRequest.predicate = NSPredicate(format: "name = %@", ExeriseNameVar)
do
{
let test = try managedContext.fetch(fetchRequest)
let objectUpdate = test[0] as! NSManagedObject
objectUpdate.setValue(value, forKey: "weight")
do{
try managedContext.save()
}
catch
{
print("Error: ",error)
}
}
catch
{
print(error)
}
}
func retrieveDataGlobal(EntityVar: String, ExeriseNameVar: String, value:String) {
guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else { return }
let managedContext = appDelegate.persistentContainer.viewContext
let fetchRequest = NSFetchRequest(entityName: "Chest")
fetchRequest.fetchLimit = 5
fetchRequest.predicate = NSPredicate(format: "name = %@", ExeriseNameVar)
let count = try! managedContext.count(for: fetchRequest)
print (count)
do {
let result = try managedContext.fetch(fetchRequest)
for data in result as! [NSManagedObject] {
}
} catch {
print("Failed")
}
}Viewcontroller that calls common code in previous controller
import UIKit
import CoreData
protocol WeightProtocol {
func updateDataGlobal(EntityVar: String, ExeriseNameVar: String, value:String)
func retrieveDataGlobal(EntityVar: String, ExeriseNameVar: String, value:String)
}
extension UIViewController {
func HideKeyboard() {
let Tap:UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(DismissKeyboard))
view.addGestureRecognizer(Tap)
}
@objc func DismissKeyboard() {
view.endEditing(true)
}
}
class DumbbellChestPress: UIViewController {
var delegate: WeightProtocol!
@IBOutlet weak var newMaxLiftText: UITextField!
@IBOutlet weak var newMaxLiftLabel: UILabel!
@IBOutlet weak var maxWeightLiftedLabel: UILabel!
@IBAction func newWeightButon(_ sender: UIButton) {
maxWeightLiftedLabel.text = newMaxLiftText.text
delegate?.updateDataGlobal(EntityVar: "Chest", ExeriseNameVar: "Dumbell Chest Press", value: maxWeightLiftedLabel.text!)
self.dismiss(animated: true, completion: nil)
}
@IBAction func delerteDataBtton(_ sender: UIButton) {
deleteData()
}
@IBAction func loadDataButton(_ sender: UIButton) {
createData()
}
@IBOutlet weak var Workout1: UIImageView!
@IBOutlet weak var Workout2: UIImageView!
@IBOutlet weak var Workout4: UIImageView!
@IBOutlet weak var Workout3: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
self.HideKeyboard()
delegate?.retrieveDataGlobal(EntityVar: "Chest", ExeriseNameVar: "Dumbell Chest Press", value: maxWeightLiftedLabel.text!)
Workout1.layer.cornerRadius = 20
Workout1.layer.masksToBounds = true
Workout1.layer.borderColor = UIColor.white.cgColor
Workout1.layer.borderWidth = 2
Workout2.layer.cornerRadius = 20
Workout2.layer.masksToBounds = true
Workout2.layer.borderColor = UIColor.white.cgColor
Workout2.layer.borderWidth = 2
Workout3.layer.cornerRadius = 20
Workout3.layer.masksToBounds = true
Workout3.layer.borderColor = UIColor.white.cgColor
Workout3.layer.borderWidth = 2
Workout4.layer.cornerRadius = 20
Workout4.layer.masksToBounds = true
Workout4.layer.borderColor = UIColor.white.cgColor
Workout4.layer.borderWidth = 2
}import UIKit
import CoreData
class TimeSensitiveChestWorkout1: UIViewController, WeightProtocol {
var Pressed: String!
@IBOutlet weak var logo: UIImageView!
@IBOutlet weak var Workout1: UIButton!
@IBOutlet weak var Workout2: UIButton!
@IBOutlet weak var Workout3: UIButton!
@IBAction func didPressButton(sender: AnyObject) {
Pressed = "DumbbellPress"
}
@IBAction func inclineDumbbellPress(_ sender: Any) {
Pressed = "inclineViewController"
}
override func viewDidLoad() {
super.viewDidLoad()
logo.layer.cornerRadius = 25
logo.layer.masksToBounds = true
logo.layer.borderColor = UIColor.white.cgColor
logo.layer.borderWidth = 3
Workout1.layer.cornerRadius = 20
Workout1.layer.masksToBounds = true
Workout1.layer.borderColor = UIColor.white.cgColor
Workout1.layer.borderWidth = 2
Workout2.layer.cornerRadius = 20
Workout2.layer.masksToBounds = true
Workout2.layer.borderColor = UIColor.white.cgColor
Workout2.layer.borderWidth = 2
Workout3.layer.cornerRadius = 20
Workout3.layer.masksToBounds = true
Workout3.layer.borderColor = UIColor.white.cgColor
Workout3.layer.borderWidth = 2
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if (Pressed == "DumbbellPress") {
let destination = segue.destination as! DumbbellChestPress
destination.delegate = self
}
else if (Pressed == "inclineViewController") {
let destination = segue.destination as! inclineViewController
destination.delegate = self
}
else {
print ("******** No button press")
}
}
func updateDataGlobal(EntityVar: String, ExeriseNameVar: String, value:String){
guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else { return }
let managedContext = appDelegate.persistentContainer.viewContext
let fetchRequest:NSFetchRequest<NSFetchRequestResult> = NSFetchRequest.init(entityName: EntityVar)
fetchRequest.predicate = NSPredicate(format: "name = %@", ExeriseNameVar)
do
{
let test = try managedContext.fetch(fetchRequest)
let objectUpdate = test[0] as! NSManagedObject
objectUpdate.setValue(value, forKey: "weight")
do{
try managedContext.save()
}
catch
{
print("Error: ",error)
}
}
catch
{
print(error)
}
}
func retrieveDataGlobal(EntityVar: String, ExeriseNameVar: String, value:String) {
guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else { return }
let managedContext = appDelegate.persistentContainer.viewContext
let fetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: "Chest")
fetchRequest.fetchLimit = 5
fetchRequest.predicate = NSPredicate(format: "name = %@", ExeriseNameVar)
let count = try! managedContext.count(for: fetchRequest)
print (count)
do {
let result = try managedContext.fetch(fetchRequest)
for data in result as! [NSManagedObject] {
}
} catch {
print("Failed")
}
}
Post not yet marked as solved
Looking for some simple help as I just learning SWIFT.I have a sample app with 5 viewcontrollers (it's a gym app) will each viewcontroller focused on a different workout. In each viewcontroller, I want to capture the same data (weight lifted) but for each workout. I am using CoreData which is working great.I want to use one function (to say capture the weight) and pass in parameters. If I place this function in viewController1 - how do I call it from viewController2?Thanks (in advance)-tekgeek************* my current viewcontroller with function *****************import UIKitimport CoreDataclass Controller1: UIViewController { @IBOutlet weak var newMaxLiftText: UITextField! @IBOutlet weak var newMaxLiftLabel: UILabel! @IBOutlet weak var maxWeightLiftedLabel: UILabel! @IBAction func newWeightButon(_ sender: UIButton) { maxWeightLiftedLabel.text = newMaxLiftText.text updateData() } @IBAction func delerteDataBtton(_ sender: UIButton) { deleteData() } @IBAction func loadDataButton(_ sender: UIButton) { createData() }override func viewDidLoad() { super.viewDidLoad()}////////////// Update Function //////////////// func updateData(){ guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else { return } let managedContext = appDelegate.persistentContainer.viewContext let fetchRequest:NSFetchRequest<NSFetchRequestResult> = NSFetchRequest.init(entityName: "Chest") fetchRequest.predicate = NSPredicate(format: "name = %@", "Dumbell Chest Press") do { let test = try managedContext.fetch(fetchRequest) let objectUpdate = test[0] as! NSManagedObject objectUpdate.setValue(maxWeightLiftedLabel.text!, forKey: "weight") do{ try managedContext.save() } catch { print("Error: ",error) } } catch { print(error) } }
Post not yet marked as solved
So I am new to developing apps. I am working a workout app where I want to store data about a users workout. Searching things, there looks to be a few ways to do this: 1) local data store on the local device (no network connection required) 2) Firebase backend DB (connection required). I am not looking at storing a lot of data. Suggestions of which might be better? Any good explanation tutorials?Thanks,-Bruce