SCNText

Struct SCNText 

Source
#[repr(C)]
pub struct SCNText { /* private fields */ }
Available on crate features SCNGeometry and SCNParametricGeometry only.
Expand description

SCNText represents a block of text that has been extruded

See also Apple’s documentation

ImplementationsΒ§

SourceΒ§

impl SCNText

Source

pub unsafe fn textWithString_extrusionDepth( string: Option<&AnyObject>, extrusion_depth: CGFloat, ) -> Retained<Self>

Available on crate feature objc2-core-foundation only.

Creates and returns a 3D representation of given text with given extrusion depth.

Parameter string: The text to be represented.

Parameter extrusionDepth: The extrusion depth.

Source

pub unsafe fn extrusionDepth(&self) -> CGFloat

Available on crate feature objc2-core-foundation only.

The extrusion depth. Animatable.

If the value is 0, we get a mono-sided, 2D version of the text.

Source

pub unsafe fn setExtrusionDepth(&self, extrusion_depth: CGFloat)

Available on crate feature objc2-core-foundation only.

Setter for extrusionDepth.

Source

pub unsafe fn string(&self) -> Option<Retained<AnyObject>>

The text to be represented. The text must be an instance of NSString or NSAttributedString.

The default value is nil.

Source

pub unsafe fn setString(&self, string: Option<&AnyObject>)

Setter for string.

Source

pub unsafe fn font(&self) -> Option<Retained<NSFont>>

Available on crate feature objc2-app-kit and macOS only.

The font used to represent the text.

The font property is only used when the string property is not an NSAttributedString. Defaults to the system font (12 point).

Source

pub unsafe fn setFont(&self, font: Option<&NSFont>)

Available on crate feature objc2-app-kit and macOS only.

Setter for font.

Source

pub unsafe fn isWrapped(&self) -> bool

Determines whether the text is wrapped to fit within the bounds.

For the text to be wrapped you first need to set its bounds, otherwise the text is not wrapped. The default value is NO.

Source

pub unsafe fn setWrapped(&self, wrapped: bool)

Setter for isWrapped.

Source

pub unsafe fn containerFrame(&self) -> CGRect

Available on crate feature objc2-core-foundation only.

A container within which the text may be wrapped or truncated.

The text will start at the top-left corner of the rect. You need to set this property for text truncation or alignment to work. Getting this property when it has never been set returns CGRectZero.

Source

pub unsafe fn setContainerFrame(&self, container_frame: CGRect)

Available on crate feature objc2-core-foundation only.

Setter for containerFrame.

Source

pub unsafe fn textSize(&self) -> CGSize

Available on crate feature objc2-core-foundation only.

Returns the bounding box size the receiver occupies.

Source

pub unsafe fn truncationMode(&self) -> Retained<NSString>

Describes how the text is truncated to fit within the bounds.

For the text to be truncated you first need to set its bounds, otherwise the text is not truncated. The default value is kCATruncationNone. See truncation modes in CATextLayer.h.

Source

pub unsafe fn setTruncationMode(&self, truncation_mode: &NSString)

Setter for truncationMode.

Source

pub unsafe fn alignmentMode(&self) -> Retained<NSString>

Determines how individual lines of text are horizontally aligned within the bounds.

For the text to be aligned you first need to set its bounds, otherwise the text is not aligned. The default value is kCAAlignmentNatural. See alignments in CATextLayer.h.

Source

pub unsafe fn setAlignmentMode(&self, alignment_mode: &NSString)

Setter for alignmentMode.

Source

pub unsafe fn chamferRadius(&self) -> CGFloat

Available on crate feature objc2-core-foundation only.

The chamfer radius. Animatable.

Values are clamped to the range [0, extrusionDepth / 2]. The actual chamfer radius might be different to the one here specified: large values are clipped to a per-glyph max value. The default value is 0.

Source

pub unsafe fn setChamferRadius(&self, chamfer_radius: CGFloat)

Available on crate feature objc2-core-foundation only.

Setter for chamferRadius.

Source

pub unsafe fn chamferSegmentCount(&self) -> NSInteger

πŸ‘ŽDeprecated: Use SCNText.chamferProfile instead

The number of chamfer subdivisions. Animatable.

If the value is less than 1, the behavior is undefined. The default value is 10.

Source

pub unsafe fn setChamferSegmentCount(&self, chamfer_segment_count: NSInteger)

πŸ‘ŽDeprecated: Use SCNText.chamferProfile instead

Setter for chamferSegmentCount.

Source

pub unsafe fn chamferProfile(&self) -> Option<Retained<NSBezierPath>>

Available on crate feature objc2-app-kit and macOS only.

Describes the profile used to when β€œchamferRadius” is not nil. When β€œchamferProfile” is nil we fallback on a path representing a quadrant.

