iOS Guides | Samples

UIKit.NSDataAsset Class

Platform-specific data object stored in an asset catalog.

See Also: NSDataAsset

Syntax

[Foundation.Register("NSDataAsset", true)]
[ObjCRuntime.Introduced(ObjCRuntime.PlatformName.iOS, 9, 0, ObjCRuntime.PlatformArchitecture.None, null)]
[ObjCRuntime.Unavailable(ObjCRuntime.PlatformName.WatchOS, ObjCRuntime.PlatformArchitecture.All, null)]
public class NSDataAsset : NSObject, INSCopying, IDisposable

Remarks

Asset catalogs are often used for icons and images, but may be used to deliver any kind of data in a platform-specific manner.

Within an asset catalog, there is one folder per data object. That folder contains platform-specific data files and a Contents.json file that maps platform characteristics to specific datafiles. For example:

Where Contents.json contains:

json Example

{
  "info" : {
    "version" : 1,
    "author" : "xcode"
  },
  "data" : [
    {
      "idiom" : "iphone",
      "filename" : "iphone.wav",
      "universal-type-identifier" : "com.microsoft.waveform-audio"
    },
    {
      "idiom" : "ipad",
      "filename" : "ipad.wav",
      "universal-type-identifier" : "com.microsoft.waveform-audio"
    }
  ]
}

To load an asset, call NSDataAsset.NSDataAsset(String) or NSDataAsset.NSDataAsset(String,NSBundle) passing the name of the folder. For instance:

C# Example

var assetCatalog = new NSDataAsset ("FolderName");
var data = assetCatalog.Data;
var uti = assetCatalog.TypeIdentifier;

NSError error = null;
var player = new AVAudioPlayer (data, uti, out error);
if (player != null) { //...etc

The appropriate datafile for the hardware device will be loaded.

Related content

Requirements

Namespace: UIKit
Assembly: Xamarin.iOS (in Xamarin.iOS.dll)
Assembly Versions: 0.0.0.0

The members of UIKit.NSDataAsset are listed below.

See Also: NSObject

Public Constructors

Returns the data specified in the name folder's "Contents.json" file.
Returns the data specified in the name folder's "Contents.json" file.

Protected Constructors

Constructor to call on derived classes to skip initialization and merely allocate the object.
A constructor used when creating managed representations of unmanaged objects; Called by the runtime.

Public Properties

[read-only]
override
ClassHandleIntPtr. The handle for this class.
[read-only]
DataNSData. The raw data of the asset.
[read-only]
NameString. The identifier of the asset dataset folder within the asset catalog.
[read-only]
TypeIdentifierNSString. The UTI of the NSDataAsset.Data.

Public Methods

Copy(NSZone) : NSObject
Performs a copy of the underlying Objective-C object.