Hello World (1st Version) Mac OS

To do this from a shell on Solaris, Linux, or Mac OS X, find the process, and kill it. The server will continue to wait for invocations until it is explicitly stopped. Running the Hello World Application on Two Machines describes one way of distributing the simple application across two machines - a client and a server. Aug 26, 2020 You can use the default application name, hello-world, as your package name. Then it asks for the version. To use v1.0.0, which comes as default, press ENTER. After that, it asks for a description.

This page tells you how to setup a Python programming environment for your Mac OS X computer and provides a step-by-step guide for creating and running a simple 'Hello, world' Python program. All of the software is freely available on the Web. These instructions are for MacOS X 10.13 (High Sierra), but the instructions for other versions of Mac OS X are similar.


Overview

The Python programming environment required by this booksite consists of:

  • Python, that is, the Python compiler/interpreter.
  • The Python standard libraries.
  • IDLE, the Python Integrated DeveLopment Environment.
  • The Tkinter, NumPy, and Pygame libraries, which are used by the booksite programs that do graphics or audio processing.
  • The booksite library, that is, a set of modules that we developed specifically to support this booksite.
  • The Terminal application that is bundled with Mac OS X.

Downloading and Installing Python, IDLE, Tkinter, NumPy, and Pygame

A version of Python 2 is bundled with Mac OS X. It's fine to use that version. IDLE, Tkinter, and NumPy are part of that version, but you must download and install Pygame yourself.

Perform these steps to download and install Pygame:

  • Open a Terminal window. To do that, click on the Spotlight Search icon on the right end of the menu bar. (It has the appearance of a magnifying glass.) In the resulting dialog box, type Terminal.app followed by the Enter key.

  • In the Terminal window issue these commands to install pip, the Python package manager. Enter your computer's administrator password when prompted:

  • In the Terminal window issue this command to use pip to install Pygame:

Perform these steps to test your environment:

  • In the Terminal window issue the python command. You should see something like this:

  • If you see that output, then your Python compiler/interpreter is working, and Tkinter, numpy, and IDLE are available.

  • At the Python >>> prompt, type the statement import pygame followed by the Enter key. If Python generates no error messages, then you have installed Pygame properly.

  • At the Python >>> prompt, type exit() followed by the Enter key to exit Python.

  • Close the Terminal window.


Hello World (1st Version) Mac OS

Downloading and Installing the Booksite Library

Perform these steps to download and install the booksite library:

  • Use your Web browser to download this introcs-1.0.zip file to your /Users/yourusername/Downloads directory.


  • Note: The Mac Finder application uses the term folder to mean a container of documents and, perhaps, other folders. This document instead uses the equivalent Unix term directory.
  • In the Finder, double click on the /Users/yourusername/Downloads/introcs-1.0.zip file to unzip the file, thus creating a directory named /Users/yourusername/Downloads/introcs-1.0.

  • Open a Terminal window.

  • At any time the Terminal application has a working directory. Initially the working directory is /Users/yourusername. In the Terminal window issue the cd Downloads command to change your working directory to /Users/yourusername/Downloads, and then issue the cd introcs-1.0 command to change your working directory to /Users/yourusername/Downloads/introcs-1.0. (Incidentally, the cd .. command changes your working directory to the 'parent' of the current working directory.)

  • Issue the ls command to display the names of all files in your working directory. Make sure that a file named setup.py is in your working directory.

  • Issue the python setup.py install --user command. The computer copies the files defining the booksite modules to a directory where Python can find them, and writes status messages to your Terminal window to indicate its progress.

Perform these steps to test your installation of the booksite library:

  • In the Terminal window issue the python command.

  • At the Python >>> prompt, type the statement import stdio followed by the Enter key. If Python generates no error messages, then you have installed the booksite library properly.

  • At the Python >>> prompt, type exit() followed by the Enter key to exit Python.

  • Close the Terminal window.


Configuring IDLE

