gpt4 book ai didi

ios - NSDictionary和NSMutableDictionary组合

转载 作者:行者123 更新时间:2023-12-01 18:45:54 25 4
gpt4 key购买 nike

我的应用程序使用存储在deviceToken类中的dataModel类。整个应用程序通过各种AFNetworking commands使用设备 token 。

//Notice the syntax for the deviceToken class in this NSDictionary
NSDictionary *params = @{@"cmd":@"join",
@"token":[_dataModel deviceToken],

下面是通过 [_dataModel deviceToken]使用 NSMutableDictionary类的另一种方法。
NSMutableDictionary* params =[NSMutableDictionary dictionaryWithObjectsAndKeys:command, @"command",                             
[_dataModel deviceToken], @"token", nil ];

事情是我的应用程序使用了两个不同的API,我想通过儿子将 [_dataModel deviceToken]类传递给新字典。当前,此字典在称为 UILabelcaption中显示用户的用户名。
//This message organizes photos, and shows the users username on them
-(id)initWithIndex:(int)i andData:(NSDictionary*)data
{
self = [super init];
if (self !=nil)
{
//add the photo caption
UILabel* caption = [[UILabel alloc] initWithFrame:CGRectMake(0, kThumbSide-32, kThumbSide, 32)];

caption.text = [NSString stringWithFormat:@"@%@",[data objectForKey:@"username"]];
[self addSubview: caption];
}

我想用设备 token 格式化称为 UILabelcaption,如您在上面看到的,它当前显示用户名。问题是当我尝试在标题标签中显示设备 token 时,出现编译器问题。正确的语法是什么?
caption.text = [NSString stringWithFormat:@"@%@",[data objectForKey:@"token"],[_dataModel deviceToken]];

最佳答案

仔细检查stringWithFormat:中的格式字符串,很明显编译器会向您提供正确且非常有用的警告。整个问题与字典无关。

顺便说一句。使用最少的代码行没有价格。使用更多,更简单的语句可使代码更易于调试。

关于ios - NSDictionary和NSMutableDictionary组合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35932510/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com