The profile should be a 2D curve beginning at (0,1) and ending at (1,0). The β€œflatness” property is also used to flatten this path. The default value is nil.

Source

pub unsafe fn setChamferProfile(&self, chamfer_profile: Option<&NSBezierPath>)

Available on crate feature objc2-app-kit and macOS only.

Setter for chamferProfile.

Source

pub unsafe fn flatness(&self) -> CGFloat

Available on crate feature objc2-core-foundation only.

Specifies the accuracy (or smoothness) with which fonts are rendered.

Smaller numbers give smoother curves at the expense of more computation and heavier geometries in terms of vertices. The default value is 0.6, which yields smooth curves.

Source

pub unsafe fn setFlatness(&self, flatness: CGFloat)

Available on crate feature objc2-core-foundation only.

Setter for flatness.

SourceΒ§

impl SCNText

Methods declared on superclass SCNGeometry.

Source

pub unsafe fn geometry() -> Retained<Self>

Creates and returns an empty geometry object.

An empty geometry may be used as the lowest level of detail of a geometry.

Source

pub unsafe fn geometryWithSources_elements( sources: &NSArray<SCNGeometrySource>, elements: Option<&NSArray<SCNGeometryElement>>, ) -> Retained<Self>

Creates and returns a new geometry built from geometry sources and geometry elements.

Parameter sources: An array of geometry sources. If several geometry sources have the same semantic, only the first one is taken into account.

Parameter elements: An array of geometry elements. The sort order in the array determines the mapping between materials and geometry elements.

A geometry is made of geometry sources (at least SCNGeometrySourceSemanticVertex) and at least one geometry element. Multiple sources for texture coordinates are accepted. In that case the mappingChannel is implicitly set based on the order of the texture sources, starting at index 0.

Source

pub unsafe fn geometryWithSources_elements_sourceChannels( sources: &NSArray<SCNGeometrySource>, elements: Option<&NSArray<SCNGeometryElement>>, source_channels: Option<&NSArray<NSNumber>>, ) -> Retained<Self>

Creates and returns a new geometry built from geometry sources and geometry elements, with per-source indexed geometry data.

Parameter sources: An array of geometry sources. If several geometry sources have the same semantic, only the first one is taken into account.

Parameter elements: An array of geometry elements. The sort order in the array determines the mapping between materials and geometry elements.

Parameter sourceChannels: An array of indices that describes, for each geometry source, which channel of the geometry elements to use.

Example: geometry made of 3 primitives (2 quads, 1 pentagon) using different indices to reference position and UV data (2 channels)

Positions         ┆   POS0           POS3           POS4    ┆             quad   quad   pentagon    quad   quad   pentagon    ┆   SCNGeometryElement *element = [SCNGeometryElement geometryElementWithData:…
0 β”‚ (0.0, 0.0, 0.0)   ┆        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”        ┆           β”Œβ”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”   ┆                                                               primitiveType:SCNGeometryPrimitiveTypePolygon
1 β”‚ (0.0, 1.0, 0.0)   ┆        β”‚UV0     UV3β”‚UV0     UV3β”‚        ┆     4 4 5 0 1 2 3 5 4 3 2 7 6 5 2 1 0 1 2 3 2 3 0 1 1 2 3 4 0   ┆                                                              primitiveCount:3
2 β”‚ (1.0, 0.0, 0.0)   ┆        β”‚           β”‚           β”‚        ┆     β””β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   ┆                                                         indicesChannelCount:2
3 β”‚ (1.0, 1.0, 0.0)   ┆        β”‚     A     β”‚     B     β”‚        ┆   polygons        channel 0                 channel 1           ┆                                                  interleavedIndicesChannels:…
4 β”‚ (2.0, 0.0, 0.0)   ┆        β”‚           β”‚           β”‚        ┆                  (positions)                  (UVs)             ┆                                                               bytesPerIndex:…];
5 β”‚ (2.0, 1.0, 0.0)   ┆        β”‚UV1     UV2β”‚UV1     UV2β”‚        ┆                                                                 ┆
6 β”‚ (2.0, 2.0, 0.0)   ┆   POS1 β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ POS5   ┆                                                                 ┆   SCNGeometry *geometry = [SCNGeometry geometryWithSources:
@
[positionSource, texcoordsSource]
7 β”‚ (0.0, 2.0, 0.0)   ┆        β”‚UVO       UV4       UV3β”‚        ┆                                                                 ┆                                                   elements:
@
[element]
┆        β”‚         POS2          β”‚        ┆                quad A          quad B          pentagon C       ┆                                             sourceChannels:
@
[0, 1]];
UVs               ┆        β”‚                       β”‚        ┆           β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   ┆
0 β”‚ (0.0, 0.0)        ┆        β”‚           C           β”‚        ┆     4 4 5 0 0 1 1 2 2 3 3 5 2 4 3 3 0 2 1 7 1 6 2 5 3 2 4 1 0   ┆
1 β”‚ (0.0, 1.0)        ┆        β”‚                       β”‚        ┆     β””β”€β”€β”€β”˜β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   ┆
2 β”‚ (1.0, 1.0)        ┆        β”‚UV1                 UV2β”‚        ┆   polygons               interleaved  channels                  ┆
3 β”‚ (1.0, 0.0)        ┆        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜        ┆                           (positions and UVs)                   ┆
4 β”‚ (0.5, 0.0)        ┆   POS7                          POS6    ┆                                                                 ┆

