#[repr(C)]pub struct SCNText { /* private fields */ }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
impl SCNText
Sourcepub unsafe fn textWithString_extrusionDepth(
string: Option<&AnyObject>,
extrusion_depth: CGFloat,
) -> Retained<Self>
Available on crate feature objc2-core-foundation only.
pub unsafe fn textWithString_extrusionDepth( string: Option<&AnyObject>, extrusion_depth: CGFloat, ) -> Retained<Self>
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.
Sourcepub unsafe fn extrusionDepth(&self) -> CGFloat
Available on crate feature objc2-core-foundation only.
pub unsafe fn extrusionDepth(&self) -> CGFloat
objc2-core-foundation only.The extrusion depth. Animatable.
If the value is 0, we get a mono-sided, 2D version of the text.
Sourcepub unsafe fn setExtrusionDepth(&self, extrusion_depth: CGFloat)
Available on crate feature objc2-core-foundation only.
pub unsafe fn setExtrusionDepth(&self, extrusion_depth: CGFloat)
objc2-core-foundation only.Setter for extrusionDepth.
Sourcepub unsafe fn string(&self) -> Option<Retained<AnyObject>>
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.
Sourcepub unsafe fn font(&self) -> Option<Retained<NSFont>>
Available on crate feature objc2-app-kit and macOS only.
pub unsafe fn font(&self) -> Option<Retained<NSFont>>
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).
Sourcepub unsafe fn setFont(&self, font: Option<&NSFont>)
Available on crate feature objc2-app-kit and macOS only.
pub unsafe fn setFont(&self, font: Option<&NSFont>)
objc2-app-kit and macOS only.Setter for font.
Sourcepub unsafe fn isWrapped(&self) -> bool
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.
Sourcepub unsafe fn setWrapped(&self, wrapped: bool)
pub unsafe fn setWrapped(&self, wrapped: bool)
Setter for isWrapped.
Sourcepub unsafe fn containerFrame(&self) -> CGRect
Available on crate feature objc2-core-foundation only.
pub unsafe fn containerFrame(&self) -> CGRect
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.
Sourcepub unsafe fn setContainerFrame(&self, container_frame: CGRect)
Available on crate feature objc2-core-foundation only.
pub unsafe fn setContainerFrame(&self, container_frame: CGRect)
objc2-core-foundation only.Setter for containerFrame.
Sourcepub unsafe fn textSize(&self) -> CGSize
Available on crate feature objc2-core-foundation only.
pub unsafe fn textSize(&self) -> CGSize
objc2-core-foundation only.Returns the bounding box size the receiver occupies.
Sourcepub unsafe fn truncationMode(&self) -> Retained<NSString>
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.
Sourcepub unsafe fn setTruncationMode(&self, truncation_mode: &NSString)
pub unsafe fn setTruncationMode(&self, truncation_mode: &NSString)
Setter for truncationMode.
Sourcepub unsafe fn alignmentMode(&self) -> Retained<NSString>
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.
Sourcepub unsafe fn setAlignmentMode(&self, alignment_mode: &NSString)
pub unsafe fn setAlignmentMode(&self, alignment_mode: &NSString)
Setter for alignmentMode.
Sourcepub unsafe fn chamferRadius(&self) -> CGFloat
Available on crate feature objc2-core-foundation only.
pub unsafe fn chamferRadius(&self) -> CGFloat
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.
Sourcepub unsafe fn setChamferRadius(&self, chamfer_radius: CGFloat)
Available on crate feature objc2-core-foundation only.
pub unsafe fn setChamferRadius(&self, chamfer_radius: CGFloat)
objc2-core-foundation only.Setter for chamferRadius.
Sourcepub unsafe fn chamferSegmentCount(&self) -> NSInteger
πDeprecated: Use SCNText.chamferProfile instead
pub unsafe fn chamferSegmentCount(&self) -> NSInteger
The number of chamfer subdivisions. Animatable.
If the value is less than 1, the behavior is undefined. The default value is 10.
Sourcepub unsafe fn setChamferSegmentCount(&self, chamfer_segment_count: NSInteger)
πDeprecated: Use SCNText.chamferProfile instead
pub unsafe fn setChamferSegmentCount(&self, chamfer_segment_count: NSInteger)
Setter for chamferSegmentCount.
Sourcepub unsafe fn chamferProfile(&self) -> Option<Retained<NSBezierPath>>
Available on crate feature objc2-app-kit and macOS only.
pub unsafe fn chamferProfile(&self) -> Option<Retained<NSBezierPath>>
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.
Sourcepub unsafe fn setChamferProfile(&self, chamfer_profile: Option<&NSBezierPath>)
Available on crate feature objc2-app-kit and macOS only.
pub unsafe fn setChamferProfile(&self, chamfer_profile: Option<&NSBezierPath>)
objc2-app-kit and macOS only.Setter for chamferProfile.
Sourcepub unsafe fn flatness(&self) -> CGFloat
Available on crate feature objc2-core-foundation only.
pub unsafe fn flatness(&self) -> CGFloat
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.
Sourcepub unsafe fn setFlatness(&self, flatness: CGFloat)
Available on crate feature objc2-core-foundation only.
pub unsafe fn setFlatness(&self, flatness: CGFloat)
objc2-core-foundation only.Setter for flatness.
SourceΒ§impl SCNText
Methods declared on superclass SCNGeometry.
impl SCNText
Methods declared on superclass SCNGeometry.
Sourcepub unsafe fn geometry() -> Retained<Self>
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.
Sourcepub unsafe fn geometryWithSources_elements(
sources: &NSArray<SCNGeometrySource>,
elements: Option<&NSArray<SCNGeometryElement>>,
) -> Retained<Self>
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.
Sourcepub unsafe fn geometryWithSources_elements_sourceChannels(
sources: &NSArray<SCNGeometrySource>,
elements: Option<&NSArray<SCNGeometryElement>>,
source_channels: Option<&NSArray<NSNumber>>,
) -> Retained<Self>
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]]; βMethods from Deref<Target = SCNGeometry>Β§
Sourcepub unsafe fn materials(&self) -> Retained<NSArray<SCNMaterial>>
Available on crate feature SCNMaterial only.
pub unsafe fn materials(&self) -> Retained<NSArray<SCNMaterial>>
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.
Sourcepub unsafe fn setMaterials(&self, materials: &NSArray<SCNMaterial>)
Available on crate feature SCNMaterial only.
pub unsafe fn setMaterials(&self, materials: &NSArray<SCNMaterial>)
SCNMaterial only.Setter for materials.
Sourcepub unsafe fn firstMaterial(&self) -> Option<Retained<SCNMaterial>>
Available on crate feature SCNMaterial only.
pub unsafe fn firstMaterial(&self) -> Option<Retained<SCNMaterial>>
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.
Sourcepub unsafe fn setFirstMaterial(&self, first_material: Option<&SCNMaterial>)
Available on crate feature SCNMaterial only.
pub unsafe fn setFirstMaterial(&self, first_material: Option<&SCNMaterial>)
SCNMaterial only.Setter for firstMaterial.
Sourcepub unsafe fn insertMaterial_atIndex(
&self,
material: &SCNMaterial,
index: NSUInteger,
)
Available on crate feature SCNMaterial only.
pub unsafe fn insertMaterial_atIndex( &self, material: &SCNMaterial, index: NSUInteger, )
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.
Sourcepub unsafe fn removeMaterialAtIndex(&self, index: NSUInteger)
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.
Sourcepub unsafe fn replaceMaterialAtIndex_withMaterial(
&self,
index: NSUInteger,
material: &SCNMaterial,
)
Available on crate feature SCNMaterial only.
pub unsafe fn replaceMaterialAtIndex_withMaterial( &self, index: NSUInteger, material: &SCNMaterial, )
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.
Sourcepub unsafe fn materialWithName(
&self,
name: &NSString,
) -> Option<Retained<SCNMaterial>>
Available on crate feature SCNMaterial only.
pub unsafe fn materialWithName( &self, name: &NSString, ) -> Option<Retained<SCNMaterial>>
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.
Sourcepub unsafe fn geometrySources(&self) -> Retained<NSArray<SCNGeometrySource>>
pub unsafe fn geometrySources(&self) -> Retained<NSArray<SCNGeometrySource>>
The array of geometry sources of the receiver.
Sourcepub unsafe fn geometrySourcesForSemantic(
&self,
semantic: &SCNGeometrySourceSemantic,
) -> Retained<NSArray<SCNGeometrySource>>
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.
Sourcepub unsafe fn geometryElements(&self) -> Retained<NSArray<SCNGeometryElement>>
pub unsafe fn geometryElements(&self) -> Retained<NSArray<SCNGeometryElement>>
The array of geometry elements of the receiver.
Sourcepub unsafe fn geometryElementCount(&self) -> NSInteger
pub unsafe fn geometryElementCount(&self) -> NSInteger
Returns the number of geometry elements owned by the geometry.
Sourcepub unsafe fn geometryElementAtIndex(
&self,
element_index: NSInteger,
) -> Retained<SCNGeometryElement>
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.
Sourcepub unsafe fn geometrySourceChannels(
&self,
) -> Option<Retained<NSArray<NSNumber>>>
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.
Sourcepub unsafe fn levelsOfDetail(
&self,
) -> Option<Retained<NSArray<SCNLevelOfDetail>>>
Available on crate feature SCNLevelOfDetail only.
pub unsafe fn levelsOfDetail( &self, ) -> Option<Retained<NSArray<SCNLevelOfDetail>>>
SCNLevelOfDetail only.Determines the receiverβs levels of detail. Defaults to nil.
Sourcepub unsafe fn setLevelsOfDetail(
&self,
levels_of_detail: Option<&NSArray<SCNLevelOfDetail>>,
)
Available on crate feature SCNLevelOfDetail only.
pub unsafe fn setLevelsOfDetail( &self, levels_of_detail: Option<&NSArray<SCNLevelOfDetail>>, )
SCNLevelOfDetail only.Setter for levelsOfDetail.
pub unsafe fn tessellator(&self) -> Option<Retained<SCNGeometryTessellator>>
Sourcepub unsafe fn setTessellator(
&self,
tessellator: Option<&SCNGeometryTessellator>,
)
pub unsafe fn setTessellator( &self, tessellator: Option<&SCNGeometryTessellator>, )
Setter for tessellator.
Sourcepub unsafe fn subdivisionLevel(&self) -> NSUInteger
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.
Sourcepub unsafe fn setSubdivisionLevel(&self, subdivision_level: NSUInteger)
pub unsafe fn setSubdivisionLevel(&self, subdivision_level: NSUInteger)
Setter for subdivisionLevel.
Sourcepub unsafe fn wantsAdaptiveSubdivision(&self) -> bool
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.
Sourcepub unsafe fn setWantsAdaptiveSubdivision(
&self,
wants_adaptive_subdivision: bool,
)
pub unsafe fn setWantsAdaptiveSubdivision( &self, wants_adaptive_subdivision: bool, )
Setter for wantsAdaptiveSubdivision.
Sourcepub unsafe fn edgeCreasesElement(&self) -> Option<Retained<SCNGeometryElement>>
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.
Sourcepub unsafe fn setEdgeCreasesElement(
&self,
edge_creases_element: Option<&SCNGeometryElement>,
)
pub unsafe fn setEdgeCreasesElement( &self, edge_creases_element: Option<&SCNGeometryElement>, )
Setter for edgeCreasesElement.
Sourcepub unsafe fn edgeCreasesSource(&self) -> Option<Retained<SCNGeometrySource>>
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.
Sourcepub unsafe fn setEdgeCreasesSource(
&self,
edge_creases_source: Option<&SCNGeometrySource>,
)
pub unsafe fn setEdgeCreasesSource( &self, edge_creases_source: Option<&SCNGeometrySource>, )
Setter for edgeCreasesSource.
Methods from Deref<Target = NSObject>Β§
Sourcepub fn doesNotRecognizeSelector(&self, sel: Sel) -> !
pub fn doesNotRecognizeSelector(&self, sel: Sel) -> !
Handle messages the object doesnβt recognize.
See Appleβs documentation for details.
Methods from Deref<Target = AnyObject>Β§
Sourcepub fn class(&self) -> &'static AnyClass
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());Sourcepub unsafe fn get_ivar<T>(&self, name: &str) -> &Twhere
T: Encode,
πDeprecated: this is difficult to use correctly, use Ivar::load instead.
pub unsafe fn get_ivar<T>(&self, name: &str) -> &Twhere
T: Encode,
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.
Sourcepub fn downcast_ref<T>(&self) -> Option<&T>where
T: DowncastTarget,
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<SCNGeometry> for SCNText
impl AsRef<SCNGeometry> for SCNText
SourceΒ§fn as_ref(&self) -> &SCNGeometry
fn as_ref(&self) -> &SCNGeometry
SourceΒ§impl Borrow<SCNGeometry> for SCNText
impl Borrow<SCNGeometry> for SCNText
SourceΒ§fn borrow(&self) -> &SCNGeometry
fn borrow(&self) -> &SCNGeometry
SourceΒ§impl ClassType for SCNText
impl ClassType for SCNText
SourceΒ§const NAME: &'static str = "SCNText"
const NAME: &'static str = "SCNText"
SourceΒ§type Super = SCNGeometry
type Super = SCNGeometry
SourceΒ§type ThreadKind = <<SCNText as ClassType>::Super as ClassType>::ThreadKind
type ThreadKind = <<SCNText as ClassType>::Super as ClassType>::ThreadKind
SourceΒ§impl CopyingHelper for SCNText
impl CopyingHelper for SCNText
SourceΒ§impl NSCopying for SCNText
impl NSCopying for SCNText
SourceΒ§impl NSObjectProtocol for SCNText
impl NSObjectProtocol for SCNText
SourceΒ§fn isEqual(&self, other: Option<&AnyObject>) -> bool
fn isEqual(&self, other: Option<&AnyObject>) -> bool
SourceΒ§fn hash(&self) -> usize
fn hash(&self) -> usize
SourceΒ§fn isKindOfClass(&self, cls: &AnyClass) -> bool
fn isKindOfClass(&self, cls: &AnyClass) -> bool
SourceΒ§fn is_kind_of<T>(&self) -> bool
fn is_kind_of<T>(&self) -> bool
isKindOfClass directly, or cast your objects with AnyObject::downcast_refSourceΒ§fn isMemberOfClass(&self, cls: &AnyClass) -> bool
fn isMemberOfClass(&self, cls: &AnyClass) -> bool
SourceΒ§fn respondsToSelector(&self, aSelector: Sel) -> bool
fn respondsToSelector(&self, aSelector: Sel) -> bool
SourceΒ§fn conformsToProtocol(&self, aProtocol: &AnyProtocol) -> bool
fn conformsToProtocol(&self, aProtocol: &AnyProtocol) -> bool
SourceΒ§fn description(&self) -> Retained<NSObject>
fn description(&self) -> Retained<NSObject>
SourceΒ§fn debugDescription(&self) -> Retained<NSObject>
fn debugDescription(&self) -> Retained<NSObject>
SourceΒ§impl NSSecureCoding for SCNText
impl NSSecureCoding for SCNText
SourceΒ§impl RefEncode for SCNText
impl RefEncode for SCNText
SourceΒ§const ENCODING_REF: Encoding = <SCNGeometry as ::objc2::RefEncode>::ENCODING_REF
const ENCODING_REF: Encoding = <SCNGeometry as ::objc2::RefEncode>::ENCODING_REF
SourceΒ§impl SCNAnimatable for SCNText
impl SCNAnimatable for SCNText
SourceΒ§unsafe fn addAnimation_forKey(
&self,
animation: &ProtocolObject<dyn SCNAnimationProtocol>,
key: Option<&NSString>,
)
unsafe fn addAnimation_forKey( &self, animation: &ProtocolObject<dyn SCNAnimationProtocol>, key: Option<&NSString>, )
SCNAnimation only.SourceΒ§unsafe fn addAnimationPlayer_forKey(
&self,
player: &SCNAnimationPlayer,
key: Option<&NSString>,
)
unsafe fn addAnimationPlayer_forKey( &self, player: &SCNAnimationPlayer, key: Option<&NSString>, )
SCNAnimation only.SourceΒ§unsafe fn removeAllAnimations(&self)
unsafe fn removeAllAnimations(&self)
SCNAnimation only.SourceΒ§unsafe fn removeAllAnimationsWithBlendOutDuration(&self, duration: CGFloat)
unsafe fn removeAllAnimationsWithBlendOutDuration(&self, duration: CGFloat)
SCNAnimation and objc2-core-foundation only.SourceΒ§unsafe fn removeAnimationForKey(&self, key: &NSString)
unsafe fn removeAnimationForKey(&self, key: &NSString)
SCNAnimation only.SourceΒ§unsafe fn removeAnimationForKey_blendOutDuration(
&self,
key: &NSString,
duration: CGFloat,
)
unsafe fn removeAnimationForKey_blendOutDuration( &self, key: &NSString, duration: CGFloat, )
SCNAnimation and objc2-core-foundation only.SourceΒ§unsafe fn animationKeys(&self) -> Retained<NSArray<NSString>>
unsafe fn animationKeys(&self) -> Retained<NSArray<NSString>>
SCNAnimation only.SourceΒ§unsafe fn animationPlayerForKey(
&self,
key: &NSString,
) -> Option<Retained<SCNAnimationPlayer>>
unsafe fn animationPlayerForKey( &self, key: &NSString, ) -> Option<Retained<SCNAnimationPlayer>>
SCNAnimation only.SourceΒ§unsafe fn removeAnimationForKey_fadeOutDuration(
&self,
key: &NSString,
duration: CGFloat,
)
unsafe fn removeAnimationForKey_fadeOutDuration( &self, key: &NSString, duration: CGFloat, )
SCNAnimation and objc2-core-foundation only.SourceΒ§unsafe fn animationForKey(
&self,
key: &NSString,
) -> Option<Retained<CAAnimation>>
unsafe fn animationForKey( &self, key: &NSString, ) -> Option<Retained<CAAnimation>>
objc2-quartz-core and non-watchOS and crate feature SCNAnimation only.SourceΒ§unsafe fn pauseAnimationForKey(&self, key: &NSString)
unsafe fn pauseAnimationForKey(&self, key: &NSString)
SCNAnimation only.SourceΒ§unsafe fn resumeAnimationForKey(&self, key: &NSString)
unsafe fn resumeAnimationForKey(&self, key: &NSString)
SCNAnimation only.SourceΒ§impl SCNBoundingVolume for SCNText
impl SCNBoundingVolume for SCNText
SourceΒ§unsafe fn getBoundingBoxMin_max(
&self,
min: *mut SCNVector3,
max: *mut SCNVector3,
) -> bool
unsafe fn getBoundingBoxMin_max( &self, min: *mut SCNVector3, max: *mut SCNVector3, ) -> bool
SceneKitTypes and objc2-core-foundation and SCNBoundingVolume only.SourceΒ§unsafe fn setBoundingBoxMin_max(
&self,
min: *mut SCNVector3,
max: *mut SCNVector3,
)
unsafe fn setBoundingBoxMin_max( &self, min: *mut SCNVector3, max: *mut SCNVector3, )
SceneKitTypes and objc2-core-foundation and SCNBoundingVolume only.SourceΒ§unsafe fn getBoundingSphereCenter_radius(
&self,
center: *mut SCNVector3,
radius: *mut CGFloat,
) -> bool
unsafe fn getBoundingSphereCenter_radius( &self, center: *mut SCNVector3, radius: *mut CGFloat, ) -> bool
SceneKitTypes and objc2-core-foundation and SCNBoundingVolume only.SourceΒ§impl SCNShadable for SCNText
impl SCNShadable for SCNText
SourceΒ§unsafe fn program(&self) -> Option<Retained<SCNProgram>>
unsafe fn program(&self) -> Option<Retained<SCNProgram>>
SCNShadable only.SourceΒ§unsafe fn setProgram(&self, program: Option<&SCNProgram>)
unsafe fn setProgram(&self, program: Option<&SCNProgram>)
SCNShadable only.program.SourceΒ§unsafe fn handleBindingOfSymbol_usingBlock(
&self,
symbol: &NSString,
block: SCNBindingBlock,
)
unsafe fn handleBindingOfSymbol_usingBlock( &self, symbol: &NSString, block: SCNBindingBlock, )
SCNNode and SCNRenderer and block2 and SCNShadable only.SourceΒ§unsafe fn handleUnbindingOfSymbol_usingBlock(
&self,
symbol: &NSString,
block: SCNBindingBlock,
)
unsafe fn handleUnbindingOfSymbol_usingBlock( &self, symbol: &NSString, block: SCNBindingBlock, )
SCNNode and SCNRenderer and block2 and SCNShadable only.SourceΒ§unsafe fn shaderModifiers(
&self,
) -> Option<Retained<NSDictionary<SCNShaderModifierEntryPoint, NSString>>>
unsafe fn shaderModifiers( &self, ) -> Option<Retained<NSDictionary<SCNShaderModifierEntryPoint, NSString>>>
SCNShadable only.SourceΒ§unsafe fn setShaderModifiers(
&self,
shader_modifiers: Option<&NSDictionary<SCNShaderModifierEntryPoint, NSString>>,
)
unsafe fn setShaderModifiers( &self, shader_modifiers: Option<&NSDictionary<SCNShaderModifierEntryPoint, NSString>>, )
SCNShadable only.shaderModifiers.SourceΒ§unsafe fn minimumLanguageVersion(&self) -> Option<Retained<NSNumber>>
unsafe fn minimumLanguageVersion(&self) -> Option<Retained<NSNumber>>
SCNShadable only.SourceΒ§unsafe fn setMinimumLanguageVersion(
&self,
minimum_language_version: Option<&NSNumber>,
)
unsafe fn setMinimumLanguageVersion( &self, minimum_language_version: Option<&NSNumber>, )
SCNShadable only.minimumLanguageVersion.