I'm trying to use a Cocoapods dependency similar to the example
However, adding another dependency which has an ObjC property starting with a new prefix will fail with
> Task :cinteropRealmIOS
e: /Users/Nabil/Dev/kotlin-native/samples/cocoapods/kotlin-library/build/classes/kotlin/iOS/main/kotlin-library-cinterop-Realm.klib-build/kotlin/cocoapods/Realm/Realm.kt: (515, 45): This annotation is not applicable to target 'getter'
````
My guess is that since the attribute is prefixed with `new` (to hint to the compiler that is `NS_RETURNS_RETAINED` see https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmRules.html) the stub generator will add the Kotlin annotation `ReturnsRetained` however, this annotation is considered illegal because it applies only to [methods](https://kotlinlang.org/api/latest/jvm/stdlib/kotlinx.cinterop.internal/-c-call/-returns-retained/index.html), hence the error.
Here's how the [attribute](https://github.com/realm/realm-cocoa/blob/master/Realm/RLMMigration.h#L59) in question is defined in ObjC
@property (nonatomic, readonly) RLMSchema *newSchema;
and here's the generated stub causing the issue
val newSchema: RLMSchema
@ObjCMethod("newSchema", "@16@0:8") @CCall.ReturnsRetained external get
...
@ObjCMethod("newSchema", "@16@0:8")
@CCall.ReturnsRetained
external open fun newSchema(): RLMSchema
### Steps to reproduce
- Using the Cocoapods [example](https://github.com/JetBrains/kotlin-native/tree/master/samples/cocoapods) add the following dependency
```Diff
index 291c2faba..90956a724 100644
--- a/samples/cocoapods/kotlin-library/build.gradle.kts
+++ b/samples/cocoapods/kotlin-library/build.gradle.kts
@@ -33,5 +33,6 @@ kotlin {
// Configure a dependency on AFNetworking. It will be added in all macOS and iOS targets.
pod("AFNetworking", "~> 3.2.0")
+ pod("Realm", "~> 3.17.3")
}
}
./build.sh, it should fail with the mentioned error I believe the same issue could occur if the property begins with “alloc”, “copy”, or “mutableCopy” as these are memory management naming convention in ObjC https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmRules.html
I have the same problem with
cocoapods {
pod("AWSCore", "= 2.9.3")
}
val newLogFileName: String?
@ObjCMethod("newLogFileName", "@16@0:8") @CCall.ReturnsRetained external get
build/classes/kotlin/ios/main/storage-file-cinterop-AWSCore.klib-build/kotlin/cocoapods/AWSCore/AWSCore.kt: (1385, 50): This annotation is not applicable to target 'getter'
Hello! I'd be particularly interested in seeing this resolved. Is there anything I would be able to assist here?
Fixed in 1.4.
Most helpful comment
I have the same problem with
build/classes/kotlin/ios/main/storage-file-cinterop-AWSCore.klib-build/kotlin/cocoapods/AWSCore/AWSCore.kt: (1385, 50): This annotation is not applicable to target 'getter'