Example: geometry made of 3 primitives (2 quads, 1 pentagon) using the same indices to reference position and UV data (1 channel)

Positions         ┆   POS0           POS3           POS4    ┆             quad A      quad B      pentagon C                  ┆   SCNGeometryElement *element = [SCNGeometryElement geometryElementWithData:…
0 β”‚ (0.0, 4.0, 0.0)   ┆        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”        ┆           β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                 ┆                                                               primitiveType:SCNGeometryPrimitiveTypePolygon
1 β”‚ (0.0, 2.0, 0.0)   ┆        β”‚UV0     UV3β”‚UV3     UV4β”‚        ┆     4 4 5 0  1  2  3  5  4  3  2  7  6  5  2  1                 ┆                                                              primitiveCount:3
2 β”‚ (2.0, 2.0, 0.0)   ┆        β”‚           β”‚           β”‚        ┆     β””β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                 ┆                                                               bytesPerIndex:…];
3 β”‚ (2.0, 4.0, 0.0)   ┆        β”‚     A     β”‚     B     β”‚        ┆   polygons              channel 0                               ┆
4 β”‚ (4.0, 4.0, 0.0)   ┆        β”‚           β”‚           β”‚        ┆                    (positions and UVs)                          ┆   SCNGeometry *geometry = [SCNGeometry geometryWithSources:
@
[positionSource, texcoordsSource]
5 β”‚ (4.0, 2.0, 0.0)   ┆        β”‚UV1     UV2β”‚UV2     UV5β”‚        ┆                                                                 ┆                                                   elements:
@
[element]];
6 β”‚ (4.0, 0.0, 0.0)   ┆   POS1 β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ POS5   ┆                                                                 ┆
7 β”‚ (0.0, 0.0, 0.0)   ┆        β”‚UV1       UV2       UV5β”‚        ┆                                                                 ┆                                            === or equivalently ===
┆        β”‚         POS2          β”‚        ┆                                                                 ┆
UVs               ┆        β”‚                       β”‚        ┆                                                                 ┆   SCNGeometryElement *element = [SCNGeometryElement geometryElementWithData:…
0 β”‚ (0.0, 0.0)        ┆        β”‚           C           β”‚        ┆                                                                 ┆                                                               primitiveType:SCNGeometryPrimitiveTypePolygon
1 β”‚ (0.0, 0.5)        ┆        β”‚                       β”‚        ┆                                                                 ┆                                                              primitiveCount:3
2 β”‚ (0.5, 0.5)        ┆        β”‚UV7                 UV6β”‚        ┆                                                                 ┆                                                         indicesChannelCount:1
3 β”‚ (0.5, 0.0)        ┆        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜        ┆                                                                 ┆                                                  interleavedIndicesChannels:…
4 β”‚ (1.0, 0.0)        ┆   POS7                          POS6    ┆                                                                 ┆                                                               bytesPerIndex:…];
5 β”‚ (1.0, 0.5)        ┆                                         ┆                                                                 ┆
6 β”‚ (1.0, 1.0)        ┆                                         ┆                                                                 ┆   SCNGeometry *geometry = [SCNGeometry geometryWithSources:
@
[positionSource, texcoordsSource]
7 β”‚ (0.0, 1.0)        ┆                                         ┆                                                                 ┆                                                   elements:
@
[element]
┆                                         ┆                                                                 ┆                                             sourceChannels:
@
[0, 0]];                                                                                                                                               ┆
SourceΒ§

impl SCNText

Methods declared on superclass NSObject.

Source

pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>

Source

pub unsafe fn new() -> Retained<Self>

Methods from Deref<Target = SCNGeometry>Β§

Source

pub unsafe fn name(&self) -> Option<Retained<NSString>>

Determines the name of the receiver.

Source

pub unsafe fn setName(&self, name: Option<&NSString>)

Setter for name.

Source

pub unsafe fn materials(&self) -> Retained<NSArray<SCNMaterial>>

Available on crate feature SCNMaterial only.

Specifies the receiver’s materials array.

Each geometry element can be rendered using a different material. The index of the material used for a geometry element is equal to the index of that element modulo the number of materials.

Source

pub unsafe fn setMaterials(&self, materials: &NSArray<SCNMaterial>)

Available on crate feature SCNMaterial only.

