0

I'm accessing the iPhone's library and doing a query on it

MPMediaQuery *albums = [MPMediaQuery albumsQuery];
NSArray *albumCollections = [albums collections];

If music doesn't exist, [albums collections] obviously causes a crash.

How can I check the results of the query, and see for example if something has been selected (or length > 0) to avoid the crash?

Thx

Sr.Richie
  • 5,680
  • 5
  • 38
  • 62

1 Answers1

0

Obviously? It's just an NSArray you are getting the information from, it shouldn't crash even if it doesn't exist.

On the worst case:

NSArray *albumCollections = [albums collections];

albumCollections is nil.

Rui Peres
  • 25,741
  • 9
  • 87
  • 137
  • sorry, I didn't realize the crash was somewhere else. If it's ok for you I'm going to remove the question as it is misleading – Sr.Richie Jan 17 '14 at 18:43
  • @Sr.Richie You should mark it as correct, as it was helpful for you. It can help someone else in the future. – Rui Peres Jan 17 '14 at 19:20