2013-11-22 45 views
0

我是iOS新手。我有一個警告信息,我可以不能解決它:) 我有以下代碼:將NSArray轉換爲NSSortDescriptor

NSSortDescriptor *sortDescriptorFirst = [NSSortDescriptor sortDescriptorWithKey:@"test" ascending:YES]; 
NSSortDescriptor *descriptor=[NSArray arrayWithObjects:sortDescriptorFirst,nil]; 
NSArray *sortedArray =[sections sortedArrayUsingDescriptors:@[descriptor]]; 

在第2行我有一個警告:

Incompatible pointer types initializing NSSortDescriptor with an expression of NSArray 

如何解決這個問題?

回答

2

你已經在第一行創建NSSortDescriptor,所以你並不需要第二之一:

NSSortDescriptor *sortDescriptorFirst = [NSSortDescriptor sortDescriptorWithKey:@"test" ascending:YES]; 
NSArray *sortedArray =[sections sortedArrayUsingDescriptors:@[sortDescriptorFirst]];