I am developing an extra GPS module for an app in WinDev. WinDev supports Swift code but only method which excluding class and global variable use. Here what I've done (basically based on Apple doc) :
import Foundation
import CoreLocation
import UIKit
class mod_GPS : NSObject, CLLocationManagerDelegate {
var distance = Double()
var location_last : [CLLocation] = []
let locationManager = CLLocationManager()
func startReceivingLocationChanges() {
// Do some stuff (basically what is write on doc)
}
internal func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let lastLocation = locations.last!
if (location_last.count != 0){
distance = distance + lastLocation.distance(from: location_last[0])
location_last[0] = lastLocation
}else{
distance = 0
location_last.append(lastLocation)
}
}
func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
//Same
}
}
So here we have some code to create an object and count the distance when the user move. But this can't deal with WinDev. The issue is about : "let locationManager = CLLocationManager()" which have to be global. So I was wondering if there is a way to avoid global variable.
First I try something like that : the part in swift write on disk at every call of LocationManage(didUpdateLocation) and the part in WinDev read the value when he wanted. But this don't solve the problem because I still have to initiate the variable locationManager in WinDev part. Then I think about anonymous class which exist in Java but it seems to be missing in swift and objective C.
Moreover the community of WinDev developer and the documentation is totally AFK so I didn't expected help this way. I clearly don't know how to do this part. If someone have and idea or a tips... I'll be glad to hear them.