factoryClass in haxe that will be automatically subclassed by other classes - flex3

Is there any equivalent of this code :
[Frame(factoryClass="mx.managers.SystemManger")]
In haxe openfl ?

Related

Use objC in swift unit test target

I am trying to use objC code in my unit test target which is swift. But when looking at Swift Compiler section there is no bridging header setup. Any ideas why is that missing? Project was created for objC. Then I added swift unit test target.
It seems that when having objc project you have to create test target in objc as well. Adding swift file inside will trigger bridging-header dialog and create Swift Compiler section along with bridging-header row.

Swift Framework: Use System Header in Objective-C code

I'm creating a new swift framework, that contains a class that I implemented in Objective-C. This works fine, but it needs sqlite3.h. I managed to create a module map, so that I can use sqlite3.h in my Swift classes already. However when I try to use it in the Objective-C header class with #import sqlite3; I get the error "Module 'sqlite3' not found.
For reference, I created the module map for sqlite3 similar to "ifaddrs" in:
https://ind.ie/labs/blog/using-system-headers-in-swift
And again, it works fine in Swift classes, unfortunately not in the Objective-C ones. Any ideas?
Thanks a lot!

Swift extension in Cocoapods Framework causing Unrecognised Selector sent to Class

I have a Swift framework which is managed via Cocoapods and contains an extension like so:
public extension UIImage {
public static func maskedImageWithColor( color: UIColor, forImageNamed image: UIImage) {
// Implementation
}
}
When I write it in Objective C in my main application I get no compiler errors or warnings.
// No problems here!
[UIImage maskedImageWithColor:UIColor.blackColor() forImageNamed:#"myImage"];
When I run the app, however, it explodes in a mess of 'Unrecognised Selector' errors.
The weird thing is, when the framework is contained within the project and added directly to the relevant parts of build phases (i.e. not managed by Cocoapods), it all works as expected.
Other aspects of the framework—classes, enums, etc.—all work fine too, it just seems to be extensions and only when they're in an framework managed by Cocoapods.
Any ideas on what I might be missing here?
This is because the linker is not loading category methods form static library by default. If you are adding category methods(extension in swift) with static library, add -ObjC to other linker flags in your targets build settings.
Read more here

Xcode pluginDidLoad not getting called when adding objective-c file in swift plugin

I'm working on a plugin for Xcode. It is supposed to be written in Swift.
When I start with a fresh plugin project (I'm using this Xcode Plugin template which is also available via Alcatraz) the project compiles and runs fine.
The pluginDidLoad method is getting called right after Xcode starts. As soon as I add any Objective-C file (and a bridging header of course) the pluginDidLoad method is not getting called anymore.
The Objective-C file might be as simple as an empty class that is a subclass of NSObject.
Removing the target-memberbership (for the plugin-target) from the newly created Objective-C (.m) file the aforementioned mentioned method is getting called again.
Has anyone developed a Xcode plugin in Swift that also uses Objective-C files before and got this working?
Update
It seems that my original solution only works with Swift only projects because Xcode always takes the objective c class if you have one.
So here is another trick: Extend the NSObject class by the function class func pluginDidLoad(bundle: NSBundle) {} and initialize your plugin there. Then it doesn't matter on which class it is called. You might have to check that also all Swift classes subclass NSObject. I pushed it to my repository that you can have a look
Original Post
I think I could reproduce the problem now. To simplify the problem, let's say that we have only two swift classes PluginMain and PluginHelper.
As you said, sometimes the plugin isn't getting called for some mysterious reason. I was struggling with the problem again and I was wondering how Xcode knows which class is the main class. So I came up with the idea to put the following initializer in both classes PluginMain and PluginHelper
class func pluginDidLoad(bundle: NSBundle) {
let appName = NSBundle.mainBundle().infoDictionary?["CFBundleName"] as? NSString
if appName == "Xcode" {
//sharedPlugin = SwiftySafe(bundle: bundle)
//initialize your shared plugin
}
}
By putting a breakpoint or log message in pluginDidLoad in both classes, I notices that Xcode isn't ignoring the plugin, it is just loading the wrong class (e.g. PluginHelper instead of PluginMain).
The Solution
It turns out that Xcode uses the class that is compiled first as the main class and calls pluginDidLoad only on that. So you can change that by reordering the "Compiled Sources" under your target settings->Build Phases. Move your main class so that it is on top. In the following image you find an example from my project. SwiftySafe is my main class.
My example
You will find my project here https://github.com/creinders/SwiftySafe if you want to compare the settings.
The pluginDidLoad method is called on the principal class. When the principal class is a Swift class, you have to include the module name in the NSPrincipalClass Info.plist key.
So if your target name is MyPlugin and your principal class is MyClass, set NSPrincipalClass to MyPlugin.MyClass.
Also make sure that MyClass inherits from NSObject.
Sometimes you need to tell Xcode to reload bundle. Run this and restart Xcode
defaults delete com.apple.dt.Xcode DVTPlugInManagerNonApplePlugIns-Xcode-7.3

Xcode 6 crashing when using Objective-C subproject inside Swift

I have a fairly large Obj-C library that's a subproject in Xcode in several Obj-C projects and it works well.
I'm trying to use that same library in a Swift project but it's crashing Xcode when it gets to a variable declaration of one of the types from my library.
The headers seem to be working because auto-complete sees the proper types from my library. I've added my library (libMylib.a) in Link Binary with Libraries just like in my other Obj-C projects.
class thing {
var width: CGFloat
// more variables
var foo: MyClass // this is a class contained in my subproject
// functions, etc..
}
It crashes Xcode if the var foo line is there, not even when I create or access it. If it's just there. That's why I think it has something to do with not linking the subproject properly or similar.
Not sure what I'm missing.
Thanks.