swift 3 override init does not override / cannot find overloads - overriding

I can't seem to extend a class from cocoapod ra1028/Former in my application with the right initializers from the parent class. Why is this?
See below situation divided into the code from the pod and my application code (ExtendedFormLabelHeaderView class)
// ra1028/Former cocaopod class signatures
public protocol FormableView: class {}
public protocol LabelFormableView: FormableView {}
open class FormHeaderFooterView: UITableViewHeaderFooterView {
required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override public init(reuseIdentifier: String?) {
super.init(reuseIdentifier: reuseIdentifier)
}
}
open class FormLabelHeaderView: FormHeaderFooterView, LabelFormableView {
required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override public init(reuseIdentifier: String?) {
super.init(reuseIdentifier: reuseIdentifier)
}
}
// my app code
open class ExtendedFormLabelHeaderView: FormLabelHeaderView {
required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override public init(reuseIdentifier: String?) {
super.init(reuseIdentifier: reuseIdentifier)
}
}
Running above code in the playground works.
But running it as setup in my workspace (coming from Swift 2.2, converted to Swift 3) it will first complain about ExtendedFormLabelHeaderView's override init(reuseIdentifier: String?) initializer not being public (most likely because it cannot find the initializer it needs to override?) and then I end up with these error messages:
Initializer does not override a designated initializer from its superclass.
Argument labels '(reuseIdentifier:)' do not match any available overloads
Some other things to note:
It worked back in 2.2
I updated Former to the latest Swift 3.0 version
Removing the override keyword from the offending initializer in my ExtendedFormLabelHeaderView class will give a different error for the first line: Initializer 'init(reuseIdentifier:)' with Objective-C selector initWithReuseIdentifier:' conflicts with implicit initializer 'init(reuseIdentifier:)' from superclass

Related

Symfony 3.4 apply tag on all classes who implement same interface

I'm working with a Symfony 3.4 (PHP 7.2, update to 7.4 soon) project. I have some classes who extends an abstract class and i would like all my classes got the same constant name (constant have value different in each class). I'm starting with a pattern like this :
abstract class AbstractClass
{
abstract public function getConstant(): string;
}
final class Foo extends AbstractClass
{
const MY_CONST = 'foo';
public function getConstant(): string
{
return self::MY_CONST;
}
}
final class Bar extends AbstractClass
{
const MY_CONST = 'bar';
public function getConstant(): string
{
return self::MY_CONST;
}
}
// echo $foo->getConstant() : 'foo'
// echo $bar->getConstant() : 'bar'
The goal: if a class who extends AbstractClass don't have MY_CONST, i want return an message error.
I have excluded theses solutions :
I can't add a constant in an interface (maybe in PHP 8 ?)
I can't use "abstract factory" pattern for a constant (in my code it runs with getConstant() method
I can't use a static property
The only way i have found is : implement an interface and tag the interface like explain in documentation. With compilerpass, helped with ReflexionClass, i will check if constant name exist, and if not: thrown an error or something like this.
So, i've edit like this :
final class Foo extends AbstractClass implements MyCustomInterface
{
// ...
}
final class Bar extends AbstractClass implements MyCustomInterface
{
// ...
}
The interface :
interface MyCustomInterface
{
}
Adding tag in AppKernel.php
protected function build(ContainerBuilder $container): void
{
$container
->registerForAutoconfiguration(MyCustomInterface::class)
->addTag('my_custom_tag');
}
And a compilerpass :
class MyCustomPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container): void
{
if (!$container->has(MyCustomInterface::class)) {
dump('No interface found');
return;
}
$definition = $container->findDefinition(MyCustomInterface::class);
$taggedServices = $container->findTaggedServiceIds('my_custom_tag');
dump($taggedServices);
}
}
The fun begin here...if i have only ONE class who implement the interface, $taggedServices find the service. BUT, if more than one class implements interface, no class are found...
I don't find where i am wrong. Do i need to implements AbstractClass instead of children classes ?

Error when extending FungibleToken: supportedSchemas() in QueryableState clashes with supportedSchemas() in FungibleState

