nst / STTwitter

A stable, mature and comprehensive Objective-C library for Twitter REST API 1.1
BSD 3-Clause "New" or "Revised" License
999 stars 161 forks source link

Is `size` really kind of NSString class ? (postMediaUploadData) #234

Closed es-kumagai closed 8 years ago

es-kumagai commented 8 years ago

Hello, when I call postMediaUploadData:fileName:uploadProgressBlock:successBlock:errorBlock: method from Swift code using with STTwitterOS authentication in OS X 10.11, I encountered the following error.

-[__NSCFNumber length]: unrecognized selector sent to instance 0x2b8037

This error raise when successBlock is called, and the instance 0x2b8037 is variable named size.

https://github.com/nst/STTwitter/blob/daec90ae5788cb7e8079d82b472c989d82f5e8a3/STTwitter/STTwitterAPI.m#L4335

I think the problem might be occurred when the size is trying to bridge from NSString (In fact, NSNumber) to Swift Native String.

mkc842 commented 8 years ago

I think this issue is broader than what #235 resolves.

Using Swift, I encountered the issue in postMediaUploadFINALIZEWithMediaID, where mediaID, expiresAfterSecs, and size are each an NSNumber, but are assigned to string variables. I fixed it there by adding stringValue in the assignments:

NSString *mediaID = [[response valueForKey:@"media_id"] stringValue];
NSString *expiresAfterSecs = [[response valueForKey:@"expires_after_secs"] stringValue];
NSString *size = [[response valueForKey:@"size"] stringValue];
es-kumagai commented 8 years ago

I tried to modify source code to handle some numeric values in API Response as NSInteger type instead of NSString* type. Because I think that it is appropriate to treat each integer value as NSInteger rather than NSString.

Commit: 39add4f