I'm having trouble using any of the UTType class methods
When I try to use any of the class methods such as:
`
UTType *foo;
foo = [UTType typeWithIdentifier: @"foo" ];
Xcode displays the error:
No known class method for selector 'UTTypeImage'
Is there a header file I need to #import?
Post
Replies
Boosts
Views
Activity
[object Object]In a project I am developing with Xcode a 2d layout of the faces of Rubik's cube is displayed (see the attached Screenshot). In the center of each face's representation is a NSColorWell. The other eight cubes on that face are represented as NSButtons displaying an NSImage of the appropriate color. In response to the user selecting a new color the program resets the eight Button's image to one of the new color.
The problem is that this change is not reflected on the display even if the NSButton is sent a setNeedsDisplay message. Sending the NSButton a display message also has no effect. The change is not seen until the Button receives a mouse click or interestingly if the window is dragged from the main screen to a second screen.
I believe this a bug in AppKit.
I use an old USB keyboard. After the last system update (Monterey 12.4) the number keys no longer work. Are these keys no longer supported?
Is there any reason besides pure perversity that metal uses a left hand coordinate system?
In the code snippet below, I am trying to have a routine run concurrently with GCD. However, the queue runs the code serially. How would one force the queue to run concurrently?
The WWDC 2017 VIDEO shows:
dispatch_apply( DISPATCH_APPLY_AUTO , count , ^(size_t i) { ...} );
but Xcode doesn't seem to recognize this syntax. Would there be a value for the flag parameter of dispatch_get_global_queue that would force concurrency.
code-block
dispatch_queue_t aQueue = dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0);
dispatch_apply( turnsMax , aQueue , ^( size_t t )
{
What is the approved method of getting a random number in macOS in Objective C? Presently I'm using:
srandomdev();
randomDevice = fopen("/dev/random", "r");
//
//
//
-(uint64)random64
{
uint64_t value = 0;
int i;
for (i = 0 ; i < sizeof(value); i++)
{
value <<= 8;
value |= fgetc(randomDevice);
}
return value;
}
However, this method no longer appears in the documentation. Is there a more modern implementation?
After upgrading to Monterey I found that the Help system wasn't displaying my Help Books. After wasting an hour or so I figured out the the Help system will not display a Help Book unless the app was launched from the Applications folder. So, if you're launching the app from Xcode the Help Book won't work. If you want to see if the Help Book is properly configured you have to dig into the project's DerivedData folder, drag the app to the Applications folder and launch it from there.
I am having trouble with NSKeyedArchiver. I create an archive with
archive = [NSDictionary dictionaryWithObjectsAndKeys:
pruneTableP2, @"depth table",
nil];
archiveData = [NSKeyedArchiver archivedDataWithRootObject: archive
requiringSecureCoding: NO
error: nil];
I then get a "The data isn’t in the correct format" error when I go to unarchive it with unarchivedObjectOfClass:. The subsequent call to a depreciated method works however.
archive = [NSKeyedUnarchiver unarchivedObjectOfClass: [NSDictionary class]
fromData: fileData
error: &error];
if( archive == nil )
{
archive = [NSKeyedUnarchiver unarchiveObjectWithData: fileData];
NSLog( @"%@", [error localizedFailureReason]);
}
What am I doing wrong?
I have set the property Restorable for a window in Interface Builder but it has no effect. The window's size and location are not restored from one launch to the next. What needs to be done to get this to work right?
I'm working on an app in MacOS in which I need to do mouse picking in a MTKView. To do this I render a Hit Triangle map of the mouse active areas into a MTLTexture. Since these areas do not change at run time the map only has to be rendered once. The metal debugger noticed this and suggested the texture resources be made purgeable. So I copied the pixel data out of the texture and marked the the texture as purgeable. I then read the pixel data from the C array and the mouse picking was screwed up. The Hit Triangles were not where they were supposed to be. I fussed around a bit and by trial and error I found out the pixels were copied out into the C array in column major order rather than row major order. I looked in the Metal documentation and couldn't find anywhere where this was pointed out. Is there anywhere in the Metal docs where it specifies how the pixels are laid out in a texture and how that relates to the viewable coordinates? This is not first time I've had problems related to this. Little details like this can really hang you up.
// Since the hit map only has to be made once the data is copied out
// and the texture is made purgeable. This to stop the debugger
// from nagging about it.
[pickTexture getBytes: hitTriangleMap
bytesPerRow: PICK_TEXTURE_SIZE * sizeof(uint8 [4])
fromRegion: MTLRegionMake2D( 0 , 0 , PICK_TEXTURE_SIZE, PICK_TEXTURE_SIZE)
mipmapLevel: 0];
[pickTexture setPurgeableState: MTLPurgeableStateVolatile];
[pickDepth setPurgeableState: MTLPurgeableStateVolatile];
//
// *
// *
// *
//
// Previous inefficient version
//
// [pickTexture getBytes: hit
// bytesPerRow: PICK_TEXTURE_SIZE * sizeof(uint8 [4])
// fromRegion: MTLRegionMake2D( hitPoint.x , hitPoint.y , 1, 1)
// mipmapLevel: 0];
// New Version Column major arrays?? In any event it works this way.
x = hitPoint.x;
y = hitPoint.y;
hit = hitTriangleMap[y][x]; //Inverted subscripts!!!
if( hit[0] <= Zs)
{
cursorHit = hit[0];
if( cursorOverHitArea == NO)
[[NSCursor pointingHandCursor] set];
cursorOverHitArea = YES;
}```
I am a hobbyist programmer and I have been fooling around with Metal. In getting my feet wet in metal I have found that there is a pretty big gap between the HelloTriangle and DeferredLighting sample code from Apple and a more intermediate sample would be helpful. I have stumbled along through the brush and put together a little app that I thought that other novice metal programmers might find interesting.
Features: Vertex buffer creation in Object Space.
Composing objects into a scene in Model Space.
Transforming a scene in Model Space to Clip Space
Hit Testing / Mouse Picking
Two pass rendering to produce shadows.
I have put the project on GitHub for others to peruse:
github.com/MackenzieBD/Sample-Code/blob/main/MetalDemo.zip
I am trying to render shadows in a Metal view. I am using two render passes. In the first pass the view is rendered into a 2d depth texture from the point of view of a point light source. This writes into the depth texture a shadow map of the minimum depths in the view . In the second pass the view is rendered to the viewport. In this second pass the vertex shader transposes the input position to the point light POV giving a shadowSpacePosition. In the fragment shader the depth of a point in the shadow map is compared to the depth of the shadowSpacePosition and the result is used to modify color of that point.
The first pass seems to be working as desired. The shadow map shown in a frame capture looks good. The problem I am having is that I don't know how the coordinates used in shadowSpacePosition relate the to coordinates in the shadow map. How do I transpose the x,y,z of the shadowPosition so that the comparison function gives the proper result?
cmp = shadowTexture.sample_compare(shadowSampler, shadowPosition.xy , shadowPosition.z);
The shadowPosition coordinates are in world space relative to the light position frustum with the origin at the light. I don't know what the above comparison function expects. Texture coordinates clamped 0 to 1?
Any insights would be appreciated. Below are the relevant shaders:
// Vertex shader outputs and fragment shader inputs
typedef struct
{
		float4 clipSpacePosition [[position]];
		float4 eyeSpacePosition;
		float4 shadowSpacePosition;
		float2 textureCoordinate;
		float4 normal;
		float4 color;
} RasterizerData;
// *******************************************************
// ******** Shaders for Textured Models ************
// *******************************************************
// Vertex function
vertex RasterizerData vertexTexShader
(
		uint									 vertexID [[vertex_id]],
		constant HT_Vertex		 *vertices [[buffer(HT_Vertex_Index)]],
		constant HT_Uniform		*param [[buffer(HT_Uniform_Index)]]
)
{
		RasterizerData	out;
		vector_float4	newPosition = float4( vertices[vertexID].position , 1 );
		newPosition = param->nodeTransform[ vertices[vertexID].pickID ] * newPosition;
		out.eyeSpacePosition = newPosition;
		out.clipSpacePosition = param->perspectiveTransform * newPosition;
		out.shadowSpacePosition = param->toLampPOV * newPosition;
		out.shadowSpacePosition = param->shadowPerspective * newPosition;
		// Apply rotations about the origin to the normals
		vector_float4 newNormal = float4( vertices[vertexID].normal , 1);
		out.normal = param->normalsTransform[vertices[vertexID].pickID] * newNormal;
		out.textureCoordinate = vertices[vertexID].textCoor;
		return out;
}
// Fragment function
fragment float4 fragmentTexShader
(
		RasterizerData											in [[stage_in]],
		constant HT_Uniform								 *param [[buffer(HT_Uniform_Index)]],
		texture2d<half>										 colorTexture [[ texture(HT_Texture_Index) ]],
		depth2d<float , access::sample>		 shadowTexture [[ texture(HT_Shadow_Index)]],
		sampler														 textureSampler [[sampler(HT_Texture_Index)]]
)
{
		vector_float4	 outColor;
		vector_float3	 lightDirection;
		float					 lightDistance;
		float					 attenuation;
		vector_float3	 halfVector;
		float					 diffuse;
		float					 specular;
		float					 cmp;
		float					 coorRatio;
		vector_float3	 shadowPosition;
		vector_float3	 scatteredLight;
		vector_float3	 reflectedLight;
		vector_float3	 rgb;
		half4					 colorSample;
		bool						isShadow;
		 constexpr sampler shadowSampler(coord::normalized,
																		 filter::linear,
																		 address::clamp_to_edge,
																		 compare_func:: less);
		shadowPosition = in.shadowSpacePosition.xyz;
		cmp = shadowTexture.sample_compare(shadowSampler, shadowPosition.xy , shadowPosition.z);
	 if(cmp < 0.0001)
			 isShadow = true;
		else
				isShadow = false;
		// Sample the texture to obtain a color
		colorSample = colorTexture.sample(textureSampler, in.textureCoordinate);
// *********
// Apply Lighting Model
// *******
		 return outColor;		
}
// *****************************************************
// ******** Shaders: Make Shadow Map ************
// *******************************************************
typedef struct
{
		float4 clipSpacePosition [[position]];
} ShadowData;
// Vertex function
vertex ShadowData shadowVertexShader
(
uint									 vertexID [[vertex_id]],
constant HT_Vertex		 *vertices [[buffer(HT_Vertex_Index)]],
constant HT_Uniform		*param [[buffer(HT_Uniform_Index)]]
)
{
		ShadowData out;
		vector_float4	newPosition = float4( vertices[vertexID].position , 1 );
		newPosition = param->nodeTransform[ vertices[vertexID].pickID ] * newPosition;
		newPosition = param->toLampPOV * newPosition;
		newPosition = param->shadowPerspective * newPosition;
		out.clipSpacePosition = newPosition;
		return out;
}
I have been getting my feet wet in Metal programming. Most recently I have given myself the task of learning how to do hit testing in a MTKView. I looked around for sample code but what I found involved ray tracing which I didn't find attractive. I ended up implementing a technique I had used in OpenGL. Here one renders a scene off-screen using psuedo colors unique to each of the objects one wishes pick. One then reads the "color" at the click point to determine what was hit.
I wrote a little proof of concept program and figured out how to do this in Metal. It works quite well I think. I have uploaded the project files to GitHub:
github.com/MackenzieBD/Sample-Code
Anyone interested in how I solved this problem may download the XCode project in the file HitTest.zip. My hope is to help other novice Metal programmers like me. Also, I would welcome any criticisms from more experienced coders. Have I done anything really asinine? What would be the advantages of a different approach?
I am trying to submit a new App to the Mac AppStore. In App Store Connect, I create a new and enter the app's bundle identifier in the proper field. Then when I use Xcode to submit the application I get the following error codes:ERROR ITMS-90511: "CFBundleIdentifier Collision. The Info.plist CFBundleIdentifier value '$(PRODUCT_BUNDLE_IDENTIFIER)' of 'Mad Octahedron.app/Contents/Resources/MadOctahedron' is already in use by another application."An unknown error occurred.ERROR ITMS-90277: "Invalid Bundle Identifier. The application bundle contains a tool or framework $(PRODUCT_NAME) [com.Ambraw.MadOctahedron.pkg/Payload/Mad Octahedron.app/Contents/Resources/MadOctahedron] using the bundle identifier '$(PRODUCT_BUNDLE_IDENTIFIER)', which is not a valid bundle identifier."An unknown error occurred.ERROR ITMS-90261: "Bad CFBundleExecutable. Cannot find executable file that matches the value of CFBundleExecutable in the nested bundle $(PRODUCT_NAME) [com.Ambraw.MadOctahedron.pkg/Payload/Mad Octahedron.app/Contents/Resources/MadOctahedron] property list file."An unknown error occurred.I've tried changing the identifier and resubmitting but get the same errors. Would anyone have any ideas?