nsmutablearray

iOS开发常识

北战南征 提交于 2020-02-02 04:30:51
一、NSString 创建字符串。 NSString *astring = @ "This is a String!"; 创建空字符串,给予赋值。 NSString *astring = [[NSString alloc] init]; astring = @ "This is a String!"; NSLog(@ "astring:%@",astring); string release]; 使用变量初始化 NSString *name = @ "Ivan!"; NSString *astring = [[NSString stringWithFormat:@”My name is %@!”,name]]; NSLog(@ "astring:%@",astring); 判断是否包含某字符串 检查字符串是否以另一个字符串开头 - ( BOOL) hasPrefix: (NSString *) aString; NSString *String1 = @ "NSStringInformation.txt"; [String1 hasPrefix:@ "NSString"] == 1 ? NSLog(@ "YES") : NSLog(@ "NO"); [String1 hasSuffix:@ ".txt"] == 1 ? NSLog(@ "YES") : NSLog(@ "NO");

Object-c 中字符串与数组的处理

旧街凉风 提交于 2020-02-02 03:55:49
//一、NSString /*----------------创建字符串的方法----------------*/ //1、创建常量字符串。 NSString *astring = @"This is a String!"; //2、创建空字符串,给予赋值。 NSString *astring = [[NSString alloc] init]; astring = @"This is a String!"; [astring release]; NSLog(@"astring:%@",astring); //3、在以上方法中,提升速度:initWithString方法 NSString *astring = [[NSString alloc] initWithString:@"This is a String!"]; NSLog(@"astring:%@",astring); [astring release]; //4、用标准c创建字符串:initWithCString方法 char *Cstring = "This is a String!"; NSString *astring = [[NSString alloc] initWithCString:Cstring]; NSLog(@"astring:%@",astring); [astring release]; //5

NSString 用法大全。

若如初见. 提交于 2020-02-02 03:48:48
一、NSString 创建字符串。 NSString *astring = @ "This is a String!" ; 创建空字符串,给予赋值。 NSString *astring = [[NSString alloc] init]; astring = @ "This is a String!" ; NSLog(@ "astring:%@" ,astring); string release]; 使用变量初始化 NSString *name = @ "Ivan!" ; NSString *astring = [[NSString stringWithFormat:@”My name is %@!”,name]]; NSLog(@ "astring:%@" ,astring); 判断是否包含某字符串 检查字符串是否以另一个字符串开头 - ( BOOL ) hasPrefix: (NSString *) aString; NSString *String1 = @ "NSStringInformation.txt" ; [String1 hasPrefix:@ "NSString" ] == 1 ? NSLog(@ "YES" ) : NSLog(@ "NO" ); [String1 hasSuffix:@ ".txt" ] == 1 ? NSLog(@ "YES" ) :

NSMutable Array in other class

风流意气都作罢 提交于 2020-01-25 23:46:17
问题 I declared an NSMutableArray in my .h and I set property and synthesize, but if i want use this array in other class? How I do? 回答1: If you have, as you stated, created an @property for the NSMutableArray , you can easily access it in other classes by name. For example: #import "MyClass.h" ... MyClass *myClass = [[MyClass alloc]init]; NSMutableArray *array = [myClass.myArray mutableCopy]; (Note: I did not use memory management.) 回答2: The basic idea here is that in your original class, the

two array retrive both value in one first array

旧时模样 提交于 2020-01-22 16:48:25
问题 First_mutableArray is 1,2,3,4,5,6 Second_MutableArray is 2,4,6,8,0,12 How to get output like this First_mutableArray is 1,2,3,4,5,6,8,0,12 ? 回答1: Ordered version: NSMutableOrderedSet *first = [NSMutableOrderedSet orderedSetWithObjects:@"1",@"2",@"3",@"4",@"5",@"6",nil]; NSOrderedSet *second = [NSOrderedSet orderedSetWithObjects:@"2",@"4",@"6",@"8",@"0",@"12",nil]; [first unionOrderedSet:second]; Variable first will contain the result. 回答2: Try : NSMutableArray *first=[NSMutableArray

iOS进阶之两个模型数组的去重方法

陌路散爱 提交于 2020-01-22 04:06:46
  经常会遇到两个数组去对比然后进行去重的计算,看了网上很多文章,都是简单的两个数组的情况,很少有介绍两个模型数组的去重,于是自己写一点自己的经验吧。   首先准备一个模型对象,这里以Person为例,对象拥有name属性: @interface Person : NSObject /** 姓名 */ @property(nonatomic, copy) NSString *name; @end   然后分别准备两个模型数组,存放一些模型数据: NSMutableArray *arr_1 = [NSMutableArray array]; for (NSInteger i = 0; i < 1000; i++) { Person *p = [[Person alloc] init]; p.name = [NSString stringWithFormat:@"name_%zd", i]; [arr_1 addObject:p]; } NSMutableArray *arr_2 = [NSMutableArray array]; for (NSInteger i = 0; i < 1000; i++) { if (i % 2 == 0) { Person *p = [[Person alloc] init]; p.name = [NSString stringWithFormat:@

NSMutableArray addObjects - unrecognized-selector

前提是你 提交于 2020-01-21 20:33:06
问题 This is how I initialize my NSMutablearray. I copy the content of cityList into cityArray. Both are NSMutableArray. FYI, I declared the'cityArray' using extern. cityArray = [[NSMutableArray alloc] init]; [cityArray addObjectsFromArray:cityList]; Then, in other method in another class, I tried to to add one more object into 'cityArray' This is how I do it. But it keep crashing when it run this line of code. NSString *allCities = @"All Cities"; [[cityArray valueForKey:@"cityName"] addObject

Remove duplicate from nsmutablearray containing nsdictionary

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-21 10:16:07
问题 I want to remove duplicates from nsmutablearray. Array Structure :- ( { "act_end_date" = ""; "act_entry_date" = "13/11/2014"; "act_recurrrance_type" = Daily; "act_start_date" = "2014-11-13"; "row_id" = 0; "act_id" = 2; } { "act_end_date" = ""; "act_entry_date" = "13/11/2014"; "act_recurrrance_type" = Daily; "act_start_date" = "2014-11-13"; "row_id" = 1; "act_id" = 2; } { "act_end_date" = ""; "act_entry_date" = "16/11/2014"; "act_recurrrance_type" = Daily1; "act_start_date" = "2014-11-15";

Add NSUInteger to NSMutableArray

ε祈祈猫儿з 提交于 2020-01-21 03:43:07
问题 Hello I am working on a project and I am trying to add an NSUInteger to an NSMutableArray. I am new to Objective-C and C in general. When I run the app NSLog displays null. I'd appreciate any help anyone is able to provide. Here is my code -(NSMutableArray *)flipCardAtIndex:(NSUInteger)index { Card *card = [self cardAtIndex:index]; [self.flipCardIndexes addObject:index]; if(!card.isUnplayable) { if(!card.isFaceUp) { for(Card *otherCard in self.cards) { if(otherCard.isFaceUp && !otherCard

NSMutable Array from One Class to Another Class in iPhone

前提是你 提交于 2020-01-17 08:07:20
问题 I have an NSMutable Array in FirstViewController class, I want to Pass that array to SecondViewController class. And I want to use that in SecondViewController class. I am doing this in Xcode 4.2.1 with ARC... How can I...? and what are the attributes i want to use when setting property... (OR) Explain me using Appdelegate files also... 回答1: There are two ways to do this. 1: Make a property for NSMutableArray in appdelegate, set the value for array in FirstViewController and retrieve value in