iphone - -[NSCF字典长度] : unrecognized selector

标签 iphone objective-c nsdictionary unrecognized-selector

我遇到此代码的下一个问题:

NSDictionary * imagen = [[NSDictionary alloc] initWithDictionary:[envio resultValue]];
NSString *imagenS = [imagen valueForKey:@"/Result"];

[Base64 initialize];
NSData * imagenDecode = [Base64 decode:imagenS];

NSLog(@"%@", [imagenS length]);

//SAVE IMAGE

NSArray *sysPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);  

NSString *docDirectory = [sysPaths objectAtIndex:0]; 

NSString *filePath = [NSString stringWithFormat:@"%@david.png",docDirectory]; 

[imagenDecode writeToFile:filePath atomically:YES]; 

[envio resultValue] --> 以 Base 64 编码返回带有一张图像的 NSDictionary。

我想要解码器并保存此图像,但在我的控制台中我显示了此消息:

2011-08-23 20:15:36.539 WSStub[39226:a0f] -[NSCFDictionary length]: unrecognized selector sent to instance 0xd00ee0

Base 64 编码是:

//
//  Base64.m
//  CryptTest
//
//  Created by Kiichi Takeuchi on 4/20/10.
//  Copyright 2010 ObjectGraph LLC. All rights reserved.
//

#import "Base64.h"


@implementation Base64

#define ArrayLength(x) (sizeof(x)/sizeof(*(x)))

static char encodingTable[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static char decodingTable[128];

+ (void) initialize 
{
    if (self == [Base64 class]) 
    {
        memset(decodingTable, 0, ArrayLength(decodingTable));
        for (NSInteger i = 0; i < ArrayLength(encodingTable); i++) {
            decodingTable[encodingTable[i]] = i;
        }
    }
}


+ (NSData*) decode:(const char*) string length:(NSInteger) inputLength 
{
    if ((string == NULL) || (inputLength % 4 != 0)) 
    {
        return nil;
    }

    while (inputLength > 0 && string[inputLength - 1] == '=') 
    {
        inputLength--;
    }

    NSInteger outputLength = inputLength * 3 / 4;
    NSMutableData* data = [NSMutableData dataWithLength:outputLength];
    uint8_t* output = data.mutableBytes;

    NSInteger inputPoint = 0;
    NSInteger outputPoint = 0;
    while (inputPoint < inputLength) 
    {
        char i0 = string[inputPoint++];
        char i1 = string[inputPoint++];
        char i2 = inputPoint < inputLength ? string[inputPoint++] : 'A'; /* 'A' will decode to \0 */
        char i3 = inputPoint < inputLength ? string[inputPoint++] : 'A';

        output[outputPoint++] = (decodingTable[i0] << 2) | (decodingTable[i1] >> 4);
        if (outputPoint < outputLength)
        {
            output[outputPoint++] = ((decodingTable[i1] & 0xf) << 4) | (decodingTable[i2] >> 2);
        }
        if (outputPoint < outputLength)
        {
            output[outputPoint++] = ((decodingTable[i2] & 0x3) << 6) | decodingTable[i3];
        }
    }

    return data;
}

+ (NSData*) decode:(NSString*) string 
{
    return [self decode:[string cStringUsingEncoding:NSASCIIStringEncoding] length:[string length]];
}

@end

最佳答案

线

NSString *imagenS = [imagen valueForKey:@"/Result"];

返回的是字典,而不是字符串。您必须检查您的数据源以确定这是否正确。

关于iphone - -[NSCF字典长度] : unrecognized selector,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7165796/

相关文章:

iphone - 如何在 ios 项目中显示 GADInterstitial?

ios - XIB 的内容未加载

ios - 如何清除 Objective-C 中的所有 NSUserDefaults 值?

ios - NSDictionary递归循环

ios - CFSocket数据回调

iphone - 如何在iOS应用程序中实现游戏中心?

ios - 使特定的 UITableViewCells 具有不同的背景颜色

iphone - 如何从 iPhone 测试用户网络速度?

objective-c - NSDictionary 为不同的键返回相同的值

swift - 如何在 swift 中向字典添加新键?