Swift: Int and UInt types encode to long rather than int on 32 bit
| Originator: | wetzeal | ||
| Number: | rdar://17506068 | Date Originated: | 30-Jun-2014 |
| Status: | Closed | Resolved: | 14-Jun-2016 |
| Product: | Developer Tools | Product Version: | Xcode 6.0/6A216f |
| Classification: | Reproducible: | Always |
Summary:
On 32 bit architectures, NSInteger and NSUInteger are typedef'd to c int types. Swift Int and UInt use long instead, which while still 32 bit integers, cause type errors when examining method signatures at runtime.
Steps to Reproduce:
1. Fetch an NSMethodSignature for a method on a class implemented in Swift that takes an Int or UInt while running in a 32 bit runtime
2. Examine the result of getArgumentTypeAtIndex() for the integer argument
3. Compare to a method implemented in Objective-C
Expected Results:
The Swift type should be 'i' for Int and 'I' for UInt
Actual Results:
The Swift type is 'l' for Int and 'L' for UInt
Version:
Xcode 6.0/6A216f OS X 10.9.3/13D65
Sample Code:
class SwiftClass : NSObject {
func objectAtIndex(index: UInt) -> AnyObject! {
return ""
}
}
let objCUIntArgType = NSArray.instanceMethodSignatureForSelector("objectAtIndex:").getArgumentTypeAtIndex(2)
let swiftUIntArgType = SwiftClass.instanceMethodSignatureForSelector("objectAtIndex:").getArgumentTypeAtIndex(2)
println(objCUIntArgType)
println(swiftUIntArgType)
assert(objCUIntArgType == swiftUIntArgType)
This code will work correctly on a 64 bit runtime, but the assertion will fail on 32 bit.
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!