문제

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

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top