Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/113.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 目标C:如何将NSString转换为UInt8数组_Ios_Arrays_Nsstring - Fatal编程技术网

Ios 目标C:如何将NSString转换为UInt8数组

Ios 目标C:如何将NSString转换为UInt8数组,ios,arrays,nsstring,Ios,Arrays,Nsstring,我的代码中有一个标记,如下所示 static const UInt8 publicKeyIdentifier[] = "com.example.zone\0"; Now in place of "com.example.zone" i need to use following String "nameWithZoneId" NSString id = @"123456"; NSString *nameWithZoneId = [@"com.example.zone" stringByApp

我的代码中有一个标记,如下所示

static const UInt8 publicKeyIdentifier[] = "com.example.zone\0";
Now in place of "com.example.zone" i need to use following String "nameWithZoneId" 

NSString id = @"123456";
NSString *nameWithZoneId = [@"com.example.zone" stringByAppendingString:id];
所以我可以使用标记作为动态方式,例如“com.example.zone123456\0”;
提前感谢。

您可以创建一个
标记
类来记录每个指定标识符的标记值(
“com.example.zone”

标签h:

@interface Tag : NSObject
+ (NSString *)nextTagForIdentifier:(NSString *)identifier
@end
Tag.m:

static NSMutableDictionary *_identifiers = nil;

@implementation Tag

+ (NSString *)nextTagForIdentifier:(NSString *)identifier
{
    if (_identifiers == nil)
        _identifiers = [NSMutableDictionary new];
    NSUInteger value = [_identifiers[identifier] unsignedInteger] + 1;
    _identifiers[identifier] = @(value);
    return [NSString stringWithFormat:@"%@%lu", identifier, value];
}

@end
你可以这样使用它:

NSString *nameWithZoneId = [Tag nextTagForIdentifier:@"com.example.zone"];

很不清楚你在问什么!非常你到底想做什么?到目前为止,您的代码中没有任何动态内容,因此没有理由不做您正在尝试的事情。@luk2302我清楚地提到了我想要用作标记的字符串,我刚刚给出了一个示例,变量id值是动态的。根据响应和反应的数量判断,这并不清楚。感谢您的回答,但我不需要创建新类。我只需要将NSString字符串转换为UInt8数组对象。因为当前我将该变量用作静态常量UInt8 publicKeyIdentifier[]=“com.example.zone\0”;