Setter for materials.

Source

pub unsafe fn firstMaterial(&self) -> Option<Retained<SCNMaterial>>

Available on crate feature SCNMaterial only.

Determines the first material of the geometry. Returns nil if the geometry has no material.

This method is here for convenience. It is equivalent to the first object in the β€œmaterials” array above.

Source

pub unsafe fn setFirstMaterial(&self, first_material: Option<&SCNMaterial>)

Available on crate feature SCNMaterial only.

Setter for firstMaterial.

Source

pub unsafe fn insertMaterial_atIndex( &self, material: &SCNMaterial, index: NSUInteger, )

Available on crate feature SCNMaterial only.

Insert a material in the materials array at the specified index.

Parameter material: The material to insert.

Parameter index: Index in the materials array to insert the new material.

Source

pub unsafe fn removeMaterialAtIndex(&self, index: NSUInteger)

Remove the material at the specified index from the materials array.

Parameter index: The index of the material to remove from the β€˜materials’ array.

Source

pub unsafe fn replaceMaterialAtIndex_withMaterial( &self, index: NSUInteger, material: &SCNMaterial, )

Available on crate feature SCNMaterial only.

Remove the material at the index β€˜index’ from the materials array of the receiver and insert β€˜material’ in its position.

Parameter index: The index of the material to replace in the materials array.

Parameter material: The new material that will replace the previous one.

Source

pub unsafe fn materialWithName( &self, name: &NSString, ) -> Option<Retained<SCNMaterial>>

Available on crate feature SCNMaterial only.

Return the first material from the materials array of the receiver with the specified name.

Parameter name: The name of the material to retrieve.

Source

pub unsafe fn geometrySources(&self) -> Retained<NSArray<SCNGeometrySource>>

The array of geometry sources of the receiver.

Source

pub unsafe fn geometrySourcesForSemantic( &self, semantic: &SCNGeometrySourceSemantic, ) -> Retained<NSArray<SCNGeometrySource>>

Returns the geometry sources for a given semantic.

Parameter semantic: The semantic of the geometry sources that should be retrieved.

Returns nil if no geometry source is found for the given semantic. May return more than one source, typically for multiple texture coordinate sources.

Source

pub unsafe fn geometryElements(&self) -> Retained<NSArray<SCNGeometryElement>>

The array of geometry elements of the receiver.

Source

pub unsafe fn geometryElementCount(&self) -> NSInteger

Returns the number of geometry elements owned by the geometry.

Source

pub unsafe fn geometryElementAtIndex( &self, element_index: NSInteger, ) -> Retained<SCNGeometryElement>

Returns the geometry element at a given index.

Parameter elementIndex: The index of the geometry element.

Source

pub unsafe fn geometrySourceChannels( &self, ) -> Option<Retained<NSArray<NSNumber>>>

An array of indices that describes, for each geometry source, which channel of the geometry elements to use.

Source

pub unsafe fn levelsOfDetail( &self, ) -> Option<Retained<NSArray<SCNLevelOfDetail>>>

Available on crate feature SCNLevelOfDetail only.

Determines the receiver’s levels of detail. Defaults to nil.

Source

pub unsafe fn setLevelsOfDetail( &self, levels_of_detail: Option<&NSArray<SCNLevelOfDetail>>, )

Available on crate feature SCNLevelOfDetail only.

Setter for levelsOfDetail.

Source

pub unsafe fn tessellator(&self) -> Option<Retained<SCNGeometryTessellator>>

Source

pub unsafe fn setTessellator( &self, tessellator: Option<&SCNGeometryTessellator>, )

Setter for tessellator.

Source

pub unsafe fn subdivisionLevel(&self) -> NSUInteger

Specifies the subdivision level of the receiver. Defaults to 0.

A subdivision level of 0 means no subdivision. When the tessellator property of the receiver is not nil, the refinement is done on the GPU.

Source

pub unsafe fn setSubdivisionLevel(&self, subdivision_level: NSUInteger)

Setter for subdivisionLevel.

Source

pub unsafe fn wantsAdaptiveSubdivision(&self) -> bool

Specifies if the subdivision is adaptive or uniform. Defaults to YES.

Adaptive subdivision requires that the tessellator property of the receiver is not nil.

Source

pub unsafe fn setWantsAdaptiveSubdivision( &self, wants_adaptive_subdivision: bool, )

Source

pub unsafe fn edgeCreasesElement(&self) -> Option<Retained<SCNGeometryElement>>

Specifies the edges creases that control the subdivision. Defaults to nil.

The primitive type of this geometry element must be SCNGeometryPrimitiveTypeLine. See subdivisionLevel above to control the level of subdivision. See edgeCreasesSource below to specify sharpness of the creases.

Source

pub unsafe fn setEdgeCreasesElement( &self, edge_creases_element: Option<&SCNGeometryElement>, )

