Tag: enumeration

for each loop in objective c for accessing NSMutable dictionary

I am finding some difficulty in accessing mutable dictionary keys and values in Objective-C. Suppose I have this: NSMutableDictionary *xyz=[[NSMutableDictionary alloc] init]; I can set keys and values. Now, I just want to access each key and value, but I don’t know the number of keys set. In PHP it is very easy, something as […]

What is the BOOL *stop argument for enumerateObjectsUsingBlock: used for?

I’ve been using enumerateObjectsUsingBlock: a lot lately for my fast-enumeration needs, and I’m having a hard time understanding the usage of BOOL *stop in the enumeration block. The NSArray class reference states stop: A reference to a Boolean value. The block can set the value to YES to stop further processing of the array. The […]

How do I iterate over an NSArray?

I’m looking for the standard idiom to iterate over an NSArray. My code needs to be suitable for OS X 10.4+.

SWIFT ALAssetsLibrary not enumerating groups

I’m trying to gather thumbnails of all the user’s images into an array, but when I call the enumerateAssetsUsingBlock method of ALAssetsLibrary nothing seems to happen. import UIKit import AssetsLibrary class ViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate { @IBOutlet var photoLibView: UICollectionView var assetLibrary : ALAssetsLibrary = ALAssetsLibrary() func showCustomLibrary() { self.assetLibrary = ALAssetsLibrary() var assetsArray : […]

how to count number of sprites swift

I’m building an app that add sprites to the screen. In several parts of my code I want to know how many sprites I have with a certain key. At the moment I implemented it in this way var counter = 0 enumerateChildNodesWithName(“box”) { node, _ in counter = counter + 1 } println(counter) Is […]

Iterating through an Enum in Swift 3.0

I have a simple enum that I would like to iterate over. For this purpose, I’ve adopted Sequence and IteratorProtocol as shown in the code below. BTW, this can be copy/pasted to a Playground in Xcode 8. import UIKit enum Sections: Int { case Section0 = 0 case Section1 case Section2 } extension Sections : […]

Difference between associated and raw values in swift enumerations

Swift enumerations have both associated and raw values. But the use cases of these values is not clear to me. So I would really appreciate if anyone can explain the difference between the associated and raw values, an example would be very helpful.

Switch statement for imported NS_OPTIONS (RawOptionSetType) in Swift?

The switch statement in Swift is so much more expressive. I’m wondering if this might be possible: Lets look at UIViewAutoresizing for example. It’s defined in Objective-C as follows: typedef NS_OPTIONS(NSUInteger, UIViewAutoresizing) { UIViewAutoresizingNone = 0, UIViewAutoresizingFlexibleLeftMargin = 1 << 0, UIViewAutoresizingFlexibleWidth = 1 << 1, UIViewAutoresizingFlexibleRightMargin = 1 << 2, UIViewAutoresizingFlexibleTopMargin = 1 << […]

How to stop enumerateObjectsUsingBlock Swift

How do I stop a block enumeration? myArray.enumerateObjectsUsingBlock( { object, index, stop in //how do I stop the enumeration in here?? }) I know in obj-c you do this: [myArray enumerateObjectsUsingBlock:^(id *myObject, NSUInteger idx, BOOL *stop) { *stop = YES; }];

How to get the name of enumeration value in Swift?

If I have an enumeration with raw Integer values: enum City: Int { case Melbourne = 1, Chelyabinsk, Bursa } let city = City.Melbourne How can I convert a city value to a string Melbourne? Is this kind of a type name introspection available in the language? Something like (this code will not work): println(“Your […]