Revise whether we should convert NSNumber to Int

Description

1. Xcode imports the `NSNumber` type "as is":
http://take.ms/StiLR

2. Method and function signatures should rather keep `NSNumber` rather than `Int` for compatibility with callees and external usages. Thus, we would like to make the behavior consistent, avoiding casual conversions between NSNumber and numeric types in the code.

Useful article:
https://clang.llvm.org/docs/ObjectiveCLiterals.html

Environment

None

Activity

Show:
Alex Petuschak
July 9, 2018, 1:58 PM
Edited

+Related feedback:

I expected that boolValue method is converted to 'boolValue'. not '!= 0'

  • Source

  • Expected

  • Actual

My note (Alex): `n != 0` seems still perfectly valid in the above case.
But the behavior of mapping NSNumber to Int should be revised.

Alex Petuschak
November 28, 2018, 9:46 AM
Edited

+Another report (Purchase App <purchase.app@kiwiup.com>)

Another report I'd want to make is that in ObjC, we convert literals to NSNumber by wrapping them inside '@()' for e.g @(2) or @(3.4) but Swiftify isn't able to convert them - I think it directly assigns the literal to a var of type NSNumber which is resulting in a compilation error. May be you can look into this as well (for future users I mean).

My comment:
http://take.ms/XgS11

<....>

and the conversion was:

so in the above converted code, ideally I would expect something like NSNumber(value: 2) instead of the literal 2 being passed as swift doesn't accept it for the argument of type NSNumber. I guess you could consider this more like a feature request than a bug-report

My reply:

I do realize that there are cases when you'll want to convert Swift to NSNumber (and we'll be looking further into that),
but your particular sample seems to compile and run perfectly (since `2` is implicitly convertible to `NSNumber`):
http://swrun.com/4w2dqm

Alex Petuschak
December 20, 2018, 9:28 AM
Edited

+Another report (ZendDesk ticket #590):

For the swift conversion for predicates
The bool value is directly converted as false
it is like

not

Assignee

Alex Petuschak

Reporter

Alex Petuschak

Labels

Git Branch Name

None

GitHub Issue

None

Components

Fix versions

Priority

High
Configure