Swift Type(of:) function no worky

Good afternoon,
Continuing my journey of the Swift programming language. Supposedly it’s very Swifty to divide a function name among argument labels. One example is typeOf in C# vs type(of:) in Swift. Unfortunately, Fire returned an error: Unknown identifier. Thanks for taking a look :slight_smile:

Hmm, that’s new? last I recall “.Self” was the equivalent of typeOf()

I’ll log an issue to have this added, compiler side.

Thanks, logged as bugs://85902

Thanks for checking on it Marc. I think it’s interesting how Swift promotes dividing the function name with parameter names such as:

show(message: ) 

Another example from Simon Allardice, a very good lecturer on Pluralsight:

You got me looking up .self vs type(of:) … what a metatype rabbit hole :D. In short, type(of:) Dynamic Metatypes vs .self Static Metatypes.

Fixed for Fridays build, and in GitHub.

yeah,. its (IMHO) a bastardiez version of Ovjective-Cs='s very nice and descriptive multi-part selector/method names

yeah. it still confuses me every time, too :wink:

1 Like

just a quick heads up … it appears ‘type(of:)’ is still generating an ‘Unknown identifier’ error with the latest build .2629 :thinking:

My apologies; it looks like i forgot to merge. Done for next week, or you can grab SBL from GitHub yourself: GitHub - remobjects/SwiftBaseLibrary.


1 Like

Just a quick note to say that type(of:) works now with the latest version of Fire. :fist_right: :fist_left:

As a side note, looking forward to your Webassembly webinar with Jim McKeeth next week. I’d have to agree with the ‘other’ Hoffman (Kevin) that Webassembly’ is such a misnomer. :nerd_face:

I may have spoken too soon. :expressionless: It appears Elements’ type(of:) lacks the specificity of Swift in distinguishing an int vs double datatype. Also, Elements returns a (null) for a String datatype. :no_mouth: Happy Monday! :nerd_face:

Ah yes, the Int/Doubke make sense, as these get boxed tote passed to the function :(. we might need to move this into he compiler, after all. The String issue is a stranger…

The variance never read warnings seem wrong too…

1 Like

Thanks, logged as bugs://85967

Curious. This works:

~> Process ConsoleApplication167 started, took 0.213.
~> Process ConsoleApplication167 terminated with exit code 0. Ran for 1.964


import Foundation;
do {
    let sv : String = "";
    print(type(of: sv));

can I get the full sample?

bugs://85902 got closed with status duplicate.

Hi Carlo,

I confirm that the above code works here as well. Here’s an iCloud link to my file. Let me know if the link works. Cheers.

Swift Type(of:) File

Here’s an alternate Dropbox link:

bugs://85967 got closed with status fixed.

1 Like

Thank you for the latest build y’all :slight_smile:

@ck, I noticed that your code is wrapped in a do statement - mine was not. Once I wrapped my code in a do statement, it functioned properly in the latest Fire release .2633.

The optional Swift do statement appears to be the equivalent of non-optional braces in C languages as well as Begin, End in the Pascal languages, so it’s understandable that the do statement may be necessary for compatibility reasons - Elements being the ‘polyglot’ compiler par excellence. :nerd_face::+1:

Fridays build should also support your testcase

1 Like