Setter for edgeCreasesElement.

Source

pub unsafe fn edgeCreasesSource(&self) -> Option<Retained<SCNGeometrySource>>

Specifies the crease value of the edges specified by edgeCreasesElement. Defaults to nil.

The semantic of this geometry source must be β€œSCNGeometrySourceSemanticEdgeCrease”. The creases values are floating values between 0 and 10, where 0 means smooth and 10 means infinitely sharp. See subdivisionLevel above to control the level of subdivision. See edgeCreasesElement above to specify edges for edge creases.

Source

pub unsafe fn setEdgeCreasesSource( &self, edge_creases_source: Option<&SCNGeometrySource>, )

Setter for edgeCreasesSource.

Methods from Deref<Target = NSObject>Β§

Source

pub fn doesNotRecognizeSelector(&self, sel: Sel) -> !

Handle messages the object doesn’t recognize.

See Apple’s documentation for details.

Methods from Deref<Target = AnyObject>Β§

Source

pub fn class(&self) -> &'static AnyClass

Dynamically find the class of this object.

Β§Panics

May panic if the object is invalid (which may be the case for objects returned from unavailable init/new methods).

Β§Example

Check that an instance of NSObject has the precise class NSObject.

use objc2::ClassType;
use objc2::runtime::NSObject;

let obj = NSObject::new();
assert_eq!(obj.class(), NSObject::class());
Source

pub unsafe fn get_ivar<T>(&self, name: &str) -> &T
where T: Encode,

πŸ‘ŽDeprecated: this is difficult to use correctly, use Ivar::load instead.

Use Ivar::load instead.

Β§Safety

The object must have an instance variable with the given name, and it must be of type T.

See Ivar::load_ptr for details surrounding this.

Source

pub fn downcast_ref<T>(&self) -> Option<&T>
where T: DowncastTarget,

Attempt to downcast the object to a class of type T.

This is the reference-variant. Use Retained::downcast if you want to convert a retained object to another type.

Β§Mutable classes

Some classes have immutable and mutable variants, such as NSString and NSMutableString.

When some Objective-C API signature says it gives you an immutable class, it generally expects you to not mutate that, even though it may technically be mutable β€œunder the hood”.

So using this method to convert a NSString to a NSMutableString, while not unsound, is generally frowned upon unless you created the string yourself, or the API explicitly documents the string to be mutable.

See Apple’s documentation on mutability and on isKindOfClass: for more details.

Β§Generic classes

Objective-C generics are called β€œlightweight generics”, and that’s because they aren’t exposed in the runtime. This makes it impossible to safely downcast to generic collections, so this is disallowed by this method.

You can, however, safely downcast to generic collections where all the type-parameters are AnyObject.

Β§Panics

This works internally by calling isKindOfClass:. That means that the object must have the instance method of that name, and an exception will be thrown (if CoreFoundation is linked) or the process will abort if that is not the case. In the vast majority of cases, you don’t need to worry about this, since both root objects NSObject and NSProxy implement this method.

Β§Examples

Cast an NSString back and forth from NSObject.

use objc2::rc::Retained;
use objc2_foundation::{NSObject, NSString};

let obj: Retained<NSObject> = NSString::new().into_super();
let string = obj.downcast_ref::<NSString>().unwrap();
// Or with `downcast`, if we do not need the object afterwards
let string = obj.downcast::<NSString>().unwrap();

Try (and fail) to cast an NSObject to an NSString.

use objc2_foundation::{NSObject, NSString};

let obj = NSObject::new();
assert!(obj.downcast_ref::<NSString>().is_none());

Try to cast to an array of strings.

β“˜
use objc2_foundation::{NSArray, NSObject, NSString};

let arr = NSArray::from_retained_slice(&[NSObject::new()]);
// This is invalid and doesn't type check.
let arr = arr.downcast_ref::<NSArray<NSString>>();

This fails to compile, since it would require enumerating over the array to ensure that each element is of the desired type, which is a performance pitfall.

Downcast when processing each element instead.

use objc2_foundation::{NSArray, NSObject, NSString};

let arr = NSArray::from_retained_slice(&[NSObject::new()]);

for elem in arr {
    if let Some(data) = elem.downcast_ref::<NSString>() {
        // handle `data`
    }
}

Trait ImplementationsΒ§

SourceΒ§

impl AsRef<AnyObject> for SCNText

SourceΒ§

fn as_ref(&self) -> &AnyObject

Converts this type into a shared reference of the (usually inferred) input type.
SourceΒ§

impl AsRef<NSObject> for SCNText

SourceΒ§

fn as_ref(&self) -> &NSObject

Converts this type into a shared reference of the (usually inferred) input type.
SourceΒ§

impl AsRef<SCNGeometry> for SCNText

SourceΒ§

fn as_ref(&self) -> &SCNGeometry

