1

I'm trying to get the last image from the album and share it on social media but whenever I tried searching for solutions, they are all either in Objective-C or Swift and I don't really understand either of the language.

I searched for solutions and got this which is in Objective-C: Get last image from Photos.app?

and I have problems trying to convert the code myself from Objective-C to C# in Xamarin.IOS

The main problem that I got stuck with when converting is this line

fetchOptions.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:NO]];

I could not find sortDescriptorWithKey anywhere in Xamarin.IOS

Community
  • 1
  • 1
Mr Anoimus
  • 69
  • 11

1 Answers1

0

It is in the constructor according to the documentation: https://developer.xamarin.com/api/type/Foundation.NSSortDescriptor/#Public_Constructors

so something like:

fetchOptions.SortDescriptors = new NSSortDescriptor[] {new NSSortDescriptor("creationDate", false)};
Marc Bruins
  • 136
  • 1
  • 9
  • I can't believe I missed that, but I'm still having a small problem, it is now saying: "cannot implicitly convert type Foundation.NSSortDescriptor to Foundation.NSSortDescriptor[]" – Mr Anoimus May 26 '16 at 09:47
  • SortDescriptors expects an array i assume, you only return 1 instance and not an array of NSSortDescriptors. What the objective c does in your example is its wraps the one instance in a array by using the []. In C# it would be something like: fetchOptions.SortDescriptors = new NSSortDescriptor[] {new NSSortDescriptor("creationDate", false)}; – Marc Bruins May 26 '16 at 10:32