1

I try to program an exercise App for the Apple Watch and iPhone. However, I'm not able to send my multidimensional Array to my iPhone. I tried many suggestions like the WCsession, NSUserDefaults or CoreData using a shared container.

There are some solutions already suggested here on stackoverflow but often they only send a short String or dictionary.

My App:

I have two classes with my variables:

class WorkoutClass: NSObject {
var date: String
var exercise: String
var duration: Double
var repetitions: Double?
var meanRepDuration: Double?
var idealAngle: Double?
var meanAngle: Double?
var repArray: Array<Any>?


init(date: String, exercise: String, duration: Double, repetitions: Double?, meanRepDuration: Double?, idealAngle: Double?, meanAngle: Double?, repArray: Array<Any>?) {


    self.date = date
    self.exercise = exercise
    self.duration = duration
    self.repetitions = repetitions
    self.meanRepDuration = meanRepDuration
    self.idealAngle = idealAngle
    self.meanAngle = meanAngle
    self.repArray = repArray

}
}

and

class RepetitionClass: NSObject { 
var oneRepAngle: Double?
    var oneRepStartTime: Double?
    var oneRepEndTime: Double?
    var oneRepInternalVariation: Double?

init(oneRepAngle: Double?, oneRepStartTime: Double?, oneRepEndTime: Double?, oneRepInternalVariation: Double?) {

        self.oneRepAngle = oneRepAngle
        self.oneRepStartTime = oneRepStartTime
        self.oneRepEndTime = oneRepEndTime
        self.oneRepInternalVariation = oneRepInternalVariation

    }
    }

Annotation: Because I get my data in a special way i had to do it like this. For each exercise an array is added with specific data from each repetition

This will be added together with multiple exercises into an array called "exerciseArray":

I get my acceleration data from the Watch and store it into an array. This array is declared as:

var exerciseArray = [Any]()

But putting this array into a dictionary and send it with userDefaults did not work. I was also suggested to cast my exerciseArray into Data and send it with sendMessage. Unfortunately, all tutorials found on youtube, stackoverflow or anywhere else did not work for iOS 10 and watchOS 3.

Therefore, if someone could suggest a method to share data (not only small data/dictionaries) between an iOS app and its extension that would actually help a lot of other people too (as I already saw here on stackoverflow).

I would prefer using a shared container with Core Data but since I'm totally new in programming I ask you for your help. Thanks!

Community
  • 1
  • 1
huberdo
  • 21
  • 4

1 Answers1

0

Since WatchOS2 you are no longer to share Core Data, but you can use WatchConnectivity framework to pass the information you need between the phone and the watch.

Grant Isom
  • 150
  • 11