Check type of class an NSData store?

五迷三道 提交于 2019-12-20 07:44:24

问题


I have a library that process a string and converts it to an unknown format and insert it into a NSData. In a part of the code that library check if the NSData is empty, if not it sends to the server:

if (!dataToSend) {
return;
}

I thought the stored value would be a string or base64, for that tested the following codes:

NSLog(@"To string -> %@",[NSString stringWithUTF8String:[dataToSend bytes]]);

NSString *decodedString = [[NSString alloc] initWithData:dataToSend encoding:NSUTF8StringEncoding];
    NSLog(@"Decode String Value: %@", decodedString);

In console I continue receiving (null), but the data is not null once I insert that code below from return;. How I can check the type of that NSData stores?


回答1:


  • Check the type of NSData
  • if([yourData isKindOfClass: [NSData class]])


来源:https://stackoverflow.com/questions/37091517/check-type-of-class-an-nsdata-store

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!