fast-enumeration

Need JSON document that is generated to be in same order as objects inserted in NSMutableDictionary in iOS

心已入冬 提交于 2019-12-10 18:33:41
问题 I am generating a JSON document from an NSMutableDictionary that is composed of keys that point to NSStrings, as well as two keys that point in turn to other NSMutableDictionary's. My problem is that when I output the JSON document, I notice that the JSON document has the objects that I inserted in the NSMutableDictionary in a different order. For example, my present output looks like this: JSON Output: { "devicetype" : "iPhone Simulator", "os" : "6.0", "test_results" : [ { "date" : "2012-12

Setting objects to nil during fast enumeration [duplicate]

核能气质少年 提交于 2019-12-10 06:56:15
问题 This question already has answers here : Why is __strong required in fast enumeration loops with ARC (2 answers) Closed 5 years ago . I want to set an object to 'nil' as I enumerate through an array, as follows: for(Object* object in array){ object = nil; } Xcode then tells me 'Fast enumeration variables can't be modified in ARC by default; declare the variable __strong to allow this.' Which means doing this: for(Object __strong* object in array){ object = nil; } This seems to be redundant.

Fast Enumeration through UICollectionView Cells - Swift

我的未来我决定 提交于 2019-12-07 02:10:26
问题 I am trying to fast enumerate through all of my collection view cells, however this implementation below is giving me a warning. for cell in self.collectionView?.visibleCells() as [UICollectionViewCell] { // Do Stuff } Error below appears on first line: Operand of postfix '?' should have optional type; type is '(UICollectionView, cellForItemAtIndexPath: NSIndexPath) -> UICollectionViewCell' I've tried messing around with optionals and had this working in Xcode 6 Beta 6, but to no avail in

Fast Enumeration through UICollectionView Cells - Swift

半城伤御伤魂 提交于 2019-12-05 07:18:50
I am trying to fast enumerate through all of my collection view cells, however this implementation below is giving me a warning. for cell in self.collectionView?.visibleCells() as [UICollectionViewCell] { // Do Stuff } Error below appears on first line: Operand of postfix '?' should have optional type; type is '(UICollectionView, cellForItemAtIndexPath: NSIndexPath) -> UICollectionViewCell' I've tried messing around with optionals and had this working in Xcode 6 Beta 6, but to no avail in "Beta 7" How do i get rid of this error? / Write a loop that goes through all my CollectionView Cells ?

Objective c “for each” (fast enumeration) — evaluation of collection?

自闭症网瘾萝莉.ら 提交于 2019-12-05 00:53:46
It seems from experimentation that the collection expression is evaluated only once. Consider this example: static NSArray *a; - (NSArray *)fcn { if (a == nil) a = [NSArray arrayWithObjects:@"one", @"two", @"three", nil]; NSLog(@"called"); return a; } ... for (NSString *s in [self fcn]) NSLog(@"%@", s); The output is: 2010-10-07 07:37:31.419 WidePhotoViewer Lite[23694:207] called 2010-10-07 07:37:31.420 WidePhotoViewer Lite[23694:207] one 2010-10-07 07:37:31.425 WidePhotoViewer Lite[23694:207] two 2010-10-07 07:37:31.425 WidePhotoViewer Lite[23694:207] three indicating that [self fcn] is

How to enumerate through UITextFields on iOS

对着背影说爱祢 提交于 2019-12-04 04:22:42
问题 Which is the correct way of enumerating through sub views to find text fields? NSMutableArray *mutableTFs = [[NSMutableArray alloc] init]; for (UIView *view in [self.view subviews]) { if ([view isKindOfClass:[UITextField class]]) { [mutableTFs addObject:view]; } } OR NSMutableArray *mutableTFs = [[NSMutableArray alloc] init]; for (UITextField *textField in [self.view subviews]) { [mutableTFs addObject:textField]; } I know this isn't the correct wording, but what I don't understand is if it is

Access objects of a specific type using for-in loop in Objective C [duplicate]

回眸只為那壹抹淺笑 提交于 2019-12-02 10:22:13
问题 This question already has answers here : Fast Enumeration on NSArray of Different Types (5 answers) Closed 5 years ago . I am running a for-in loop over an NSMutableArray . There are instances of Class A in the array also out of those some are actually instances of its subclass B . So If I only want members of subclass B , I am checking the class of each object I get in an if condition inside the loop body. Is it possible that instead of writing something like this, for(A* obj in collection){

Access objects of a specific type using for-in loop in Objective C [duplicate]

◇◆丶佛笑我妖孽 提交于 2019-12-02 03:10:02
This question already has an answer here: Fast Enumeration on NSArray of Different Types 5 answers I am running a for-in loop over an NSMutableArray . There are instances of Class A in the array also out of those some are actually instances of its subclass B . So If I only want members of subclass B , I am checking the class of each object I get in an if condition inside the loop body. Is it possible that instead of writing something like this, for(A* obj in collection){ if([obj isKindOfClass:[B class]]){ //take some action. } } I can do something like this? for(B* obj in collection){ //take

Why does fast enumeration not skip the NSNumbers when I specify NSStrings?

我只是一个虾纸丫 提交于 2019-12-01 07:08:01
I thought that I knew how to use fast enumeration, but there is something I don't understand about it. If I create three NSString objects and three NSNumber objects and put them in an NSMutableArray : NSString *str1 = @"str1"; NSString *str2 = @"str2"; NSString *str3 = @"str3"; NSNumber *nb1 = [NSNumber numberWithInt:1]; NSNumber *nb2 = [NSNumber numberWithInt:2]; NSNumber *nb3 = [NSNumber numberWithInt:3]; NSArray *array = [[NSArray alloc] initWithObjects:str1, str2, str3, nb1, nb2, nb3, nil]; then I make do fast enumeration on all NSString objects, like this: for (NSString *str in array) {

Is this an inefficient way of using fast enumeration?

回眸只為那壹抹淺笑 提交于 2019-12-01 04:16:31
问题 I don't entirely understand the details of how fast enumeration works, but compare the following two cases: for(NSObject *object in self.myParent.parentsParents.granfathersMother.cousin.unclesNephew.array) { // do something } vs. NSArray *array = self.myParent.parentsParents.granfathersMother.cousin.unclesNephew.array; for(NSObject *object in array) { // do something } In the first example, will it go through that entire chain every iteration to get the array? Should I be using the second way