Can anybody help me understand how I can use iOS c...
# multiplatform
a
Can anybody help me understand how I can use iOS classes in Kotlin? For example, I want to get a database path in iOS, we already have it on Android using the context, but for iOS I'm not sure how. I can't import the swift class right since its compiled before hand or something, but we can use the Objective C classes? For example, this logic here:
Copy code
//get an instance of the File Manager
NSFileManager *fileManager = [NSFileManager defaultManager];

   //we'll list file in the temporary directory

NSString * strPath = NSTemporaryDirectory();

//we'll need NSURL for the File Manager
NSURL *tempDirURL = [NSURL fileURLWithPath:strPath];


  //An array of NSURL object representing the path to the file
    //using the flag NSDirectoryEnumerationSkipsHiddenFiles to skip hidden files

NSArray *directoryList = [fileManager contentsOfDirectoryAtURL:tempDirURL 
                      includingPropertiesForKeys:nil 
              options:NSDirectoryEnumerationSkipsHiddenFiles error:nil];
How can that be written in Kotlin? I think I need to do import platform.Foundation.NSFileManager right? I'm not sure exactly how I can find a .db file though. Or use these classes / methods. Is there a way to see method names etc in the IDE? Right now it seems to import but its red and I can't see methods etc. Any tips would be great
d
try adding:
Copy code
kotlin.mpp.enableGranularSourceSetsMetadata=true
to your gradle.properties that will resolve the red imports
a
Hey, we already have that there it seems, still seeing red imports however
a
Ah those extra bits seemed to fix it. I still see issues with this though:
Copy code
co.touchlab.sqliter.DatabaseConfiguration
and
Copy code
import com.squareup.sqldelight.drivers.native.NativeSqliteDriver
Is this something to do with libraries?
d
I believe it does
Copy code
kotlin {
  // The drivers needed will change depending on what platforms you target:

  sourceSets.androidMain.dependencies {
    implementation "com.squareup.sqldelight:android-driver:1.5.2"
  }

  sourceSets.iosMain.dependencies {
    implementation "com.squareup.sqldelight:native-driver:1.5.2"
  }
}
the native driver has to be added to work with iOS
a
Thats interesting I will try do that in a while, this has helped a lot with writing ios code in Kotlin, seeing the syntax and prepopulation is great!
Do you know if there is an easy way to debug ios? Right now we build the XCFramework, drag into xcode, sign and embed, then we need to drag our commonMain and iosMain code into xcode and set the source as java which seems to work . Was wondering if therres a better way
d
that’s exactly what we do lol
a
Ah I see haha, thought there might be a better way!
Thanks for the help!
✌️ 1