سؤال

To save a UIImage to a PNG or JPEG locally you call the asPNG().Save(...) function.

The asPNG().Save() function requires an out NSError

The problem is that you can no longer just create a blank NSError to pass in like this (Obsolete)

NSError err = new NSError();  //Obsolete

So, to use the Save() function in MonoTouch, how do we create an NSError() object now?

هل كانت مفيدة؟

المحلول

In .NET you do not have to initialize any out parameter (in contrast to ref parameters) since it's the called method job to do so.

E.g.

NSError err; // unitialized
UIImage img = ...;
img.AsPNG ().Save (url, true, our err);
if (err != null && err.Code != 0) {
    // error handling
}

نصائح أخرى

Only the default empty constructor for NSError is obsolete, not the NSError class itself. Feel free to specify the appropriate domain and code for your scenario and pass it in. Should work fine.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top