2014-06-09 82 views
0

我有一個包含一些CGPoints值的數組,其中包含一些CGPoints值,稍後將其添加到其他數組數據中。循環遍歷數組並刪除具有相同值的索引

CGFloat xpoint = [[points objectAtIndex:0] floatValue]; 
    CGFloat ypoint = [[points objectAtIndex:1] floatValue]; 
    CGFloat xpoint1 = [[points objectAtIndex:2] floatValue]; 
    CGFloat ypoint1 = [[points objectAtIndex:3] floatValue]; 
    CGFloat xpoint2 = [[points objectAtIndex:4] floatValue]; 
    CGFloat ypoint2 = [[points objectAtIndex:5] floatValue]; 
    CGFloat xpoint3 = [[points objectAtIndex:6] floatValue]; 
    CGFloat ypoint3 = [[points objectAtIndex:7] floatValue]; 
    CGFloat xpoint4 = [[points objectAtIndex:8] floatValue]; 
    CGFloat ypoint4 = [[points objectAtIndex:9] floatValue]; 
    CGFloat xpoint5 = [[points objectAtIndex:10] floatValue]; 
    CGFloat ypoint5 = [[points objectAtIndex:11] floatValue]; 
    CGFloat xpoint6 = [[points objectAtIndex:12] floatValue]; 
    CGFloat ypoint6 = [[points objectAtIndex:13] floatValue]; 
    CGFloat xpoint7 = [[points objectAtIndex:14] floatValue]; 
    CGFloat ypoint7 = [[points objectAtIndex:15] floatValue]; 
    CGFloat xpoint8 = [[points objectAtIndex:16] floatValue]; 
    CGFloat ypoint8 = [[points objectAtIndex:17] floatValue]; 
    CGFloat xpoint9 = [[points objectAtIndex:18] floatValue]; 
    CGFloat ypoint9 = [[points objectAtIndex:19] floatValue]; 

[data addObject:[NSValue valueWithCGPoint:CGPointMake(xpoint,ypoint)]]; 
    [data addObject:[NSValue valueWithCGPoint:CGPointMake(xpoint1,ypoint1)]]; 
    [data addObject:[NSValue valueWithCGPoint:CGPointMake(xpoint2,ypoint2)]]; 
    [data addObject:[NSValue valueWithCGPoint:CGPointMake(xpoint3,ypoint3)]]; 
    [data addObject:[NSValue valueWithCGPoint:CGPointMake(xpoint4,ypoint4)]]; 
    [data addObject:[NSValue valueWithCGPoint:CGPointMake(xpoint5,ypoint5)]]; 
    [data addObject:[NSValue valueWithCGPoint:CGPointMake(xpoint6,ypoint6)]]; 
    [data addObject:[NSValue valueWithCGPoint:CGPointMake(xpoint7,ypoint7)]]; 
    [data addObject:[NSValue valueWithCGPoint:CGPointMake(xpoint8,ypoint8)]]; 
    [data addObject:[NSValue valueWithCGPoint:CGPointMake(xpoint9,ypoint9)]]; 

我想打一個循環,通過數組和檢查的X koordinates具有相同值的循環,然後刪除「最老」的價值。 Fx。

(x,y) 
1,1 
2,2 
2,3 
2,4 
3,4 

我只想要一個值爲2,但同時我想要所有的y值,其中x值= 2,添加。然後刪除值,所以只有一個x值= 2回來。所以我想輸出TOD是:

(x,y) 
1,1 
2,9 
3,4 

請幫我:)

親切的問候

+0

我認爲你應該接受至少一些你給過去的答案的問題。 – trudyscousin

回答

1

可以循環中的所有值,並將其添加到新陣列,鯨也將其添加到字典,它的關鍵是你想刪除的,所以在添加之前,檢查它是否已經在字典中,以知道它是否已經添加

+0

您可以爲我提供一段代碼嗎? –

相關問題