I'm using the Java template (token-template branch), tokens SDK version is 1.1-SNAPSHOT.
I'm extending FungibleToken class to add one extra attribute (PublicKey owningAccount) and I'm getting this error inside Intellij (as red underlines):
supportedSchemas() in QueryableState clashes with supportedSchemas() in FungibleState, attempting to use incompatible type
When I add the below function; the compile error is gone (Intellij no longer shows red underlines), but I get a different error on ./gradlew deployNodes:
#NotNull
#Override
public List<FungibleTokenSchemaV1> supportedSchemas() {
return super.supportedSchemas();
}
Build error:
> Task :contracts:compileJava FAILED
MyToken.java:33: error: supportedSchemas() in MyToken cannot implement supportedSchemas() in QueryableState
public List<FungibleTokenSchemaV1> supportedSchemas() {
^
return type List<FungibleTokenSchemaV1> is not compatible with Iterable<MappedSchema>
1 error
Even though List is Iterable and FungibleTokenSchemaV1 is MappedSchmea.
Full code of class:
public class MyToken extends FungibleToken {
private final PublicKey owningAccount;
public Shoken(Amount<IssuedTokenType> amount,
AbstractParty holder,
SecureHash tokenTypeJarHash,
PublicKey owningAccount) {
super(amount, holder, tokenTypeJarHash);
this.owningAccount = owningAccount;
}
public PublicKey getOwningAccount() {
return owningAccount;
}
#NotNull
#Override
public List<FungibleTokenSchemaV1> supportedSchemas() {
return super.supportedSchemas();
}
}
I would suggest you to use evolvableTokentype to issue tokens with evolvable attributes. The FungibleToken and NonFungibleToken objects are only the instruments that carries the issuance of the tokens. The underlying template of the token is what stores the information.
Feel free to look at our TokenSDK workshop at https://www.youtube.com/watch?v=IAViczRAEyU.

How to customize Unity Dependency injection to select a different constructor as an extension

I am not in control of the registration of dependencies of my unity container and want to build an extension that allows me to select a different constructor then the default one.
So how do i do this in a builder strategy like below?
public sealed class CustomBuilderStrategy : BuilderStrategy
{
private readonly CustomBuildExtension extension;
public CustomBuilderStrategy(CustomBuildExtension extension)
{
this.extension = extension;
}
public override void PreBuildUp(IBuilderContext context)
{
//Check if type has more than one constructor
// select a random constructor and build the object. (I will write my own custom code then if this works.
base.PreBuildUp(context);
}
public override void PostTearDown(IBuilderContext context)
{
base.PostTearDown(context);
}
public override void PostBuildUp(IBuilderContext context)
{
base.PostBuildUp(context);
}
public override void PreTearDown(IBuilderContext context)
{
base.PreTearDown(context);
}
}
You can find some data regarding to overriding the object creation at:
https://weblogs.asp.net/ricardoperes/unity-part-10-custom-build-strategies
To get information about the constructors for a given type you can use reflection
typeof(type).GetConstructors()

strucutreMap Dependency injection is not working

In my application i configured structuremap like
public class DefaultRegistry : Registry {
#region Constructors and Destructors
public DefaultRegistry() {
Scan(
scan => {
scan.Assembly("Eterp.Data.ErpCore");
scan.Assembly("Eterp.Data.Seed");
scan.Assembly("Eterp.Application.ErpCore");
scan.TheCallingAssembly();
scan.WithDefaultConventions();
});
ForConcreteType<AclAuthorizationManager>().Configure.Ctor<IResourceOperationAppService>()
}
#endregion
}
And i have class
public class AclAuthorizationManager : ClaimsAuthorizationManager
{
private readonly IResourceOperationAppService _resourceOperationAppService;
public AclAuthorizationManager(IResourceOperationAppService resourceOperationAppService)
{
_resourceOperationAppService = resourceOperationAppService;
}
public override bool CheckAccess(AuthorizationContext context)
{
var isCurrentUserAuthorized = context.Principal.Identity.IsAuthenticated;
return isCurrentUserAuthorized && _resourceOperationAppService.CanAccessResource(context.Action.FirstOrDefault().Value, context.Principal.Claims);
}
}
This class is custom claim authorization class using in my application, but when i exceuting the application,i am getting an error which related to lack of parameter required by the constructor, ( This class has constructor with parameter type IResourceOperation). but i already configured all the details in structureMap . i am sure that my structuremap configuration is working 100% well expect the creation of this AclAuthorizationManager class.because i am able to to apply DI in other classes.
What is wrong part in my code?
in my experience when you specify the type constructor must say that inherits from the interface.
Therefore, you should replace this line:
ForConcreteType<AclAuthorizationManager>().Configure.Ctor<IResourceOperationAppService>()
By:
ForConcreteType<AclAuthorizationManager>().Configure.Ctor<IResourceOperationAppService>().Is<ResourceOperationAppService>()
Where is the implementation ResourceOperationAppService IResourceOperationAppService.

How can I aggregate interfaces into with castle dynamic proxy

I would like to allow for declarative mixin management in my codebase. I would like to declare an interface like
public interface IMyRepo : IRepository, ICanFindPeopleByName, ICantSing {}
So my classes can consume only the bits of the data access layer they need. In my IoC container I would like to aggregate the implementations of these interfaces into a single instance. However when I do things similar to the referenced threads, the generator throws an exception stating that interfaces are implemented in multiple places. What can I do, other than implementing my own interceptor and passing through?
Relevant Threads:
Help Migrating mixins from Castle.DynamicProxy to DynamicProxy2.
Windsor MixIn is a Singleton?
Better Example (wall of code)
public interface IIceCream {
void Eat();
}
public class IceCream : IIceCream {
public void Eat() { Console.WriteLine("Yummy!"); }
}
public interface ICake {
void NomNom();
}
public class Cake : ICake {
public void NomNom() { Console.WriteLine("Cakey!"); }
}
public interface ISprinkles {
void Oogle();
}
public class Sprinkles : ISprinkles {
public void Oogle(){ Console.WriteLine("Its Pretty!");}
}
public interface IIceCreamWithCakeAndSprinkles : IIceCream, ICake, ISprinkles {}
public class Program
{
public static void Main()
{
var gen = new ProxyGenerator();
var options = new ProxyGenerationOptions();
options.AddMixinInstance(new IceCream());
options.AddMixinInstance(new Cake());
options.AddMixinInstance(new Sprinkles());
var result =
gen.CreateClassProxy(typeof (object), new[] {typeof (IIceCreamWithCakeAndSprinkles)}, options) as IIceCreamWithCakeAndSprinkles;
}
}
throws
InvalidMixinConfigurationException: "The mixin IceCream adds the interface 'ConsoleApplication1.IIceCream' to the generated proxy, but the interface already exists in the proxy's additional interfaces. A mixin cannot add an interface already implemented in another way."
Update to Dynamic Proxy 2.2 or 2.5 It is more permissive and it will let the mixin own the interface and ignore that it was passed again as "additional interface".

Resources