<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Sure thing. Yeah, ideally the bridging would be fixed, but at the least, correcting the documentation will be a good start. Will file, thanks.</div><div class=""><br class=""></div><div class="">Best,</div><div class="">Chris Anderson</div><div class=""><br class=""></div><div><blockquote type="cite" class=""><div class="">On Nov 11, 2016, at 5:55 PM, Tony Parker <<a href="mailto:anthony.parker@apple.com" class="">anthony.parker@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi Chris,<div class=""><br class=""></div><div class="">Can you file a radar or JIRA for us on this? It looks like something should be fixed in the documentation at least, or perhaps in the bridging.</div><div class=""><br class=""></div><div class="">- Tony</div><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Nov 11, 2016, at 1:46 PM, Chris Anderson via swift-users <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div style="font-family: helvetica; font-size: 12px;" class="">I'm having problems with the type conversion between a Swift `Decimal` and an Objective C `NSDecimalNumber`.</div><div style="font-family: helvetica; font-size: 12px;" class=""><br class=""></div><div style="font-family: helvetica; font-size: 12px;" class="">If I have the Swift class:</div><div style="font-family: helvetica; font-size: 12px;" class=""><br class=""></div><div style="font-family: helvetica; font-size: 12px;" class=""> @objc class Exam: NSObject {</div><div style="font-family: helvetica; font-size: 12px;" class=""> var grade: Decimal = 90.0</div><div style="font-family: helvetica; font-size: 12px;" class=""> }</div><div style="font-family: helvetica; font-size: 12px;" class=""><br class=""></div><div style="font-family: helvetica; font-size: 12px;" class="">And try to use that Swift class in Objective C, </div><div style="font-family: helvetica; font-size: 12px;" class=""><br class=""></div><div style="font-family: helvetica; font-size: 12px;" class=""> Exam *exam = [[Exam alloc] init];</div><div style="font-family: helvetica; font-size: 12px;" class=""> NSDecimalNumber *result = [[NSDecimalNumber zero] decimalNumberByAdding:grade.value];</div><div style="font-family: helvetica; font-size: 12px;" class=""><br class=""></div><div style="font-family: helvetica; font-size: 12px;" class="">I get the error:</div><div style="font-family: helvetica; font-size: 12px;" class=""><br class=""></div><div style="font-family: helvetica; font-size: 12px;" class="">Sending 'NSDecimal' to parameter of incompatible type 'NSDecimalNumber * _Nonnull'</div><div style="font-family: helvetica; font-size: 12px;" class=""><br class=""></div><div style="font-family: helvetica; font-size: 12px;" class="">as it seems like `grade` is being treated as an `NSDecimal` not an `NSDecimalNumber`. This seems incorrect as per <a href="https://developer.apple.com/reference/foundation/nsdecimalnumber" class="">https://developer.apple.com/reference/foundation/nsdecimalnumber</a> it says </div><div style="font-family: helvetica; font-size: 12px;" class=""><br class=""></div><div style="font-family: helvetica; font-size: 12px;" class="">"The Swift overlay to the Foundation framework provides the Decimal structure, which bridges to the NSDecimalNumber class. The Decimal value type offers the same functionality as the NSDecimalNumber reference type, and the two can be used interchangeably in Swift code that interacts with Objective-C APIs. This behavior is similar to how Swift bridges standard string, numeric, and collection types to their corresponding Foundation classes."</div><div style="font-family: helvetica; font-size: 12px;" class=""><br class=""></div><div style="font-family: helvetica; font-size: 12px;" class="">So I'm not sure if 1) I'm doing something wrong. 2) there's an error in the documentation or 3) this is a Swift bug. Number 1 on that list is definitely the most likely, but I wanted to see what I’m missing here.</div><div style="font-family: helvetica; font-size: 12px;" class=""><br class=""></div><div style="font-family: helvetica; font-size: 12px;" class="">I don't want to explicitly make the values in my Swift class `NSDecimalNumber` because then I cannot do simple arithmetic operations such as `+` without doing the whole ugly `decimalNumberByAdding` dance.</div><div style="font-family: helvetica; font-size: 12px;" class=""><br class=""></div><div style="font-family: helvetica; font-size: 12px;" class="">Thanks for the help!</div><div style="font-family: helvetica; font-size: 12px;" class=""><br class=""></div><div style="font-family: helvetica; font-size: 12px;" class="">Best,</div><div style="font-family: helvetica; font-size: 12px;" class="">Chris Anderson</div></div>
_______________________________________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-users" class="">https://lists.swift.org/mailman/listinfo/swift-users</a><br class=""></div></blockquote></div><br class=""></div></div></div></blockquote></div><br class=""></body></html>