How to call Objective-C code from Swift

In the new Swift language from Apple, how does one call Objective-C code?Apple mentioned that they could co-exist in one application, but does this mean that one could technically re-use old classes made in Objective-C whilst building new classes in Swift?The ReasoningObjective-C is a platform-independent language, whereas Swift is platform-dependent. Writing non-platform-dependent code (business logic libraries) in Swift would thus not be wise. However, writing platform-dependent code in it (interface related for example) would be perfectly fi...Read more

macos - How to specify which NSView to draw on in objective-c?

I found this example of drawing a rectangle in objective-c cocoaNSRect r = NSMakeRect(10, 10, 50, 60);NSBezierPath *bp = [NSBezierPath bezierPathWithRect:r];NSColor *color = [NSColor blueColor];[color set];[bp stroke];However, where should I specify which NSView to draw on in the code?For example, if I have two NSView objects, and I run this code, how do I specify which one to draw on?...Read more

cocoa - Objective-C throwing an exception in a static library. How can I catch the exception from a program using the library?

I am writing a static library with Cocoa and the Xcode project contains an "Example App" target. In the library, there are places in which I create an NSException object and raise it, with either the raise method or the @trow directive. I don't succeed to catch the exception in the example app. My code is: @try { sdk = [SDK GetInstanceWithApiKey:@"12345"]; } @catch (NSException *exception) { NSLog(@"Exception:%@",exception); }Unfortunately, the application does not go to the catch block, it crashes normally like if I called ...Read more

Objective C for Windows

What would be the best way to write Objective-C on the Windows platform?Cygwin and gcc? Is there a way I can somehow integrate this into Visual Studio?Along those lines - are there any suggestions as to how to link in and use the Windows SDK for something like this. Its a different beast but I know I can write assembly and link in the Windows DLLs giving me accessibility to those calls but I don't know how to do this without googling and getting piecemeal directions.Is anyone aware of a good online or book resource to do or explain these kinds ...Read more

objective c - Use of GL_STENCIL_TEST to render concave polygons

I'm working on a custom geometry library adapted to Quartz Composer and trying to draw some concave polygons in a Plug In. I implemented the poly2tri library, so the user can choose to triangulate or not, but it's not suitable for a per-frame polygon transformations rendering.I'm a noob in OpenGL and I've been reading and testing a lot, about stencil buffer and odd/even operations, but even code that seem to work for other people, doesn't work for me. The render context is a CGLContextObj, and I'm working on a MacBook Pro Retina Display, with N...Read more

objective c - Mac, OpenGL 4: drawing on FrameBuffer does not work

I try to implement simple OpenGL drawing to a Framebuffer object as described here.My code get compiled well, however the shape of a couple of 2D triangles isn't drawn, and the output picture doesn't get color from fragment shader. I spent many hours, but found no solution. Please, help me.During execution there is no exceptions or OpenGL errors. Using breakpoints I see that all the indices of buffers, shader program, attribute get appropriate values. And when I change glClearColor I get an output image with specified size and background color....Read more

OpenGL draws nothing on Mac, Objective-C

I'm trying to draw something using OpenGL with VAO and VBO objects. To do that, I just subclassed NSOpenGLView. By default, OpenGL v2.1 was used, so, I put a PixelFormat, wrote code, and solved all the printed errors. For now the app is running well, but nothing is drawing at the window, even glClearColor has no effect. Please, help me to find and solve the problems. My OS is Mac v10.12 with OpenGL v4.1.MyOpenGLView.m, part 1:#import "MyOpenGLView.h"#include <OpenGL/gl3.h>#include "error.h"static const char *vertexShaderSource ="#version ...Read more

Generating random numbers in Objective-C

I'm a Java head mainly, and I want a way to generate a pseudo-random number between 0 and 74. In Java I would use the method:Random.nextInt(74)I'm not interested in a discussion about seeds or true randomness, just how you accomplish the same task in Objective-C. I've scoured Google, and there just seems to be lots of different and conflicting bits of information....Read more

Shortcuts in Objective-C to concatenate NSStrings

Are there any shortcuts to (stringByAppendingString:) string concatenation in Objective-C, or shortcuts for working with NSString in general?For example, I'd like to make:NSString *myString = @"This";NSString *test = [myString stringByAppendingString:@" is just a test"];something more like:string myString = "This";string test = myString + " is just a test";...Read more

cocoa - Constants in Objective-C

I'm developing a Cocoa application, and I'm using constant NSStrings as ways to store key names for my preferences.I understand this is a good idea, because it allows easy changing of keys if necessary. Plus, it's the whole 'separate your data from your logic' notion.Anyway, is there a good way to make these constants defined once for the whole application? I'm sure that there's an easy and intelligent way, but right now my classes just redefine the ones they use....Read more

objective c - UIView frame, bounds and center

I would like to know how to use these properties in the right manner.As I understand, frame can be used from the container of the view I am creating.It sets the view position relative to the container view. It also sets the size of that view.Also center can be used from the container of the view I'm creating. This property changes the position of the view relative to its container.Finally, bounds is relative to the view itself. It changes the drawable area for the view.Can you give more info about the relationship between frame and bounds? What...Read more