标签: nsmutablearray

检查NSMutableArray中是否存在项目

我有一个包含自定义对象的NSMutableArray.其内容的一个例子如下:

2013-03-14 20:06:23.895 MyMusicLibrary[1667:c07] myLibrary: (
    {
    artist = "Green Day";
    id = 1421768;
    name = "American Idiot";
    releasedate = "21 Sep 2004";
    runningtime = "57.53";
    tracks = "1: American Idiot\n2: Jesus of Suburbia\n3: Holiday/Boulevard Of Broken Dreams\n4: Are We The Waiting/St. Jimmy\n5: Give Me Novacaine/She's A Rebel\n6: Extraordinary Girl/Letterbomb\n7: Wake Me Up When September Ends\n8: Homecoming\n9: Whatsername\n";
    trackscount = 9;
    type = 1;
},
    {
    artist = Bastille;
    id = 309124896;
    name = "Bad Blood";
    releasedate = "1 Mar …
Run Code Online (Sandbox Code Playgroud)

objective-c nsmutablearray ios

-4
推荐指数
1
解决办法
807
查看次数

使用array或alloc init初始化NSMutableArray

我是Obejtive C的新手,所以当时我正在查看很多示例代码,我注意到人们初始化他们的NSMutableArray的方式不同.

NSMutableArray *items = [NSMutableArray array];
Run Code Online (Sandbox Code Playgroud)

要么

NSMutableArray *items = [[NSMutableArray alloc] init];
Run Code Online (Sandbox Code Playgroud)

在这两行中,您最终得到一个NSMutableArray对象.
它们之间有什么区别或它们完全相同?

initialization objective-c nsmutablearray

-4
推荐指数
1
解决办法
5089
查看次数

将NSMutableDictionary的内容导入NSMutable数组

如何将NSMutableDictionary的内容导入NSMutable数组?

我正在尝试跟随但它的崩溃

for(int i=0; i< [dict count] ; i++){

  [array_listToDisplay addObject:[dict objectAtIndex:i] objectForKey:@"NAMES"];
}
Run Code Online (Sandbox Code Playgroud)

请帮忙

iphone objective-c nsmutablearray nsmutabledictionary ios

-5
推荐指数
1
解决办法
2192
查看次数

无法使用for循环创建NSMutableArray

我希望有一个数值为"25公斤","26公斤"......"149公斤","150公斤"的阵列.为了简化任务我写了这个:

-(NSMutableArray*)weightArray{

    NSMutableArray *myArray;
    for (int i=25; i++; i<150){
        NSString *weightString;
        weightString = [NSString stringWithFormat:@"%d kg", i];
        [myArray addObject:weightString];
    }
    return myArray;
}
Run Code Online (Sandbox Code Playgroud)

然后在我的视图中的viewDidload中我写道:NSLog (@"%@", [self weightArray]); 但看起来它不起作用.我可能会遗漏像语法这样明显的东西.为什么不起作用?

更新:最后我找到了一个解决方案 - 首先,我在@implementation部分声明了weightArray,然后我写道:

-(void)fillingArray{

    if (!weightArray){
        for (int i=25; i<150 ;i++){
            NSString *weightString = [[NSMutableArray alloc] init];
            weightString = [NSString stringWithFormat:@"%d kg", i];
            [weightArray addObject:weightString];
            NSLog(@"%@", weightString);
        }
    }

}
Run Code Online (Sandbox Code Playgroud)

在viewDidLoad我写道:

[self fillingArray];  
 NSLog(@"%@", weightArray);
Run Code Online (Sandbox Code Playgroud)

我想,我的问题出在那个字符串NSLog(@"%@",[self weightArray]); 在方括号中,它假设是方法名称,但我试图指向数组,没有任何事情发生.

iphone objective-c nsmutablearray ios

-5
推荐指数
1
解决办法
491
查看次数

无法识别的选择器发送到Array中的实例

我试图将一个对象添加到一个数组,但它发送zig bart错误"无法识别的选择器发送到实例"下面是我的代码

AppDelegate     *appdelegate              = (AppDelegate *)[[UIApplication sharedApplication]delegate];
    NSDictionary *infomation = [self dictionaryWithContentsOfJSONString:@"Contacts.json"];
    IstructContactsOrgByEntity *ObjIstructContactsOrgByEntity=[[IstructContactsOrgByEntity alloc]initWithIstructContactsOrgByEntity:infomation];
    NSArray *array=[infomation objectForKey:@"contacts_list"];
    for (int ndx = 0; ndx < [array count]; ndx++)
    {
        NSDictionary *stream = (NSDictionary *)[array objectAtIndex:ndx];
        IstructContacts_List *ObjIstructContacts_List=[[IstructContacts_List alloc]initWithIstructContacts_List:stream];
        NSArray *Qnarray=[stream objectForKey:@"contacts"];
        for (int i=0; i<Qnarray.count; i++)
        {
            NSDictionary *Qnstream = (NSDictionary *)[Qnarray objectAtIndex:i];
            IstructContacts *ObjIstructContacts=[[IstructContacts alloc]initWithIstructContacts:Qnstream];
            [ObjIstructContacts_List.m_muteArrContacts addObject:ObjIstructContacts];
        }

        [ObjIstructContactsOrgByEntity.m_muteArrContacts_List addObject:ObjIstructContacts_List];

    }
    [appdelegate.m_ArrContactsOrgEntity addObject:ObjIstructContactsOrgByEntity];
Run Code Online (Sandbox Code Playgroud)

最后一行 [appdelegate.m_ArrContactsOrgEntity addObject:ObjIstructContactsOrgByEntity]; 是我遇到的问题.

iphone objective-c nsmutablearray ipad ios

-5
推荐指数
1
解决办法
886
查看次数

使用“NSArray *”类型的表达式初始化“NSMutableArray *”时不兼容的指针类型

这是我的代码导致上述警告:

    NSMutableArray *tbValueArray = [NSArray arrayWithObjects:oServices1.text,
                oServices2.text,oServices3.text,oServices4.text,oServices5.text,oServices6.text,
                oServices7.text,oServices8.text,oServices9.text,oServices10.text,oServices11.text,
                oServices12.text,oServices13.text,oServices14.text,oServices15.text,oServices16.text,
                oServices17.text,oServices18.text,oServices19.text,oServices20.text,oServices21.text,
                oServices22.text,oServices23.text,oServices24.text,nil];
Run Code Online (Sandbox Code Playgroud)

如何更改此设置以删除警告?(我查看了 Google 和 SO,没有发现任何适用的内容)。

objective-c nsmutablearray nsarray

-5
推荐指数
1
解决办法
7956
查看次数