Converts this type into a shared reference of the (usually inferred) input type.
SourceΒ§

impl AsRef<SCNText> for SCNText

SourceΒ§

fn as_ref(&self) -> &Self

Converts this type into a shared reference of the (usually inferred) input type.
SourceΒ§

impl Borrow<AnyObject> for SCNText

SourceΒ§

fn borrow(&self) -> &AnyObject

Immutably borrows from an owned value. Read more
SourceΒ§

impl Borrow<NSObject> for SCNText

SourceΒ§

fn borrow(&self) -> &NSObject

Immutably borrows from an owned value. Read more
SourceΒ§

impl Borrow<SCNGeometry> for SCNText

SourceΒ§

fn borrow(&self) -> &SCNGeometry

Immutably borrows from an owned value. Read more
SourceΒ§

impl ClassType for SCNText

SourceΒ§

const NAME: &'static str = "SCNText"

The name of the Objective-C class that this type represents. Read more
SourceΒ§

type Super = SCNGeometry

The superclass of this class. Read more
SourceΒ§

type ThreadKind = <<SCNText as ClassType>::Super as ClassType>::ThreadKind

Whether the type can be used from any thread, or from only the main thread. Read more
SourceΒ§

fn class() -> &'static AnyClass

Get a reference to the Objective-C class that this type represents. Read more
SourceΒ§

fn as_super(&self) -> &Self::Super

Get an immutable reference to the superclass.
SourceΒ§

impl CopyingHelper for SCNText

SourceΒ§

type Result = SCNText

The immutable counterpart of the type, or Self if the type has no immutable counterpart. Read more
SourceΒ§

impl Debug for SCNText

SourceΒ§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
SourceΒ§

impl Deref for SCNText

SourceΒ§

type Target = SCNGeometry

The resulting type after dereferencing.
SourceΒ§

fn deref(&self) -> &Self::Target

Dereferences the value.
SourceΒ§

impl Hash for SCNText

SourceΒ§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 Β· SourceΒ§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
SourceΒ§

impl Message for SCNText

SourceΒ§

fn retain(&self) -> Retained<Self>
where Self: Sized,

Increment the reference count of the receiver. Read more
SourceΒ§

impl NSCoding for SCNText

SourceΒ§

unsafe fn encodeWithCoder(&self, coder: &NSCoder)
where Self: Sized + Message,

SourceΒ§

unsafe fn initWithCoder( this: Allocated<Self>, coder: &NSCoder, ) -> Option<Retained<Self>>
where Self: Sized + Message,

SourceΒ§

impl NSCopying for SCNText

SourceΒ§

fn copy(&self) -> Retained<Self::Result>
where Self: Sized + Message + CopyingHelper,

Returns a new instance that’s a copy of the receiver. Read more
SourceΒ§

unsafe fn copyWithZone(&self, zone: *mut NSZone) -> Retained<Self::Result>
where Self: Sized + Message + CopyingHelper,

Returns a new instance that’s a copy of the receiver. Read more
SourceΒ§

impl NSObjectProtocol for SCNText

SourceΒ§

fn isEqual(&self, other: Option<&AnyObject>) -> bool
where Self: Sized + Message,

Check whether the object is equal to an arbitrary other object. Read more
SourceΒ§

fn hash(&self) -> usize
where Self: Sized + Message,

An integer that can be used as a table address in a hash table structure. Read more
SourceΒ§

fn isKindOfClass(&self, cls: &AnyClass) -> bool
where Self: Sized + Message,

Check if the object is an instance of the class, or one of its subclasses. Read more
SourceΒ§

fn is_kind_of<T>(&self) -> bool
where T: ClassType, Self: Sized + Message,

πŸ‘ŽDeprecated: use isKindOfClass directly, or cast your objects with AnyObject::downcast_ref
Check if the object is an instance of the class type, or one of its subclasses. Read more
SourceΒ§

fn isMemberOfClass(&self, cls: &AnyClass) -> bool
where Self: Sized + Message,

Check if the object is an instance of a specific class, without checking subclasses. Read more
SourceΒ§

fn respondsToSelector(&self, aSelector: Sel) -> bool
where Self: Sized + Message,

Check whether the object implements or inherits a method with the given selector. Read more
SourceΒ§

fn conformsToProtocol(&self, aProtocol: &AnyProtocol) -> bool
where Self: Sized + Message,

Check whether the object conforms to a given protocol. Read more
SourceΒ§

fn description(&self) -> Retained<NSObject>
where Self: Sized + Message,

A textual representation of the object. Read more
SourceΒ§

fn debugDescription(&self) -> Retained<NSObject>
where Self: Sized + Message,

A textual representation of the object to use when debugging. Read more
SourceΒ§

fn isProxy(&self) -> bool
where Self: Sized + Message,

