好吧,我知道我是obj-c的新手,但是对于所有意图和目的,下面的SEEMS就像它应该有效:
songCollection = [[NSMutableArray alloc] init];
[songCollection addObject:@"test"];
//Array is init, and I can see it in the debugger.
songCollection = [GeneralFunctions getJSONAsArray:@"library"];
// I can see the expected data in the debugger after this.
[songCollection retain];
NSLog(@"%@", [songCollection objectAtIndex:0]);
// Crashes here due to the array not responding to the selector. Also, the array is now empty.
//NSLog(@"%@", songCollection);
NSArray * songList = [songCollection objectAtIndex:1];
NSLog(@"%@", songList);
Run Code Online (Sandbox Code Playgroud)
我希望有人能在这里帮助我,我正撞在墙上!
是否有一个方法,如containsObject:对于NSMUtableArrays来检查是否存在一个对象而不必遍历整个数组并检查每个元素?检查对象是否存在于NSMutableArray中的最佳方法是什么?
我刚刚搜索了我的特定问题,虽然答案很接近,但我无法理解答案......所以我需要一些帮助.
我想用一组字典对象填充一个数组(NSMutableArray),这些字典对象是从JSON字符串解析的......我得到的字典部分,我得到的JSON解析,但当我尝试将这些对象放入NSMutableArray和NSLog我得到(null)...这是我的步骤(以一般方式)
编辑1: 我正在创建的数组名为NewFinalArray.它是一个NSMutableArray,在.h文件中声明并合成(现在是alloc'd和init'd),如DetailViewController的viewDidLoad方法中所述.它的内容将显示在UITableView中.
- 在DetailViewController中,我成功创建了一个普通的NSArray/NSMutableArray,并用我的UITableView中显示的值填充它.
- 在新场景中,我收到要通过JSON字符串显示的信息,这些字符串可以通过字典对象检索.我正在为iPHone/iPad使用Stig JSON库.我没有问题.
- 我想要做的是获取现有的字典对象(我可以从现有的数组中查看并查看)并将它们添加到一个新的数组中,用于在我的UITableview中显示菜单项.
我在我的.h文件中声明了我的mutableArray
@interface blah : ...,...,...{
NSMutableArray *newFinalArray;
// other vars and IBOutlets
}
@property (nonatomic, retain) NSMutableArray *newFinalArray;
// other @property and (IBAction) stuff
@end
Run Code Online (Sandbox Code Playgroud)然后我在我的.m文件中合成它...我甚至在viewDidLoad中分配/插入它(它是一个DetailViewController)
@synthesize this,that, newFinalArray; // keep track of newFinalArray, that's the one I want
- (void)viewDidLoad {
// other code
[[newFinalArray alloc] init]; // ya returns a warning, about not responding to alloc, but whatever (for now)
// I also tested of course without …Run Code Online (Sandbox Code Playgroud)嘿伙计们,我想知道如何在数组中找到特定类型对象的对象数.例如,我在随机位置的NSMutableArray中有6个'云',我在这个NSMutableArray中也有4个'龙'.
我怎样才能收集整数6?
我正在思考以下问题:
int z = [[SomeClass *clouds in _somearray] count];
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激.Thnx,奥利弗.
如何通过方法返回传递NSMutableArray.
我让它传递数组"空格",所以10个对象的数组传递了10个块,但没有包含在这些对象中的信息.
提前致谢
编辑:基本上我创建了另一个包含路径信息的类,因为我的控制器有点杂乱.所以我想要这个新类调用返回NSMutableArray的"create"方法.数组在路径类中很好地创建,但是当return语句触发时,它只传递空格而不是值,甚至是指针.
目前是的
return path;
Run Code Online (Sandbox Code Playgroud)
我试过了
return &path;
Run Code Online (Sandbox Code Playgroud)
而且这种情况不合时宜.
编辑2:不幸的是,这是我遇到的问题.


还在崩溃
调用
newNode = [newNode copy];
Run Code Online (Sandbox Code Playgroud)
导致崩溃
我必须更新位置2和4处的数组值.如何更新数组值.我正在初始化我的数组,如下所示.
ArrayrData=[[NSArray alloc]initWithArray:statuses]; // where statuses is also an array
Run Code Online (Sandbox Code Playgroud) 我有一个NSMutableArray包含Person类型的对象.Person对象包含NSString*name,NSString*dateStamp和NSString*testScore的参数.我想用快速枚举做的是检查NSMutableArray*testResults,查看是否存在具有相同名称参数的对象.
如果确实如此,那么我想NSMutableArray用我将要插入的具有dateStamp最新值的对象和testScore值替换现有对象.如果找到没有匹配name参数的对象,则只需插入我拥有的对象.
到目前为止,我的代码如下所示:
这是创建我要插入的对象的代码:
Person *newPerson = [[Person alloc] init];
[newPerson setPersonName:newName]; //variables newName, pass, and newDate have already been
[newPerson setScore:pass]; //created and initialized
[newPerson setDateStamp:newDate];
Run Code Online (Sandbox Code Playgroud)
这里是我尝试迭代NSMutableArray以查看是否已存在具有相同名称参数的对象的代码:
for (Person *checkPerson in personList) { //personList is of type NSMutableArray
if (newPerson.newName == checkPerson.name) {
//here is where I need to insert the code that replaces checkPerson with newPerson after a match has been found
}
else …Run Code Online (Sandbox Code Playgroud) 我有一个NSArray对象(不是NSStrings,而是自定义对象).每个对象都有一个值,obj.name 我知道如何按名称对NSMutableArray进行排序,如下所示
NSSortDescriptor *sort = [NSSortDescriptor sortDescriptorWithKey:@"name" ascending:YES];
[array sortUsingDescriptors:[NSArray arrayWithObject:sort]];
Run Code Online (Sandbox Code Playgroud)
但是,有些名称以"The","A"或"An"开头,如果它们出现,我想跳到名称中的下一个单词.反正有没有避免这三种情况,如果它们出现,会自动切换到下一个单词?
我正在用cocos2d制作一个iPhone应用程序,我在使用泄漏工具标记了一个NSMutableArray时遇到了一些麻烦,我的应用程序显然正在泄漏.我已经解决了这个问题,但我真的不明白为什么它首先出现了,所以希望有人可以向我解释.
我已经将CCParticleSystemQuad子类化了,这样我就可以添加一些实例变量,包括名为'damagedObjects'的NSMutable数组:
@interface SonicBoom : CCParticleSystemQuad{
NSMutableArray *damagedObjects;
HelloWorldLayer *gameClass;
CGPoint radiusPoint;
CGPoint origin;
}
@property(nonatomic, retain) NSMutableArray *damagedObjects;
@property(nonatomic, retain) HelloWorldLayer *gameClass;
@property CGPoint radiusPoint;
@property CGPoint origin;
@end
Run Code Online (Sandbox Code Playgroud)
这被初始化并且在主游戏类中分配了damagedObjects数组,通过设置autoRemoveOnFinish属性在完成时移除粒子系统:
-(void)createSonicBoom{
sonicBoom = [SonicBoom particleWithFile:@"SonicBoom.plist"];
sonicBoom.damagedObjects = [[NSMutableArray alloc]init];
sonicBoom.gameClass = self;
sonicBoom.autoRemoveOnFinish = YES;
//etc..........
Run Code Online (Sandbox Code Playgroud)
然后我重写了'SonicBoom'类的dealloc方法,以释放'damagedObjects'数组:
-(void)dealloc{
NSLog(@"Removing SonicBoom");
NSLog(@"damaged objects retain count = %i", damagedObjects.retainCount);
gameClass.sonicBoomActive = NO;
[damagedObjects removeAllObjects];
[damagedObjects release];
[damagedObjects release];
[super dealloc];
}
Run Code Online (Sandbox Code Playgroud)
出于某种原因,只有一个发布消息到阵列我得到了泄漏.我检查了保留计数(我从不打扰通常考虑这些),它是2,所以我现在发送两次发布消息,这似乎已经解决了问题.
这是发布它的最佳方式,有人可以解释为什么需要这样做吗?
谢谢
iphone memory-leaks objective-c nsmutablearray cocos2d-iphone
为什么这会给我一个错误?
var colorArray = [UIColor.self]
colorArray.append(UIColor.redColor()) //error here
colorArray.removeLast()
Run Code Online (Sandbox Code Playgroud)
如何定义要存储的可变数组UIColor?
nsmutablearray ×10
objective-c ×7
iphone ×6
ios ×4
ipad ×2
nsarray ×2
cocoa ×1
cocoa-touch ×1
enumeration ×1
memory-leaks ×1
nsdictionary ×1
object ×1
swift2 ×1
uicolor ×1