Questions tagged [metatype]

A metatype type refers to the type of any type, including class types, structure types, enumeration types, and protocol types.

Filter by
Sorted by
Tagged with
0 votes
1 answer
104 views

TypeScript convert tuple type with nullable type to tuple with non-nullable type

I am going to function to memoize return values from the function given. const memoize = (value, onHandle) => { for (let index = 0; index < value.length; index++) { if (value[index] === ...
QuavoHuncho's user avatar
0 votes
2 answers
693 views

How to use types as values in Rust? / Metatypes

I’m working on the database component of my app. The idea is to describe objects using a Record structure which stores an identifier for fetching the object, and also specifies the object type. struct ...
Yakov Manshin's user avatar
0 votes
1 answer
166 views

Migrating Apache Felix SCR to OSGI Declarative Services

I'm Migrating from Apache Felix SCR Annotations to OSGI Declarative Services and here is my Problem. Before I had: SCR annotation Implementation @Component (ds = true, immediate = true, metatype = ...
Kamalraj's user avatar
1 vote
0 answers
49 views

What is the fundamental difference between SomeProtocol.Protocol and SomeProtocol.Type?

By chance, I observed some differences in behaviour between the types SomeProtocol.Protocol and SomeProtocol.Type (before this, I thought they are the same thing!): public protocol P { } public ...
Sweeper's user avatar
  • 224k
0 votes
2 answers
59 views

Using metatype in closure

Is it possible to use metatype in closures? The simplest example I came up with does not work let type = String.self let closure = { () -> type in return type.init() } Compiler complains at ...
Simon Moshenko's user avatar
3 votes
0 answers
163 views

Behavior of Swift Any.Type and generics

Given a function with a generic parameter, I would like to pass a value of which type is Any.Type to the function but it doesn't compile. func foo<T>(_ type: T.Type) { print(type) } foo(...
Yonguk Jeong's user avatar
2 votes
0 answers
42 views

How to provide a default value for a metatype parameter in a Swift function? [duplicate]

In my app, I often need to access values stored in Info.plist. Instead of typing things like Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String every time, I created a nice wrapper. ...
Yakov Manshin's user avatar
1 vote
1 answer
269 views

Create class instances from an array of metatypes

Let's suppose I do have a protocol TestProtocol and classes TestClass1 and TestClass2 conforming to TestProtocol: protocol TestProtocol: AnyObject { } class TestClass1: TestProtocol { } class ...
Wizard's user avatar
  • 295
7 votes
1 answer
164 views

What is the best way in Swift 4+ to store a set of homogenous arrays for various types in a dictionary?

Consider a situation where we want to have a dictionary of arrays, with each array being a homogeneous collection of values of some type (which may be a struct or a primitive type). I'm currently ...
Fooberman's user avatar
  • 626
11 votes
2 answers
333 views

Can I get the Owning Object of a Member Function Template Parameter?

Given a object: struct foo { void func(); }; Now given the templatized function declaration: template<typename T, T F> void bar(); So bar will be taking in a member function like so: ...
Jonathan Mee's user avatar
  • 38.1k
0 votes
2 answers
68 views

Different behavior between T.Type & [T.Type]

I am using generics func to improve tableView cells as below; public func registerNib<T: UITableViewCell>(_:T.Type) { print("Registering.....") print(T.self) let nib = UINib(nibName:...
Göktuğ Aral's user avatar
2 votes
1 answer
607 views

Why can't I use a Metatype as a property on a struct in swift?

So I was wondering my playground crashes when I try to instantiate a struct with a Metatype as a property type but not when I do the same with a class. Struct Version: struct Dog { static func ...
Joe Susnick's user avatar
  • 6,604
5 votes
3 answers
2k views

Check if a given metatype is an enum

Given the method func enumCaseCount<T: Hashable>(ofType type: T.Type) -> Int { // Needed check if type is an enum type return 3 } Used as follows private enum SimpleEnum: String { ...
Binarian's user avatar
  • 12.3k
0 votes
1 answer
101 views

Karaf OSGI How to copy files as part of postProcessing?

I have some files that I need to copy to a directory configured in the .cfg file as part of installing the bundle in Karaf server. I couldn't figure out what exactly is the js method to invoke. Below ...
Maria's user avatar
  • 1,161
1 vote
1 answer
190 views

Getting Type identity of Swift type by name

I'm trying to use a type identity as a key in a dictionary, but I'm having trouble writing the declaration. In C#, I would use something like this: Type theType = typeof(MyCoolClass); It seems like ...
Ana Betts's user avatar
  • 74k
0 votes
1 answer
473 views

Accessing Class var on AnyClass variable in Swift 4

In Swift 3.2 this (let id = row.tableViewCellClass?.reuseIdentifier) worked: class DrillDownTableViewCell { class var reuseIdentifier: String { return String(describing: self) } } ...
Mason11987's user avatar
5 votes
1 answer
576 views

Swift generic function call underlying method based on generic type

I am writing an interface to Someone Else's Code (SEC), and I have a long list of functions more or less like this: public func readString(_ row: Row, columnName: String) -> String? { return ...
Jerry's user avatar
  • 3,431
2 votes
1 answer
859 views

Pass Metatype as function argument

In Swift I can do the following: struct Employee{ var name:String var age:Int } // Metatype let currentType = Employee.self // concrete instance let instanceFromType = currentType.init(name: ...
user avatar
10 votes
3 answers
3k views

Check whether Swift object is an instance of a given metatype

I need to keep a collection of Swift metatypes and write a function which will check if a given object is an instance of one of them. I can do that easily in Java: Class c = x.getClass(); c....
frangulyan's user avatar
  • 3,630
1 vote
0 answers
608 views

Qt 5.7 - C++ Signal / QML Slot - Custom Meta type wrapped in QVariant

I'm trying to connect a C++ signal to a QML slot. The exchanged data is a constant reference to an object of my own class. Thereby this class is registered to the Qt meta system, before the QML file ...
SimdSeemsSuitable's user avatar
3 votes
1 answer
1k views

Swift 3, is the ".self" in a metatype issue actually correct?

I have an extension to walk up the view controller chain (even through container views, which is very handy) public extension UIViewController // go up to a certain class { public func ...
Fattie's user avatar
  • 20.8k
0 votes
1 answer
150 views

How to implement an OSGI dynamic metatype?

I would customize the OSGI-INF metatype (xml) in order to add attributes dynamically. This is an example of a metatype input: <AD id="Device-Operation" name="Device-Operation" type="...
Andrea Limoli's user avatar
0 votes
1 answer
113 views

Return object with an specific metatype in general metatype function

I have some issues with inheritance and generics classes. I want to return an object of a subclass (with an specific generic type) in a function that return an object of the parent class with a ...
URi's user avatar
  • 67
7 votes
1 answer
2k views

Storing and then casting to Metatypes in Swift [duplicate]

Effectively, I want to have a protocol that will return a Metatype (e.g.: Type.Type), which I can pass to a Class, and then when I need to, cast an object to that MetaType. The reason I'm to cast it ...
chillok's user avatar
  • 235
4 votes
2 answers
2k views

expected constructor, destructor, or type conversion before ';' token (Q_DECLARE_METATYPE_CONTACT)

so i have defined the class with Qt creator (C++11) : #ifndef CONTACT_H #define CONTACT_H #include <QStringList> #include <list> class Contact { public : Contact(); ~Contact(); /...
Mangemouton's user avatar
0 votes
1 answer
106 views

Implementing a registerClass like behavior in Swift using generics

I have a tricky question to figure out. But I'm not able to find out a specific solution for it. Before explaining the goal this is the code I created so far. protocol SomeProtocol { init() ...
Lorenzo B's user avatar
  • 33.3k
4 votes
1 answer
51 views

Swift Metatyping Inconsistency

Given the following code... protocol MyProtocol {} enum MyEnum: MyProtocol {} struct MyStruct: MyProtocol {} class MyClass: MyProtocol {} func MyFunction(parameter: MyProtocol.Type) -> String { ...
72A12F4E's user avatar
  • 1,744
1 vote
1 answer
163 views

OSGI Metatype representing complex configurations

Is there a clean and easy way to model Maps of Maps in OSGI Metatype. I have a fairly complex configuration need for a distributed system and the examples of Metatype I can find do not shed any ...
Hassan Syed's user avatar
  • 20.1k