Check whether the receiver is a subclass of the NSProxy root class instead of the usual NSObject. Read more
SourceΒ§

fn retainCount(&self) -> usize
where Self: Sized + Message,

The reference count of the object. Read more
SourceΒ§

impl NSSecureCoding for SCNText

SourceΒ§

unsafe fn supportsSecureCoding() -> bool
where Self: Sized + ClassType,

SourceΒ§

impl PartialEq for SCNText

SourceΒ§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 Β· SourceΒ§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
SourceΒ§

impl RefEncode for SCNText

SourceΒ§

const ENCODING_REF: Encoding = <SCNGeometry as ::objc2::RefEncode>::ENCODING_REF

The Objective-C type-encoding for a reference of this type. Read more
SourceΒ§

impl SCNAnimatable for SCNText

SourceΒ§

unsafe fn addAnimation_forKey( &self, animation: &ProtocolObject<dyn SCNAnimationProtocol>, key: Option<&NSString>, )
where Self: Sized + Message,

Available on crate feature SCNAnimation only.
Adds and runs an animation Read more
SourceΒ§

unsafe fn addAnimationPlayer_forKey( &self, player: &SCNAnimationPlayer, key: Option<&NSString>, )
where Self: Sized + Message,

Available on crate feature SCNAnimation only.
Add an animation player. Read more
SourceΒ§

unsafe fn removeAllAnimations(&self)
where Self: Sized + Message,

Available on crate feature SCNAnimation only.
Remove all animations.
SourceΒ§

unsafe fn removeAllAnimationsWithBlendOutDuration(&self, duration: CGFloat)
where Self: Sized + Message,

Available on crate features SCNAnimation and objc2-core-foundation only.
Smoothly remove all animations. Read more
SourceΒ§

unsafe fn removeAnimationForKey(&self, key: &NSString)
where Self: Sized + Message,

Available on crate feature SCNAnimation only.
Remove the animation with the given identifier. Read more
SourceΒ§

unsafe fn removeAnimationForKey_blendOutDuration( &self, key: &NSString, duration: CGFloat, )
where Self: Sized + Message,

Available on crate features SCNAnimation and objc2-core-foundation only.
Smoothly remove the animation with the given identifier. Read more
SourceΒ§

unsafe fn animationKeys(&self) -> Retained<NSArray<NSString>>
where Self: Sized + Message,

Available on crate feature SCNAnimation only.
Returns an array containing the keys of all animations currently attached to the receiver.
SourceΒ§

unsafe fn animationPlayerForKey( &self, key: &NSString, ) -> Option<Retained<SCNAnimationPlayer>>
where Self: Sized + Message,

Available on crate feature SCNAnimation only.
Returns the animation player with the given identifier Read more
SourceΒ§

unsafe fn removeAnimationForKey_fadeOutDuration( &self, key: &NSString, duration: CGFloat, )
where Self: Sized + Message,

πŸ‘ŽDeprecated
Available on crate features SCNAnimation and objc2-core-foundation only.
Smoothly remove the animation with the given identifier. Read more
SourceΒ§

unsafe fn animationForKey( &self, key: &NSString, ) -> Option<Retained<CAAnimation>>
where Self: Sized + Message,

πŸ‘ŽDeprecated
Available on crate feature objc2-quartz-core and non-watchOS and crate feature SCNAnimation only.
Returns the animation with the given identifier Read more
SourceΒ§

unsafe fn pauseAnimationForKey(&self, key: &NSString)
where Self: Sized + Message,

πŸ‘ŽDeprecated: Use -[SCNAnimationPlayer setPaused:] instead
Available on crate feature SCNAnimation only.
Pause the animation with the given identifier. Read more
SourceΒ§

unsafe fn resumeAnimationForKey(&self, key: &NSString)
where Self: Sized + Message,

πŸ‘ŽDeprecated: Use -[SCNAnimationPlayer setPaused:] instead
Available on crate feature SCNAnimation only.
Resume the animation with the given identifier. Read more
SourceΒ§

unsafe fn setSpeed_forAnimationKey(&self, speed: CGFloat, key: &NSString)
where Self: Sized + Message,

πŸ‘ŽDeprecated: Use -[SCNAnimationPlayer setSpeed:] instead
Available on crate features SCNAnimation and objc2-core-foundation only.
Update the animation speed of the animation with the given identifier. Read more
SourceΒ§

unsafe fn isAnimationForKeyPaused(&self, key: &NSString) -> bool
where Self: Sized + Message,

πŸ‘ŽDeprecated: Use -[SCNAnimationPlayer paused] instead
Available on crate feature SCNAnimation only.
Returns whether the animation for the specified identifier is paused. Read more
SourceΒ§

impl SCNBoundingVolume for SCNText

SourceΒ§

unsafe fn getBoundingBoxMin_max( &self, min: *mut SCNVector3, max: *mut SCNVector3, ) -> bool
where Self: Sized + Message,

