- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我有一个 Mutable NSArray 存储对象类型(ids - NSNumber、NSString),它将存储数字(1、2、3、4 等)、操作(+、-、/、* 等),和变量(x、y、z 等)。我将变量和相关值存储在 NSDictionary 中,键是 NSStrings,等于 x、y、z,NSNumber 值分别为 5、5、2。我想用存储在 NSDictionary 中的实际值替换 NSArray 中的变量。当我尝试替换对象时,我不断收到以下错误。请帮忙。
-[__NSArrayI replaceObjectAtIndex:withObject:]: 无法识别的选择器发送到实例
NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys:
[NSNumber numberWithDouble:5],@"x",
[NSNumber numberWithDouble:5],@"y",
[NSNumber numberWithDouble:2],@"z",
nil];
+ (double)runProgram:(id)program
usingVariableValues:(NSDictionary *)variableValues;
{
// introspection - ensure program is NSArray and variableValues is NSDictionary
if ([program isKindOfClass:[NSArray class]] && [variableValues isKindOfClass: [NSDictionary class]])
{
// array for program stack
NSMutableArray *stack = [program copy];
// Loop to replace variables with actual values in NSDictionary
for (NSUInteger i = 0; i < [stack count]; i++)
{
NSLog(@"object at index = %@", [stack objectAtIndex:i]);
if ([[stack objectAtIndex:i] isKindOfClass:[NSString class]] && [[stack objectAtIndex:i] isEqualToString: @"x"])
{
// replace variable with value in corresponding value in dictionary
NSNumber *numberKeyValue = [variableValues objectForKey:@"x"];
[stack replaceObjectAtIndex:i withObject:numberKeyValue];
}
}
return 0
}
最佳答案
NSArray 的copy
方法总是返回一个不可变数组,不管原始数组是可变的还是不可变的。如果你想要一个可变副本,你需要使用 mutableCopy
。 (这是 Cocoa 的约定。NSString、NSDictionary 以及通常任何具有可变和不可变变体的类都将以相同的方式工作。)
关于objective-c - -[__NSArrayI replaceObjectAtIndex :withObject:]: unrecognized selector sent to instance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11787802/
我正在使用Coreplot API创建条形图。当我尝试作为单个项目运行相同的代码时,它运行良好,但是当我将其集成到UINavigationController中的项目中时,这给我一个错误。 Graph
我在 Swift 3 中实现了以下功能: func parseJSON() { var JsonResult: NSMutableArray = NSMutableArray()
我有一个带有NSArray object userIDs 的实现文件 NSArray *userIDs; NSInteger friendID; @implementation TableViewCo
我正在从我的服务器收到响应,它看起来像这样: 2012-09-12 16:29:11.690 WhatIsIt[1763:707] ( { qid = ebb81a9c0c2125c9
所以我正在编写一个 NSTableView 代码。一切都很好——直到我的控制流停止工作。 出于某种原因,数组定义为 _permanentItems = @[ @[@"My", @"Permanent"
我正在尝试将数据从 Collection View Controller 传递到 Table View Controller,但是当我认为一切正常时,就会出现这个问题。无法识别的选择器发送到实例 我的
我已使用委托(delegate)将 NSArray 值传回父 View 。 在父 View 中是这样接收的 - (void) setManufactureSearchFields:(NSArray *
我是 objective-c 的新手,我想知道是否有人可以帮助我弄清楚为什么我的应用程序总是崩溃。我相信它与我的阵列有关,但我不确定如何修复它。有人可以帮忙吗??? .. 这是崩溃时的日志输出: 20
我有这个代码: override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) ->
我有三个继承自 UITableViewController 类的 View 。第一个显示位置列表,第二个显示带有注释的 map ,该注释表示在第一个 View 中选择的行的位置,最后一个显示有关位置的
let url = "http://xyz/index_main.php?c=webservices&a=get&e=007" Alamofire.request(url, method: .
什么是 __NSArrayI 和 __NSArrayM? __NSArrayI(or M) 导致“无法识别的选择器”错误。 如何转成NSArray? 我确实测试过解析 json,twitter api
过去在以前的 iPhoneOS 下将自己标识为 NSCFArray 的对象现在似乎在运行 iOS 4.0 的设备下将自己标识为 __NSArrayI。 知道这是怎么回事吗?我在任何文档中都找不到它。
我正在尝试从 Parse 获取所有数据,并将这些数据与手机中的核心数据同步。我目前遇到一个提取请求未正确执行的小问题。我认为原因是我将 ManagedObjectContext 用于不同的任务,但我真
我正在尝试在 Flutter 中创建一个 Uint8List,将其放入 JSON 字符串中并将该字符串传递给 native 代码。这是我的Flutter 代码: final jsonObj = {
在 tableView 中,我有一些对象显示得很好。但是,当我与列表交互并向下(向前)滚动时,应用程序将崩溃。我以前从未见过这种情况,也不知道为什么会这样。我将第 3 方日历与我的代码结合使用,我认为
这段代码的基本前提是它有两个字段,一个以英尺为单位存储人的高度的文本字段,一个以英寸为单位存储高度的文本字段。因此,当有人单击英尺文本字段或英寸文本字段时,会弹出一个选择器 View ,允许用户选择高
从周日开始,我尝试用 100 种方法初始化 NSMutableArray,但没有任何效果。我尝试将其设置为等于新分配和初始化的 NSMutableArray,只需分配并自行初始化变量,我能想到的每种组
这个问题在这里已经有了答案: How can I debug 'unrecognized selector sent to instance' error (9 个回答) 关闭 7 年前。
我有一个 Mutable NSArray 存储对象类型(ids - NSNumber、NSString),它将存储数字(1、2、3、4 等)、操作(+、-、/、* 等),和变量(x、y、z 等)。我将
我是一名优秀的程序员,十分优秀!