我的代码:
NSArray *array = //objects here
NSMutableArray *mutarray = [[NSMutableArray alloc] init];
for (NSString *s in array)
{
NSRange ran = [s rangeOfString:@"abc"];
if (ran.location != NSNotFound)
{
int inde = [array indexOfObject:s];
[mutarray setValue:[NSNumber numberWithInt:inde] forKey:s];
}
}
NSLog (@"mutarray: %@", mutarray);
Run Code Online (Sandbox Code Playgroud)
我尝试过NSMutableDictionary,但内容是无序的,所以我更喜欢NSMutableArray有序地存储值和键.但NSLog的输出什么也没有显示,到底是什么?NSMutableDictionary的输出显示了四个发现.
编辑:
我甚至在NSLog前面尝试过这段代码,但没有显示:
[mutarray setValue:@"aha" forKey:@"jaha"];
Run Code Online (Sandbox Code Playgroud)
编辑:伙计们,谢谢你的回答!现在我明白了.但问题是我将数字存储为值和字符串作为键.我有一个无序的NSMutableDictionary.我还没弄明白我应该怎么订购它.我有我使用的代码,但没有正确编写:
NSInteger intSort(id num1, id num2, void *context)
{
int v1 = [num1 intValue];
int v2 = [num2 intValue];
if (v1 < v2)
return NSOrderedAscending;
else if (v1 > v2)
return …Run Code Online (Sandbox Code Playgroud) 我想将NSDate从XML保存到coreData.我不知道如何设置NSDate的值.有人能给我一点帮助吗?我的实体属性是NSDate.或者它应该是一个字符串并将日期保存为字符串?
[Sets setValue:[TBXML textForElement:xmlDate] forKey:@"beginDate"];
Run Code Online (Sandbox Code Playgroud)
感谢任何回应和帮助,
brush51
这是我的组合模型
Ext.define('ExtJS.myApp.ComboModel', {
extend: 'Ext.data.Model',
alias: 'widget.combomodel',
fields: [
{ name: 'ID', type: 'int' },
{ name: 'title', type: 'string' }
]
});
Run Code Online (Sandbox Code Playgroud)
这是comboStore
this.comboStore = Ext.create('Ext.data.Store', {
model: 'ExtJS.myApp.ComboModel',
autoLoad: true,
scope: this,
proxy: {
type: 'ajax',
scope: this,
url: 'myApp/GetRecords',
reader: {
type: 'json',
root: 'data'
}
}
});
this.myComboBox = Ext.create('Ext.form.ComboBox', {
store: this.comboStore,
queryMode: 'local',
displayField: 'title',
valueField: 'ID'
});
Run Code Online (Sandbox Code Playgroud)
这是我为我的商店获得的json对象:
{"ID":"111","title":"Ext Page 1"}
Run Code Online (Sandbox Code Playgroud)
现在,当我尝试像这样设置组合框的值.this.myComboBox.setValue( '111');
组合框显示"111"而不是"Ext Page 1"
在设置valueField时,我需要做什么才能使组合框显示displayField.例如.我想将值设置为"Ext Page 1"供用户查看,但在保存值时,我实际上想要保存"111"
我有这个枚举
enum Items { pen = 5, watch = 4, rubber = 1, ruler = 8};
Run Code Online (Sandbox Code Playgroud)
我想将watch(现在是4)的值更改为6.所以这样的事情:
Items.watch = 6;
Run Code Online (Sandbox Code Playgroud)
但这不起作用.有任何想法吗?
我是Java的新手,正在完成一项任务.我应该创建我自己的类"Cylinder"并从中调用方法,以便能够打印出半径和高度,然后更改它并再次打印出来.我得到它来打印cylinder1的设定值和cylinder1.setRadius/setHeight..my问题是我必须打印像Cylinder Radius:和Height:...但是当它打印所有我得到的是3.04.0或者它设置的任何......我花了很长时间试图解决这个问题,欢迎任何帮助!
public class Funtimes{
public static void main(String[] args){
Cylinder cylinder1= new Cylinder(1,2);
System.out.println(cylinder1);
cylinder1.setRadius(3);
cylinder1.setHeight(4);
System.out.println(cylinder1);
}}
class Cylinder
{
private double radius, height, area, volume;
public Cylinder(double height, double radius){
this.radius = radius;
this.height=height;
}
public double getRadius() {
return radius;
}
public double getHeight() {
return height;
}
public double getArea() {
double area = (2 * Math.PI * radius * height) + (2 * Math.PI * Math.pow(radius, 2));
return area;
}
public void setRadius(double r) …Run Code Online (Sandbox Code Playgroud) 我试图在三角形的三个对象上设置第二和第三角的值.如果明确地完成,这看起来像这样:
triangle_mesh[0].set_vector_point2(vector_anchors[1]);
triangle_mesh[1].set_vector_point3(vector_anchors[1]);
triangle_mesh[1].set_vector_point2(vector_anchors[2]);
triangle_mesh[2].set_vector_point3(vector_anchors[2]);
triangle_mesh[2].set_vector_point2(vector_anchors[3]);
triangle_mesh[0].set_vector_point3(vector_anchors[3]);
Run Code Online (Sandbox Code Playgroud)
这很有效!打印这些三角形,我得到(nb第一个角已经设置 - 这不是问题):
triangle0 is ( 0, 0, -1) (1, 0, 0) (-0.5, -0.866025, 0)
triangle1 is ( 0, 0, -1) (-0.5, 0.866025, 0) (1, 0, 0)
triangle2 is ( 0, 0, -1) (-0.5, -0.866025, 0) (-0.5, 0.866025, 0)
Run Code Online (Sandbox Code Playgroud)
首先,这是丑陋的,其次它必须推广到我有三个以上三角形设置的情况.我的代码是:
for (int longitude = 0; longitude < num_longitudes; longitude++){
SurfaceVector current_anchor = vector_anchors[1 + longitude];
triangle_mesh[longitude].set_vector_point2(current_anchor);
triangle_mesh[(longitude + 1) % num_longitudes].set_vector_point3(current_anchor);
}
Run Code Online (Sandbox Code Playgroud)
*nb num_longitudes是3*
我已经检查了我能想到的一切,但现在当我打印出三角形时,我得到:
triangle0 is ( 0, …Run Code Online (Sandbox Code Playgroud)