kpgalligan
08/19/2019, 3:38 PMType mismatch: inferred type is Long but NSInteger /* = Int */ was expected
louiscad
08/19/2019, 3:41 PMNSUserDefaults
wrapper, I wrote iosArm32
specific code, and apple64
specific code to use NSNumber
for Long
on 32 bits iOS, and use toInt()
for Int
on 64 bits apple devices.
In some cases, using toInt()
or toLong()
and suppressing the warning for the case it's redundant when compiled for one or another architecture may be enough if you can't have unwanted overflows because of conversion.Arkadii Ivanov
08/19/2019, 3:43 PMDominaezzz
08/19/2019, 3:43 PMconvert()
louiscad
08/19/2019, 3:44 PMNSInteger
if you want the number encoding to be dependent on the architecture and still can't have unwanted overflows by doing so.
That approach only works when compiled for iOS or macOS though. If you need it for other native targets, you might want to define your own typealias, using NSInteger
on Apple platforms.kpgalligan
08/19/2019, 3:46 PMlouiscad
08/19/2019, 3:47 PMtoInt()
with warning suppress is okay and allow users to always use Int
without dealing themselves with conversion.kpgalligan
08/19/2019, 3:53 PMSam
08/19/2019, 4:54 PMkpgalligan
08/19/2019, 4:56 PMtylerwilson
08/19/2019, 5:03 PMtylerwilson
08/19/2019, 5:06 PM.toLong() as NSInteger
so perhaps it was the casting that was the issue. But in any case the .convert() is much cleaner.louiscad
08/19/2019, 5:37 PMNSInteger
, which is different from transforming NSInteger
to stable width Int
or Long
.
And since Kotlin allows me, I'd make libraries compatible with iOS 2+ unless there's an API or a bug that prevents me from doing so. That way, developers wanting to use your library to make an app for an old iPad (i.e. mostly nerdy children with no means to buy the latest), iPod touch, iPhone 5 or earlier, it's possible. My cousin uses an iPhone 4S on iOS 9.3.5, and his family still own a working iPhone 3GS on iOS 6.
No need to accelerate planned obsolescence through software if it only saves you one or two integer conversions.Kris Wong
08/20/2019, 8:46 PMKris Wong
08/20/2019, 8:46 PMtylerwilson
08/20/2019, 8:48 PMKris Wong
08/20/2019, 8:49 PMtylerwilson
08/20/2019, 8:49 PMKris Wong
08/20/2019, 8:50 PMtylerwilson
08/20/2019, 8:50 PMactual constructor(year: Int, month: Int, day: Int) {
val components = NSDateComponents()
components.year = year.convert()
components.month = month.convert()
components.day = day.convert()
this.date = NSCalendar.currentCalendar.dateFromComponents(components) ?: NSDate()
}
tylerwilson
08/20/2019, 8:51 PMimport kotlinx.cinterop.convert
tylerwilson
08/20/2019, 8:51 PMKris Wong
08/20/2019, 8:51 PMtylerwilson
08/20/2019, 8:53 PMKris Wong
08/20/2019, 8:53 PMtylerwilson
08/20/2019, 8:54 PMKris Wong
08/20/2019, 8:55 PMtylerwilson
08/20/2019, 8:56 PMlouiscad
08/20/2019, 8:57 PMKris Wong
08/20/2019, 8:59 PMlouiscad
08/20/2019, 9:06 PMbuildSrc
is part of the setup: https://github.com/LouisCAD/Splitties/blob/14ef6cf169354a5abf6c2929f2b02e6dcffdd510/buildSrc/src/main/kotlin/config/KotlinSourceSetsConfig.kt#L37
There's also two Kotlin scripts to help creating new modules and adding targets with the needed symlink setup.