Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode playground not executing functions

I created a new playground and I add simple function but the function is never been call:

var str = "New playground"

func hello()
{
    print("Hello, World")
}

enter image description here

Any of you knows why the function is not been call ?

I'll really appreciate your help

like image 968
user2924482 Avatar asked Oct 27 '15 21:10

user2924482


People also ask

How do I run code in Xcode playground?

In the Swift Playgrounds app on your Mac, click Run My Code (or use the Touch Bar). If there are instructions on the right side of the screen, they slide down when you click Run My Code, so you can watch your code run in the live view. When you click Stop, the instructions slide back up.

What is the difference between playground and Xcode?

An Xcode project allows you to create real apps that you could eventually upload to the App Store (providing you became an Apple Developer). An Xcode Playground allows you to play with code and test it out.

Does Xcode still have playground?

You can use playgrounds in Xcode to quickly write some Swift code, experiment with new Swift syntax, or work on your Swift algorithms skills. Most of all, playgrounds in Xcode are a great way to learn Swift programming. In this tutorial, you'll learn how to get started with playgrounds in Xcode.

What is the difference between Swift playground and Xcode?

One of the biggest differences between Swift Playgrounds and Xcode Playgrounds is that Swift Playgrounds are much less powerful and are built more as an educational tool. My biggest fear is that as Apple brings Swift Playgrounds to the Mac that they will stop supporting and growing Xcode Playgrounds.


1 Answers

Because you didn't call the function. Just call it:

func hello()
{
    print("Hello, World")
}

hello()
like image 175
Arsen Avatar answered Oct 12 '22 13:10

Arsen