0

I was trying this last night in various combinations. To my sane mind, this should work perfectly reasonably:

var aTest: Array<AnyObject.Type> = [MyObject.Type]

As should this:

var myTest: AnyObject.Type = MyObject.Type

As for that second example, which is a little simpler, I first get the error:

Expected member name or constructor after type name

And the suggestion to change it to:

var myTest: AnyObject.Type = MyObject.Type()

Which then simply gives the dead-end error of:

'MyObject.Type' is not constructible with '()'

My MyObject is simply set up like so:

class MyObject {

}

My goal is to subclass MyObject into various different subclasses, all which will be contained within an array, so I could access their class methods and then create an instance of any of them when I choose to.

1
  • p.s. AnyObject.Type is better known as AnyClass Commented Sep 18, 2014 at 23:30

1 Answer 1

3

It seems the solution was to do this:

var myTest: AnyObject.Type = MyObject.self

And this:

var aTest: Array<AnyObject.Type> = [MyObject.self]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.