XPlat Windows APIs
  • XPlat Windows APIs
  • Getting started
  • XPlat.ApplicationModel
    • IPackage
    • IPackage2
    • IPackage3
    • IPackageId
    • Package
    • PackageId
    • PackageVersion
  • XPlat.ApplicationModel.DataTransfer
    • Clipboard
    • DataPackage
    • DataPackageView
    • IDataPackage
    • IDataPackageView
  • XPlat.Core
    • AppPermissionInvalidException
    • CollectionExtensions
    • NSDateExtensions
    • NSObjectExtensions
    • PackageManifestHelper
    • RequestCodeHelper
    • TaskSchedulerAwaiter
    • TimeoutTask
  • XPlat.Device.Display
    • DisplayRequest
    • IDisplayRequest
  • XPlat.Device.Geolocation
    • BasicGeoposition
    • Geocoordinate
    • GeolocationAccessStatus
    • Geolocator
    • Geoposition
    • IGeocoordinate
    • IGeolocator
    • IGeopoint
    • IGeoposition
    • IStatusChangedEventArgs
    • PositionAccuracy
    • PositionChangedEventArgs
    • PositionStatus
    • PositionStatusExtensions
    • StatusChangedEventArgs
  • XPlat.Device.Launcher
    • ILauncher
    • Launcher
    • LaunchQuerySupportStatus
  • XPlat.Device.Power
    • BatteryStatus
    • BatteryStatusChangedEventArgs
    • BatteryStatusChangedEventHandler
    • IPowerManager
    • PowerManager
  • XPlat.Device.Profile
    • AnalyticsInfo
    • AnalyticsVersionInfo
    • IAnalyticsVersionInfo
  • XPlat.Foundation
    • CollectionChange
    • IMapChangedEventArgs
    • IObservableMap
    • IPropertySet
    • MapChangedEventHandler
    • ApplicationData
    • StringMapChangedEventArgs
    • TypedEventHandler
  • XPlat.Media.Capture
    • BitmapExtensions
    • CameraCaptureUI
    • CameraCaptureUIMode
    • CameraCaptureUIPhotoCaptureSettings
    • CameraCaptureUIVideoCaptureSettings
    • ICameraCaptureUI
    • StorageFileExtensions
  • XPlat.Services.Maps
    • IMapAddress
    • IMapLocation
    • IMapLocationFinderResult
    • MapAddress
    • MapLocation
    • MapLocationDesiredAccuracy
    • MapLocationFinder
    • MapLocationFinderResult
    • MapLocationFinderStatus
  • XPlat.Storage
    • ApplicationDataContainer
    • ApplicationDataContainerSettings
    • ApplicationDataCreateDisposition
    • ApplicationDataLocality
    • BasicProperties
    • CreationCollisionOption
    • FileAccessMode
    • FileAttributes
    • IApplicationData
    • IApplicationDataContainer
    • IBasicProperties
    • IImageProperties
    • ImageProperties
    • IMusicProperties
    • IStorageFile
    • IStorageFileExtras
    • IStorageFolder
    • IStorageFolder2
    • IStorageFolderExtras
    • IStorageFolderQueryOperations
    • IStorageItem
    • IStorageItem2
    • IStorageItemContentProperties
    • IStorageItemProperties
    • IVideoProperties
    • KnownFolders
    • MusicProperties
    • NameCollisionOption
    • PhotoOrientation
    • StorageFile
    • StorageFileExtensions
    • StorageFolder
    • StorageItemContentProperties
    • StorageItemContentPropertiesExtensions
    • StorageItemCreationException
    • StorageItemException
    • StorageItemNotFoundException
    • StorageItemTypes
    • VideoOrientation
    • VideoProperties
  • XPlat.Storage.Pickers
    • FileOpenPicker
    • IFileOpenPicker
  • XPlat.UI
    • DispatcherTimer
    • IDispatcherTimer
  • XPlat.UI.Core
    • CoreDispatcher
    • CoreDispatcherPriority
    • DispatchedHandler
    • ICoreDispatcher
Powered by GitBook
On this page
  • Supported platforms
  • Static Methods
  • ToObject(this NSObject)
  1. XPlat.Core

NSObjectExtensions

Namespace: XPlat.Extensions

Defines a collection of extensions for NSObject objects.

public static class NSObjectExtensions

Supported platforms

Platform

Version

Xamarin.iOS

1.0

Static Methods

ToObject(this NSObject)

Takes a base NSObject and, depending on it's actual type, will convert the iOS object to a .NET equivalent.

public static object ToObject(this NSObject obj)

Example

This example shows how the ToObject method can be used to convert a stored value from the iOS NSUserDefaults to the .NET equivalent object.

public bool TryGetValue(string key, out object value)
{
    NSObject nsObj = null;
    if (!this.ContainsKey(key))
    {
        value = null;
    }
    else
    {
        lock (this.obj)
        {
            // Retrieve a value key from the NSUserDefaults instance.
            nsObj = this.standardUserDefaults.ValueForKey(new NSString(key));
        }

        // Converts the NSObject to the relevant .NET equivalent.
        value = nsObj.ToObject();
    }

    return nsObj != null;
}

Parameters

obj (NSObject)

The iOS object to convert to a .NET object.

Returns

Returns the converted .NET object value.

PreviousNSDateExtensionsNextPackageManifestHelper

Last updated 6 years ago