0

I am following Apple documentation https://developer.apple.com/documentation/coremotion/accessing_submersion_data

Created a new watchOS app with iOS companion app. Went into ContentView default code and added few lines as per documentation (also added authorisation for motion data and info.plist for WKBackgroundModes)

Copying whole code for context, but the one I added is the last at the end:`

import SwiftUI
import CoreMotion

//protocol SubmergeActionDelegate {
//    func didSubmerge()
//
//}

struct GoUnderView: View {
   
    
    var body: some View {
        VStack {
            Image(systemName: "globe")
                .imageScale(.large)
                .foregroundColor(.accentColor)
            Text("Hello, world!")
        }
        .padding()
    }
    
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        GoUnderView()
        
        
        
    }
}



func letsSinc () {
    guard CMWaterSubmersionManager.waterSubmersionAvailable else {
        return
    }
    
    let waterSubmersionManager = CMWaterSubmersionManager()
    
    //Assign a delegate to receive events and update
    waterSubmersionManager.delegate = self
}

Getting error: "Cannot find 'self' in scope; did you mean to use it in a type or extension context?"

justas180
  • 1
  • 1
  • You have created the function outside of any class or struct, so there is no `self`. You will need to create class to hold this code. You will also need a property in this class to hold the submersionmanager instance – Paulw11 Jul 04 '23 at 20:00
  • You’re a star my friend. I don’t yet remember exactly how to do it correctly, but I recall pieces of that and it makes total sense what you’re saying. Thanks again for taking your time to respond such a basic question / issue - will experiment tonight in this one. – justas180 Jul 05 '23 at 05:10
  • I had to go through some crash courses of iOS development to recall things. I think I passed through these initial issues. I will share sample code once it works. – justas180 Jul 05 '23 at 17:14

0 Answers0