Available on crate features SceneKitTypes and objc2-core-foundation and SCNBoundingVolume only.
Fill the min and max vectors with the min and max vertex of the bounding box. Read more
SourceΒ§

unsafe fn setBoundingBoxMin_max( &self, min: *mut SCNVector3, max: *mut SCNVector3, )
where Self: Sized + Message,

Available on crate features SceneKitTypes and objc2-core-foundation and SCNBoundingVolume only.
Override the receiver bounding box with the min and max vectors provided (in local space of the receiver). Read more
SourceΒ§

unsafe fn getBoundingSphereCenter_radius( &self, center: *mut SCNVector3, radius: *mut CGFloat, ) -> bool
where Self: Sized + Message,

Available on crate features SceneKitTypes and objc2-core-foundation and SCNBoundingVolume only.
Fill the center vector with the center of the bounding sphere and store the radius of the bounding sphere in β€˜radius’. Read more
SourceΒ§

impl SCNShadable for SCNText

SourceΒ§

unsafe fn program(&self) -> Option<Retained<SCNProgram>>
where Self: Sized + Message,

Available on crate feature SCNShadable only.
Specifies a custom program used to render the receiver. Read more
SourceΒ§

unsafe fn setProgram(&self, program: Option<&SCNProgram>)
where Self: Sized + Message,

Available on crate feature SCNShadable only.
Setter for program.
SourceΒ§

unsafe fn handleBindingOfSymbol_usingBlock( &self, symbol: &NSString, block: SCNBindingBlock, )
where Self: Sized + Message,

Available on crate features SCNNode and SCNRenderer and block2 and SCNShadable only.
Sets the block to call at render time to bind the value for the specified symbol of the receiver’s SCNProgram. This method has no effect for symbols declared in shader modifiers. Read more
SourceΒ§

unsafe fn handleUnbindingOfSymbol_usingBlock( &self, symbol: &NSString, block: SCNBindingBlock, )
where Self: Sized + Message,

Available on crate features SCNNode and SCNRenderer and block2 and SCNShadable only.
Sets the block to call at render time to unbind the value for the specified symbol of the receiver’s SCNProgram. This method has no effect for symbols declared in shader modifiers. Read more
SourceΒ§

unsafe fn shaderModifiers( &self, ) -> Option<Retained<NSDictionary<SCNShaderModifierEntryPoint, NSString>>>
where Self: Sized + Message,

Available on crate feature SCNShadable only.
Dictionary of shader modifiers snippets, targeting entry points. The valid keys are the entry points described in the β€œShader Modifier Entry Point” constants. The values are the code snippets formatted as described below. Read more
SourceΒ§

unsafe fn setShaderModifiers( &self, shader_modifiers: Option<&NSDictionary<SCNShaderModifierEntryPoint, NSString>>, )
where Self: Sized + Message,

Available on crate feature SCNShadable only.
Setter for shaderModifiers.
SourceΒ§

unsafe fn minimumLanguageVersion(&self) -> Option<Retained<NSNumber>>
where Self: Sized + Message,

Available on crate feature SCNShadable only.
The minimum language version required to interpret the shadable source code (wrapped MTLLanguageVersion). Defaults to nil. Read more
SourceΒ§

unsafe fn setMinimumLanguageVersion( &self, minimum_language_version: Option<&NSNumber>, )
where Self: Sized + Message,

Available on crate feature SCNShadable only.
SourceΒ§

impl DowncastTarget for SCNText

SourceΒ§

impl Eq for SCNText

Auto Trait ImplementationsΒ§

Blanket ImplementationsΒ§

SourceΒ§

impl<T> Any for T
where T: 'static + ?Sized,

SourceΒ§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
SourceΒ§

impl<'a, T> AnyThread for T
where T: ClassType<ThreadKind = dyn AnyThread + 'a> + ?Sized,

SourceΒ§

fn alloc() -> Allocated<Self>
where Self: Sized + ClassType,

Allocate a new instance of the class. Read more
SourceΒ§

impl<T> Borrow<T> for T
where T: ?Sized,

SourceΒ§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
SourceΒ§

impl<T> BorrowMut<T> for T
where T: ?Sized,

SourceΒ§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
SourceΒ§

impl<T> From<T> for T

SourceΒ§

fn from(t: T) -> T

Returns the argument unchanged.

SourceΒ§

impl<T, U> Into<U> for T
where U: From<T>,

SourceΒ§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

SourceΒ§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

SourceΒ§

type Target = T

πŸ”¬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
SourceΒ§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

SourceΒ§

type Error = Infallible

The type returned in the event of a conversion error.
SourceΒ§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
SourceΒ§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

SourceΒ§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
SourceΒ§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
SourceΒ§

impl<T> AutoreleaseSafe for T
where T: ?Sized,