So far you've downloaded and installed all of the software that you'll need. You should perform one more step before creating your first program: configure the IDLE programming environment. Follow these instructions:

  • Open a Terminal window.

  • In the Terminal window issue the command idle to launch IDLE.

  • Click on the Python → Preferences... menu item.

  • Click on the General tab.

  • Click on the Open Edit Window radio button.

  • Click on the Ok button.

  • Close the IDLE window.

  • Close the Terminal window.


Composing Your First Program

Having installed Python, the Python standard libraries, IDLE, Tkinter, NumPy, Pygame, and the booksite libraries, and having configured IDLE, you are ready to compose your first Python program. Perform these instructions:

  • Using the Finder, create a directory named /Users/yourusername/hello.

  • Open a Terminal window.

  • Issue the cd hello command to make the /Users/yourusername/hello directory your working directory.

  • Issue the command idle & to launch IDLE. Note the trailing ampersand. The trailing ampersand tells the computer to run the idleX program in the background, thereby leaving your Terminal application free to handle additional commands while IDLE is running.

  • In IDLE, type the four-line Python program helloworld.py exactly as it appears below. Use the arrow keys, mouse, or touchpad to move within the text that you have typed. Use the Delete key to delete text. Be careful; the smallest typing mistake might cause the program to fail.

  • When you are finished typing, in IDLE click on the File → Save... menu item to save the Python program. Save it in a file named helloworld.py in the directory /Users/yourusername/hello. The file name is case sensitive, so make sure you use all lowercase letters.


Running Your First Program

The final step is to run your program. It is possible to run some Python programs from within IDLE, but you should run the programs associated with this booksite directly from a Terminal window. To do that, perform these steps:

  • Within the same Terminal window, issue the ls command to display the names of all files in the working directory. Confirm that the working directory contains your helloworld.pyfile.

  • Issue the python helloworld.py command to run your program. If the computer writes 'Hello, World' to the Terminal window, then the execution of your helloworld.py program was successful. If the computer instead writes error messages, then use IDLE to correct your program, and issue the python helloworld.py command again. Repeat until your program runs successfully. If your program runs successfully the first time you try, then intentionally introduce an error into your program, just so you get some experience with correcting errors.

  • Close the IDLE window.

  • Close the Terminal window.

You now have installed and configured a reasonable Python environment, and have used it to compose and run a Python program. Congratulations! You are a Python programmer!


Downloading the Booksite Example Programs (optional)

