K/N iOS question: is there a way I can control how...
# kotlin-native
t
K/N iOS question: is there a way I can control how a Kotlin Int gets translated to the ObjC code? Right now it is making it an int32_t which requires casting and such. I would like to make it an NSInteger, which require less of this. Thank you!
o
please provide more context, generally we provide bit of control on how translation happens, but try to make sane defaults
t
I have a Kotlin ViewModel I created like so:
Copy code
class DeclarationsViewModel(val declarations: List<Declaration>) {

    // how many declarations we have
    val count: Int = declarations.size
}
this gets translated to:
Copy code
@interface SWLDeclarationsViewModel : KotlinBase
@property (readonly) int32_t count;
@end;
then i want to use in my UITableViewController (in Swift) like so:
Copy code
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.viewModel?.count ?? 0
//        return Int(self.viewModel?.count ?? 0)
    }
but I get an error like so:
Cannot convert return expression of type ‘Int32’ to return type ‘Int’
So I then have to do that ugly Int() wrapping you see in the comment.
@olonho see above. thanks!
d
+1 on this request
@tylerwilson curious why the return type of that function an Int instead of NSInteger?
t
You mean numberOfRowsInSection? That is a Swift method.
d
ahhhh, just realized the "func"
s
Currently you can’t control that. The problem is that
<http://kotlin.Int|kotlin.Int>
!=
NSInteger
. For example, the second one is 64-bit integer on some platforms, while the first one is always 32-bit. So this feature should be designed carefully first.