Xojo to Swift cheat sheet?

Has anyone already created a Xojo to Swift cheat sheet? If not then I‘ll make one (my memory is too bad to remember everything after reading it once) …

dave probably has a crib sheet he used way back when

There may be things that dont have a direct line by line equivalence and you need to convert whole blocks of code and their overall meaning rather than just single lines

I’m finding much the same with a VB6 to Xojo conversion where you get chunks of code in VB that turn into a slightly different chunk in Xojo. Or one liners in VB that turn into chunks of code in Xojo. And vice versa where a chunk of code in VB is a one liner in Xojo

Both Xojo and Swift are too complex in their own rights to be able to create a single document that could be a “cheat sheet”. What I have been doing over that past few years is writing libraries in Swift that duplicate/replicate many common functions using syntax that looks like Xojo, but compiles to Swift. On this forum I have already posted 11 of these, and each one that I posted are in active use within Swift projects that I am developing. But like Norm mentioned… some is one to one or one to a few lines of code, but some are not.

These two seem quite nice:

1 Like

nether of which is an “Xojo to Swift” cheatsheet… but both are a nice Swift specific reference

THAT I’m still working on … :wink:

THAT is why I have thousands of lines of custom code to encapsulate exactly that information… its NOT going to be a one to one translations… especially if you have the “new” version encapsuluate error checking etc… but I would be interested to see what you come up with,

As it is intended to make it easier for beginners to move to Swift it is more along the lines of

Fundamental differences: eg everything is an object type (class, struct, enum), there are no scalars in Swift

Syntax:

dim becomes var
const becomes let
as becomes :

etc with examples for each

array, dict, function declarations, underscore, named and unnamed parameters I have so far

In part it already helps me as I work my way through Matt Neuburg‘s books (remember: bad memory! “Why was that again?”), and I hope it might prove useful for others too if they start out in Swift.

Not everything will be direct translations, but in my experience the best way of teaching is building on what people already know.

An example of what I mean by “building on what people already know” (a little excerpt from the introduction of a book I’m working on):

Many people, even highly intelligent professors, do not understand Evolution and get it horribly - and embarrassingly - wrong. But you don’t need to go to University to understand how Evolution works. You don’t even need to do your A levels or an advanced class at school. We can do it right here in the introduction - all you need are a few dice and two minutes. It is really that simple. You don’t believe it? Let’s try it:

Imagine you have ten dice. Throw them until you have ten sixes.

How long will that take? Now with ten dice there are 6x6x6x6x6x6x6x6x6x6 = 610 = 60,466,176 different possibilities, so the probability of getting ten sixes is pretty low. You might be incredibly lucky and throw ten sixes on your first try, but it is more likely that it will take a really long time.

Now let’s try it in an evolutionary way:
Imagine you have ten dice. Throw them in an evolutionary way until you have ten sixes.

Stop! What is an evolutionary way? Glad you asked. Evolution has two parts: One is Variation, e.g. the throwing of the dice. And the other is Selection - in this case we want the sixes, so we select the sixes. They “survive”. All the other dice are thrown again (Variation). The sixes survive again (Selection) and join the “survivors” from the first round. The other dice - the “non-sixes” - are thrown again … and so on.

How long will it take you now to get ten sixes? Nobody will be able to tell - after all there is an element of chance in throwing the dice, and you might have to throw that last one quite often before you get that tenth six. But in all likelihood it will be a LOT less time than by chance alone.

So there you have it. Evolution is the combination of chance and selection that over time leads to change (with the change over time being how many sixes you have after x throws). Evolution isn’t a fixed law as there is an element of chance involved, but you can call it a principle.

Note that not every change over time is Evolution. If you grow up then you change over time too - but that is development, not Evolution! Because in development there is no Selection involved, and without Selection it is not Evolution. It is really embarrassing to hear some American Scientists talk about “Evolution” when they should say “development”.

And while you might not know yet how Evolution works in detail, you already understand what Evolution is better than some of these very clever people :wink:

The one that really bothers me is how people anthropomorphize things like viruses & bacteria. You hear people say all the time “The virus WANTS to…” or something equivalent. As if the virus is consciously willing itself to do something or take some action when that is nowhere near the truth.

The virus DOES what it does but its not as if its actively seeking out humans, infects them and then things to itself “ooh now I’m inside I should so to that cell, take over its internal machinery and reproduce”.

That just IS how it works and IS what it does.

</rant off>

Wrong thread Norman?

Well, it is difficult to conceptualize that a virus is just a little primitive machine, basically some genetic instructions that evolved into spreading themselves rapidly without any other purpose than spreading. It contradicts what our brain is for: to explain the World to us, to find reason.

I highly recommend the book „The man who mistook his wife for his hat“ by Oliver Sacks. It‘s a collection of short clinical case descriptions written for laymen, in which he shows the effects of what happens if certain functions do not work as expected (eg memory that only lasts a few minutes, a woman who does not know left, people who have gone blind but do not know they are blind, „living lie detectors“ that can’t be fooled unlike normal people that are easily fooled, etc) or go into overdrive.

But yes, humans have not moved on much from telling fairy tales and fables to convey more complex moral behaviors.

No such thing, and it won‘t get locked here, it just goes back to it‘s original purpose in good time :hugs:

replying to Markus post