We recommend that you download the booksite example programs, that is, the example Python programs that are presented incrementally throughout the booksite. Having done so, you can run those programs to help you learn about them. Perform these instructions:

  • Use your Web browser to download this introcs-python.zip file to your /Users/yourusername/Downloads directory.

  • In the Finder, double-click on the /Users/yourusername/Downloads/introcs-python.zip file, thus creating the /Users/yourusername/Downloads/introcs-python directory containing the booksite example programs. (It's OK to delete the /Users/yourusername/Downloads/introcs-python.zip file after you have unzipped it.)

Then perform these steps to test your download of the booksite example programs:

  • Open a Terminal window.

  • Issue the cd Downloads and cd introcs-python commands to make /Users/yourusername/Downloads/introcs-python your working directory.

  • Issue the ls command. Confirm that the working directory contains a file named bouncingball.py.

  • Issue the python bouncingball.py command. If Python launches a stddraw window showing an animated bouncing ball, then your download of the booksite example programs was successful.

  • Close the stddraw window.

  • Close the Terminal window.


Downloading the Booksite Example Data (optional)

We recommend that you download the booksite example data, that is, the data files used by the booksite example programs that are presented incrementally throughout the booksite. Perform these instructions:

  • Use your Web browser to download this introcs-data.zip file to your /Users/yourusername/Downloads directory.

  • In the Finder, double-click on the /Users/yourusername/Downloads/introcs-data.zip file, thus creating the /Users/yourusername/Downloads/introcs-data directory containing the booksite example data files. (It's OK to delete the /Users/yourusername/Downloads/introcs-data.zip file after you have unzipped it.)


Downloading the Booksite Library: Part 2 (optional)

Previously on this page we described how to download and install the booksite library so Python can find it. Now we describe how to download the booksite library so you can find it — for the sake of studying the code that implements it, should you so desire. Perform these instructions:

  • Use your Web browser to download this stdlib-python.zip file to your /Users/yourusername/Downloads directory.

  • In the Finder, double-click on the /Users/yourusername/Downloads/stdlib-python.zip file, thus creating the /Users/yourusername/Downloads/stdlib-python directory containing the booksite library. (It's OK to delete the /Users/yourusername/Downloads/stdlib-python.zip file after you have unzipped it.)

We invite you to study the code that implements the booksite library. But don't be concerned if some of the code is cryptic. The code that implements the booksite library uses some features of Python that are beyond the scope of the textbook and this booksite.


Q & A

Q. Why do I get the error ImportError: No module named stddraw when I issue the command python program_that_uses_stddraw.py?

A. You must issue the command python2.7 program_that_uses_stddraw.py, as described above.

Q. I downloaded files using my browser, but can't find them. Where are they?

A. Many browsers by default place downloaded files in the directory /Users/yourusername/Downloads.

Q. How do I break out of an infinite loop when running my program from the Terminal application?

A. Type Ctrl-c. That is, while pressing the Ctrl key, type the c key.

Q. Must I use IDLE to create my Python programs? Can I use some other text editor?

A. You need not use IDLE to create your Python programs; it is fine to use some other text editor. For example, it is reasonable to use the TextEdit editor that is bundled with Mac OS X. However if you do use some other text editor, then make sure you change its settings so it (1) uses a four-space indentation scheme, and (2) indents using spaces instead of tabs. The Wikipedia Comparison of text editors page provides summary descriptions of many text editors.

-->

Warning

The iOS Designer was deprecated in Visual Studio 2019 version 16.8 and Visual Studio 2019 for Mac version 8.8, andremoved in Visual Studio 2019 version 16.9 and Visual Studio for Mac version 8.9.The recommended way to build iOS user interfaces is directly on a Mac running Xcode's Interface Builder. For more information, see Designing user interfaces with Xcode.

This guide describes how to create an application that translates an alphanumeric phone number entered by the user into a numeric phone number, and then calls that number. The final application looks like this:

Requirements

iOS development with Xamarin requires:

  • A Mac running macOS High Sierra (10.13) or above.
  • Latest version of Xcode and iOS SDK installed from the App Store .

Xamarin.iOS works with the following setup:

  • Latest version of Visual Studio for Mac that fits the above specifications.

The Xamarin.iOS Mac Installation guide is available for step-by-step installation instructions

Xamarin.iOS works with the following setup:

Hello World (1st Version) Mac Os Download

  • Latest version of Visual Studio 2019 or Visual Studio 2017 Community, Professional, or Enterprise on Windows 10, paired with a Mac build host that fits the above specifications.

The Xamarin.iOS Windows Installation guide is available for step-by-step installation instructions.

Before getting started, download the Xamarin App Icons set.

Visual Studio for Mac Walkthrough

This walkthrough describes how to create an application called Phoneword that translates an alphanumeric phone number into a numeric phone number.

  1. Launch Visual Studio for Mac from the Applications folder or Spotlight:

    On the Launch Screen, click New Project... to create a new Xamarin.iOS solution:

  2. From the New Solution dialog, choose the iOS > App > Single View Application template, ensuring that C# is selected. Click Next:

  3. Configure the app. Give it the NamePhoneword_iOS, and leave everything else as default. Click Next:

  4. Leave the Project and Solution Name as is. Choose the location of the project here, or keep it as the default:

  5. Click Create to make the Solution.

  6. Open the Main.storyboard file by double-clicking on it in the Solution Pad. Ensure you open the file using the Visual Studio iOS Designer (right click the storyboard and select Open With > iOS Designer). This provides a way to visually to create a UI:

    Note that size classes are enabled by default. Refer to the Unified Storyboards guide to learn more about them.

  7. In the Toolbox Pad, type 'label' into the search bar and drag a Label onto the design surface (the area in the center):

    Note

    You can bring up the Properties Pad or Toolbox at any time by navigating to View > Pads.

  8. Grab the handles of the Dragging Controls (the circles around the control) and make the label wider:

  9. With the Label selected on the design surface, use the Properties Pad to change the Text property of the Label to 'Enter a Phoneword:'

  10. Search for “text field” inside the Toolbox and drag a Text Field from the Toolbox onto the design surface and place it under the Label. Adjust the width until the Text Field is the same width as the Label:

  11. With the Text Field selected on the design surface, change the Text Field’s Name property in the Identity section of the Properties Pad to PhoneNumberText, and change the Text property to '1-855-XAMARIN':

  12. Drag a Button from the Toolbox onto the design surface and place it under the Text Field. Adjust the width so the Button is as wide as the Text Field and Label:

  13. With the Button selected on the design surface, change the Name property in the Identity section of the Properties Pad to TranslateButton. Change the Title property to 'Translate':

  14. Repeat the two steps above and drag a Button from the Toolbox onto the design surface and place it under the first Button. Adjust the width so the Button is as wide as the first Button:

  15. With the second Button selected on the design surface, change the Name property in the Identity section of the Properties Pad to CallButton. Change the Title property to 'Call':

    Save the changes by navigating to File > Save or by pressing ⌘ + s.

  16. Some logic needs to be added to the app to translate phone numbers from alphanumeric to numeric. Add a new file to the Project by right clicking on the Phoneword_iOS Project in the Solution Pad and choosing Add > New File... or pressing ⌘ + n:

  17. In the New File dialog, select General > Empty Class and name the new file PhoneTranslator:

  18. This creates a new, empty C# class for us. Remove all the template code and replace it with the following code:

    Save the PhoneTranslator.cs file and close it.

  19. Add code to wire up the user interface. To do this double-click on ViewController.cs in the Solution Pad to open it:

  20. Begin by wiring up the TranslateButton. In the ViewController class, find the ViewDidLoad method and add the following code beneath the base.ViewDidLoad() call:

    Include using Phoneword_iOS; if the file's namespace is different.

  21. Add code to respond to the user pressing the second button,which is named CallButton. Place the following code below thecode for the TranslateButton and add using Foundation;to the top of the file:

  22. Save the changes and then build the application by choosing Build > Build All or pressing ⌘ + B. If the application compiles, a success message will appear at the top of the IDE:

    If there are errors, go through the previous steps and correct any mistakes until the application builds successfully.

  23. Finally, test the application in the iOS Simulator. In the top left of the IDE, choose Debug from the first dropdown, and iPhone XR iOS 12.0 (or other available simulator) from the second dropdown, and press Start (the triangular button that resembles a Play button):

    Note

    At present, due to a requirement from Apple, it may be necessary to have a development certificate or signing identity to build you code for device or simulator. Follow the steps in the Device Provisioning guide to set this up.

  24. This will launch the application inside the iOS Simulator:

    Phone calls are not supported in the iOS Simulator; instead, you will see an alert dialog when trying to place a call:

Visual Studio Walkthrough

This walkthrough describes how to create an application called Phoneword that translates an alphanumeric phone number into a numeric phone number.

Note

Hello World (1st Version) Mac Os Catalina

This walkthrough uses Visual Studio Enterprise 2017 on a Windows 10 Virtual Machine. Your set up can differ from this, as long as it meets the requirements above, but be aware that some screenshots may look different to your set up.

Note

Before proceeding with this walkthrough, you must have already connected to your Mac from Visual Studio. This is because Xamarin.iOS relies on Apple's tooling to build and launch applications. To get set up, follow the steps in the Pair to Mac guide.

  1. Launch Visual Studio from the Start menu:

    Create a new Xamarin.iOS solution by selecting File > New > Project... > Visual C# > iPhone & iPad > iOS App (Xamarin):

    In the next dialog that appears, select the Single View App template and press OK to create the project:

  2. Confirm that the Xamarin Mac Agent icon in the toolbar is green.

    If it isn't, this means that there is no connection to your Mac build host, follow the steps in the configuration guide to get connected.

  3. Open the Main.storyboard file in the iOS Designer by double-clicking on it in the Solution Explorer:

  4. Open the Toolbox tab, type “label” into the search bar and drag a Label onto the design surface (the area in the center):

  5. Next, grab the handles of the Dragging Controls and make the label wider:

  6. With the Label selected on the design surface, use the Properties Windows to change the Text property of the Label to 'Enter a Phoneword:'

    Note

    You can bring up the Properties or Toolbox at any time by navigating to the View menu.

  7. Search for “text field” inside the Toolbox and drag a Text Field from the Toolbox onto the design surface and place it under the Label. Adjust the width until the Text Field is the same width as the Label:

  8. With the Text Field selected on the design surface, change the Text Field’s Name property in the Identity section of the Properties to PhoneNumberText, and change the Text property to '1-855-XAMARIN':

  9. Drag a Button from the Toolbox onto the design surface and place it under the Text Field. Adjust the width so the Button is as wide as the Text Field and Label:

  10. With the Button selected on the design surface, change the Name property in the Identity section of the Properties to TranslateButton. Change the Title property to 'Translate':

  11. Repeat the previous two steps and drag a Button from the Toolbox onto the design surface and place it under the first Button. Adjust the width so the Button is as wide as the first Button:

  12. With the second Button selected on the design surface, change the Name property in the Identity section of the Properties to CallButton. Change the Title property to 'Call':

    Save the changes by navigating to File > Save All or by pressing Ctrl + s.

  13. Add some code to translate phone numbers from alphanumeric to numeric. To do this, first add a new file to the Project by right-clicking on the Phoneword Project in the Solution Explorer and choosing Add > New Item... or pressing Ctrl + Shift + A:

  14. In the Add New Item dialog (right click on the project, choose Add > New Item...), select Apple > Class and name the new file PhoneTranslator:

    Important

    Make sure that you select the 'class' template that has a C# in the icon. Otherwise you may not be able to reference this new class.

  15. This creates a new C# class. Remove all the template code and replace it with the following code:

    Save the PhoneTranslator.cs file and close it.

  16. Double-click on ViewController.cs in the Solution Explorer to open it, so that logic can be added to handles interactions with the buttons:

  17. Begin by wiring up the TranslateButton. In the ViewController class, find the ViewDidLoad method. Add the following button code inside ViewDidLoad, beneath the base.ViewDidLoad() call:

    Include using Phoneword; if the file's namespace is different.

  18. Add code to respond to the user pressing the second button,which is named CallButton. Place the following code below thecode for the TranslateButton and add using Foundation;to the top of the file:

  19. Save the changes, and then build the application by choosing Build > Build Solution or pressing Ctrl + Shift + B. If the application compiles, a success message will appear at the bottom of the IDE:

    If there are errors, go through the previous steps and correct any mistakes until the application builds successfully.

  20. Finally, test the application in the Remoted iOS Simulator. In the IDE toolbar, choose Debug and iPhone 8 Plus iOS x.x from the drop down menus, and press Start (the green triangle that resembles a Play button):

  21. This will launch the application inside the iOS Simulator:

    Phone calls are not supported in the iOS Simulator; instead, an alert dialog will display when trying to place a call:

Os Version 10

Congratulations on completing your first Xamarin.iOS application!

Hello World (1st Version) Mac Os Pro

Now it’s time to dissect the tools and skills shown in this guide in the Hello, iOS Deep Dive.

Hello World (1st Version) Mac Os Catalina

Related Links