items NSArray Objective-C

I have this code from the iPod Library Access Programming Guide: Using the iPod Library:


Listing 4-1 Creating and using a generic media query


MPMediaQuery *everything = [[MPMediaQuery alloc] init];


NSLog(@"Logging items from a generic query...");

NSArray *itemsFromGenericQuery = [everything items];

for (MPMediaItem *song in itemsFromGenericQuery) {

NSString *songTitle = [song valueForProperty: MPMediaItemPropertyTitle];

NSLog (@"%@", songTitle);

}


I am unclear about the line starting with "NSArray". "items" is not a declared identifier in the code. What is "items"? How do I translate that to Swift from Objective-C?

Accepted Answer
items
is a property of MPMediaQuery, so this code translates (roughly) as:
let everything = MPMediaQuery()
let itemsFromGenericQuery = everything.items!
for song in itemsFromGenericQuery {
    // …
}

In Objective-C the type of

itemsFromGenericQuery
is NSArray; in Swift that’s translated an
[MPMediaItem]
.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
items NSArray Objective-C
 
 
Q