100% found this document useful (1 vote)
46 views

Beginning Xamarin Development for the Mac: Create iOS, watchOS, and Apple tvOS apps with Xamarin.iOS and Visual Studio for Mac 1st Edition Dawid Borycki All Chapters Instant Download

Borycki

Uploaded by

muhalaintani83
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
46 views

Beginning Xamarin Development for the Mac: Create iOS, watchOS, and Apple tvOS apps with Xamarin.iOS and Visual Studio for Mac 1st Edition Dawid Borycki All Chapters Instant Download

Borycki

Uploaded by

muhalaintani83
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 55

Experience Seamless Full Ebook Downloads for Every Genre at textbookfull.

com

Beginning Xamarin Development for the Mac: Create


iOS, watchOS, and Apple tvOS apps with Xamarin.iOS
and Visual Studio for Mac 1st Edition Dawid
Borycki
https://textbookfull.com/product/beginning-xamarin-
development-for-the-mac-create-ios-watchos-and-apple-tvos-
apps-with-xamarin-ios-and-visual-studio-for-mac-1st-edition-
dawid-borycki/

OR CLICK BUTTON

DOWNLOAD NOW

Explore and download more ebook at https://textbookfull.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

Beginning Visual Studio for Mac: Build Cross-Platform Apps


with Xamarin and .NET Core Alessandro Del Sole

https://textbookfull.com/product/beginning-visual-studio-for-mac-
build-cross-platform-apps-with-xamarin-and-net-core-alessandro-del-
sole/
textboxfull.com

Biota Grow 2C gather 2C cook Loucas

https://textbookfull.com/product/biota-grow-2c-gather-2c-cook-loucas/

textboxfull.com

Build, Run, and Sell Your Apple Consulting Practice:


Business and Marketing for iOS and Mac Start Ups Charles
Edge
https://textbookfull.com/product/build-run-and-sell-your-apple-
consulting-practice-business-and-marketing-for-ios-and-mac-start-ups-
charles-edge/
textboxfull.com

Beginning iOS AR Game Development: Developing Augmented


Reality Apps with Unity and C# 1st Edition Allan Fowler

https://textbookfull.com/product/beginning-ios-ar-game-development-
developing-augmented-reality-apps-with-unity-and-c-1st-edition-allan-
fowler/
textboxfull.com
Visual Studio Extensibility Development: Extending Visual
Studio IDE for Productivity, Quality, Tooling, and
Analysis Rishabh Verma
https://textbookfull.com/product/visual-studio-extensibility-
development-extending-visual-studio-ide-for-productivity-quality-
tooling-and-analysis-rishabh-verma/
textboxfull.com

Machine Learning by Tutorials Beginning Machine Learning


for Apple and iOS First Edition Raywenderlich Tutorial
Team
https://textbookfull.com/product/machine-learning-by-tutorials-
beginning-machine-learning-for-apple-and-ios-first-edition-
raywenderlich-tutorial-team/
textboxfull.com

Beginning Ubuntu for Windows and Mac Users : Start your


Journey into Free and Open Source Software Haines

https://textbookfull.com/product/beginning-ubuntu-for-windows-and-mac-
users-start-your-journey-into-free-and-open-source-software-haines/

textboxfull.com

Beginning Ubuntu for Windows and Mac Users: Start your


Journey into Free and Open Source Software Nathan Haines

https://textbookfull.com/product/beginning-ubuntu-for-windows-and-mac-
users-start-your-journey-into-free-and-open-source-software-nathan-
haines/
textboxfull.com

Beginning Ubuntu for Windows and MAC users: start your


journey into free and open source software Second Edition
Haines
https://textbookfull.com/product/beginning-ubuntu-for-windows-and-mac-
users-start-your-journey-into-free-and-open-source-software-second-
edition-haines/
textboxfull.com
Beginning Xamarin
Development for
the Mac
Create iOS, watchOS, and Apple tvOS apps
with Xamarin.iOS and Visual Studio for Mac

Dawid Borycki
Beginning Xamarin
Development for
the Mac
Create iOS, watchOS, and Apple tvOS apps
with Xamarin.iOS and Visual Studio for Mac

Dawid Borycki
Beginning Xamarin Development for the Mac
Dawid Borycki
Institute of Physical Chemistry,
Polish Academy of Sciences,
Kasprzaka 44/52, Warsaw, 01-224, Poland
ISBN-13 (pbk): 978-1-4842-3131-9 ISBN-13 (electronic): 978-1-4842-3132-6
https://doi.org/10.1007/978-1-4842-3132-6
Library of Congress Control Number: 2017963095
Copyright © 2018 by Dawid Borycki
This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the
material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation,
broadcasting, reproduction on microfilms or in any other physical way, and transmission or information
storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now
known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with
every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an
editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are
not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to
proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of publication,
neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or
omissions that may be made. The publisher makes no warranty, express or implied, with respect to the
material contained herein.
Cover image designed by Freepik
Managing Director: Welmoed Spahr
Editorial Director: Todd Green
Acquisitions Editor: Joan Murray
Development Editor: Laura Berendson
Technical Reviewer: Chaim Krause
Coordinating Editor: Jill Balzano
Copy Editor: April Rondeau
Compositor: SPi Global
Indexer: SPi Global
Artist: SPi Global
Distributed to the book trade worldwide by Springer Science+Business Media New York,
233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505,
e-mail [email protected], or visit www.springeronline.com. Apress Media, LLC is a California
LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc).
SSBM Finance Inc is a Delaware corporation.
For information on translations, please e-mail [email protected], or visit http://www.apress.com/
rights-permissions.
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions
and licenses are also available for most titles. For more information, reference our Print and eBook Bulk
Sales web page at http://www.apress.com/bulk-sales.
Any source code or other supplementary material referenced by the author in this book is available to
readers on GitHub via the book’s product page, located at www.apress.com/9781484231319. For more
detailed information, please visit http://www.apress.com/source-code.
Printed on acid-free paper
This book is dedicated to my wife, Agnieszka, daughter, Susanna, and son, Xavier, with love.
We all have dreams. But in order to make dreams come into reality, it takes an awful
lot of determination, dedication, self-discipline, and effort.

—Jesse Owens
Contents

About the Author����������������������������������������������������������������������������������������������������� ix


About the Technical Reviewer��������������������������������������������������������������������������������� xi
Acknowledgments������������������������������������������������������������������������������������������������� xiii
Introduction�������������������������������������������������������������������������������������������������������������xv


■Chapter 1: Fundamentals�������������������������������������������������������������������������������������� 1
Setting Up the Development Environment����������������������������������������������������������������������� 2
Hello, World! App�������������������������������������������������������������������������������������������������������������� 8
Creating the Project�������������������������������������������������������������������������������������������������������������������������������� 8
Storyboard Designer����������������������������������������������������������������������������������������������������������������������������� 16
User Interface��������������������������������������������������������������������������������������������������������������������������������������� 17
AlertViewController������������������������������������������������������������������������������������������������������������������������������� 20
Actions�������������������������������������������������������������������������������������������������������������������������������������������������� 23
Action Sheet����������������������������������������������������������������������������������������������������������������������������������������� 25

Summary ����������������������������������������������������������������������������������������������������������������������� 26

■Chapter 2: App Structure and Lifecycle��������������������������������������������������������������� 27
An Entry Point����������������������������������������������������������������������������������������������������������������� 27
AppDelegate������������������������������������������������������������������������������������������������������������������� 29
View Lifecycle���������������������������������������������������������������������������������������������������������������� 32
Information Property List������������������������������������������������������������������������������������������������ 34
Entitlements Property List���������������������������������������������������������������������������������������������� 35
Launch Storyboard �������������������������������������������������������������������������������������������������������� 36
Storyboards Under the Hood������������������������������������������������������������������������������������������ 38
Model View Controller���������������������������������������������������������������������������������������������������� 41
v
■ Contents

Persisting Data��������������������������������������������������������������������������������������������������������������� 42
Summary������������������������������������������������������������������������������������������������������������������������ 46

■Chapter 3: Views������������������������������������������������������������������������������������������������� 47
Basic Controls���������������������������������������������������������������������������������������������������������������� 47
Tables����������������������������������������������������������������������������������������������������������������������������� 50
Displaying Items����������������������������������������������������������������������������������������������������������������������������������� 51
Selecting Items������������������������������������������������������������������������������������������������������������������������������������� 55
Deleting Items�������������������������������������������������������������������������������������������������������������������������������������� 57

Web View������������������������������������������������������������������������������������������������������������������������ 61
Google Geocoding API��������������������������������������������������������������������������������������������������������������������������� 64
Invoking JavaScript Functions�������������������������������������������������������������������������������������������������������������� 66

Map View and Geolocation��������������������������������������������������������������������������������������������� 68


Auto-Layout�������������������������������������������������������������������������������������������������������������������� 73
Size Classes������������������������������������������������������������������������������������������������������������������� 77
UI Thread������������������������������������������������������������������������������������������������������������������������ 80
Summary������������������������������������������������������������������������������������������������������������������������ 82

■Chapter 4: Navigation������������������������������������������������������������������������������������������ 83
Tab Bar��������������������������������������������������������������������������������������������������������������������������� 83
Pages���������������������������������������������������������������������������������������������������������������������������������������������������� 90
Navigation Between View Controllers��������������������������������������������������������������������������������������������������� 95
Editing a Segue������������������������������������������������������������������������������������������������������������������������������������� 97
Unwind Segue�������������������������������������������������������������������������������������������������������������������������������������� 98
Preparing for Segues���������������������������������������������������������������������������������������������������������������������������� 99

Summary���������������������������������������������������������������������������������������������������������������������� 100

■Chapter 5: Touch������������������������������������������������������������������������������������������������ 101
Touches and Gesture Recognizers������������������������������������������������������������������������������� 101
Swipe and Long-Press Gesture Recognizers��������������������������������������������������������������� 103
Manipulating Controls with Gestures��������������������������������������������������������������������������� 107

vi
■ Contents

Pan Gesture Recognizer��������������������������������������������������������������������������������������������������������������������� 107


Detecting Gesture Location���������������������������������������������������������������������������������������������������������������� 109
Rotation and Pinch Gesture Recognizers�������������������������������������������������������������������������������������������� 111

Summary���������������������������������������������������������������������������������������������������������������������� 116

■Chapter 6: Unit Testing�������������������������������������������������������������������������������������� 117
Creating a Model to Test����������������������������������������������������������������������������������������������� 119
Implementing Unit Tests����������������������������������������������������������������������������������������������� 120
Running Unit Tests�������������������������������������������������������������������������������������������������������� 126
User Interface Tests������������������������������������������������������������������������������������������������������ 127
Creating an App���������������������������������������������������������������������������������������������������������������������������������� 128
Xamarin Test Cloud Agent������������������������������������������������������������������������������������������������������������������� 128
Creating UI Tests��������������������������������������������������������������������������������������������������������������������������������� 130

Xamarin Test Cloud������������������������������������������������������������������������������������������������������� 135


Provisioning Profile����������������������������������������������������������������������������������������������������������������������������� 136
Running Tests in the XTC�������������������������������������������������������������������������������������������������������������������� 140

Summary���������������������������������������������������������������������������������������������������������������������� 142

■Chapter 7: Consuming RESTful Web Services���������������������������������������������������� 143
REST Service Client������������������������������������������������������������������������������������������������������ 145
Updating Data������������������������������������������������������������������������������������������������������������������������������������� 148
Getting a Specific User����������������������������������������������������������������������������������������������������������������������� 149
Testing the REST Client������������������������������������������������������������������������������������������������ 149
Users Repository���������������������������������������������������������������������������������������������������������� 152
Presenting a List of Users�������������������������������������������������������������������������������������������� 155
Displaying User Details������������������������������������������������������������������������������������������������ 158
Summary���������������������������������������������������������������������������������������������������������������������� 162

■Chapter 8: watchOS������������������������������������������������������������������������������������������� 163
Creating the Project������������������������������������������������������������������������������������������������������ 163
Watch App Bundle�������������������������������������������������������������������������������������������������������� 165
Watch Extension����������������������������������������������������������������������������������������������������������� 166

vii
■ Contents

Hello, Watch!���������������������������������������������������������������������������������������������������������������� 166


Watch Simulator����������������������������������������������������������������������������������������������������������� 169
View Lifecycle�������������������������������������������������������������������������������������������������������������� 171
App Lifecycle���������������������������������������������������������������������������������������������������������������� 173
Text Input���������������������������������������������������������������������������������������������������������������������� 175
Force Touch and Navigation����������������������������������������������������������������������������������������� 177
Notification Controller�������������������������������������������������������������������������������������������������� 181
ClockKit and Complication Controller��������������������������������������������������������������������������� 184
Glance Controller���������������������������������������������������������������������������������������������������������� 189
Summary���������������������������������������������������������������������������������������������������������������������� 191

■Chapter 9: tvOS�������������������������������������������������������������������������������������������������� 193
Creating a Project��������������������������������������������������������������������������������������������������������� 194
User Interface��������������������������������������������������������������������������������������������������������������� 195
OpenWeatherMap API��������������������������������������������������������������������������������������������������� 197
Retrieving the Weather Report������������������������������������������������������������������������������������� 199
Presenting the Weather������������������������������������������������������������������������������������������������ 202
Temperature Units�������������������������������������������������������������������������������������������������������� 205
Testing the App in a Simulator������������������������������������������������������������������������������������� 206
Summary���������������������������������������������������������������������������������������������������������������������� 209

Index��������������������������������������������������������������������������������������������������������������������� 211

viii
About the Author

Dawid Borycki is a software engineer, biomedical researcher, and an


expert in several Microsoft developer technologies. He has resolved a
broad range of software development challenges for device prototypes
(mainly medical equipment), embedded device interfacing, and desktop
and mobile programming. Dawid regularly speaks at international
developers conferences and has published, cited, and presented on
numerous developer topics, including web technologies, mobile/cross-
platform development, wearables, embedded, and more.

ix
About the Technical Reviewer

Chaim Krause is an expert computer programmer with over thirty years


of experience to prove it. He worked as a lead tech support engineer for
ISPs as early as 1995 and as a senior developer support engineer with
Borland for Delphi, and has worked in Silicon Valley for over a decade
in various roles, including technical support engineer and developer
support engineer. He is currently a military simulation specialist for the
US Army’s Command and General Staff College, working on projects such
as developing serious games for use in training exercises. He has also
authored several video training courses on Linux topics and has been
a technical reviewer for over twenty books, including iOS Code Testing,
Android Apps for Absolute Beginners (4th ed.), and XML Essentials for C#
and .NET Development (all Apress). It seems only natural then that he
would be an avid gamer and have his own electronics lab and server room in his basement. He currently
resides in Leavenworth, Kansas, with his loving partner, Ivana, and a menagerie of four-legged companions:
their two dogs, Dasher and Minnie, and their three cats, Pudems, Talyn, and Alaska.

xi
Acknowledgments

Dear reader, you hold or view this book thanks to Joan Murray, who was very encouraging of my book
proposal and provided a lot of writing tips.
I am grateful to Chaim Krause for providing a very detailed technical review and catching even the
smallest mistakes.
Many thanks go to Laura Berendson for reading the manuscript, providing feedback, and giving general
advice. I thank Jill Balzano for her patience and keeping track of the book project. I also thank Welmoed
Spahr and Todd Green for publishing this book and April Rondeau for copyediting.
Finally, special thanks go to my wife, Agnieszka, daughter, Susanna, and son, Xavier, for their
continuous support and patience shown to me during the writing of this book.

xiii
Introduction

The programming of mobile apps has recently become one of the most important and exciting aspects of
the IT market, leading to numerous applications. At the same time, mobile development is very challenging
because of market fragmentation, which is manifested by the presence of devices of different sizes, operating
systems, and software development tools. So, to start doing mobile development, you need to take into
account these various factors and decide your strategy.
There are three leading mobile platforms: Apple (including iOS, watchOS, and tvOS), Android, and
Universal Windows Platform (UWP), each of which provides dedicated tools for developing apps. Each
platform has specific hardware requirements. Clearly, iOS SDKs require you to use the local Mac machine
or the remote build agent installed on a Mac. UWP apps can be built on Windows 10 machines. Finally, you
can use either Mac or Windows machines to develop Android apps. So, first and foremost, the question to
answer is that of which hardware to choose. For mobile development, the Intel-based Mac platform is the
best choice because it allows you to use macOS and Windows 10 concurrently. The latter can be installed
natively through the Boot Camp or virtually using the Parallels Desktop. Accordingly, Mac machines will give
you the most flexibility.
After choosing the hardware, you need to select the software development strategy. You have three
traditional options here:
• Native apps – In this case, you use platform SDKs, which require you to utilize
platform-specific IDEs and programming languages. For instance, in terms of iOS,
watchOS, and tvOS, you would need to use either Swift or Objective-C along with
Xcode. Native tools give you full access to the platform API at the cost of needing to
learn platform-specific programming languages.
• Hybrid apps – They are programmed with web technologies as web pages. These
pages are then rendered with a native WebView component, which can be virtually
understood as the local web browser, delivered by each platform. In this case, you
have a lot of flexibility in terms of programming tools and can use the same code
across various platforms at the cost of reduced access to platform-specific APIs.
• Mobile web apps – They are web apps whose views are tailored to mobile
devices. Such a strategy is the simplest to apply but does not let you access device
components, and it also requires a network connection.
Of course, development strategy is dictated by a number of factors, ranging from your programming
preferences to application complexity and target platforms. If you intend to target multiple platforms at
the same time, you can choose one of the cross-platform mobile tools, like Xamarin.Forms, Qt Mobile,
Embarcadero RAD Studio, or React Native. They provide an additional layer of the unified, platform-
independent programming API, which is translated to a platform-specific API during compilation.
Importantly, cross-platform instruments provide not only access to the API but also to visual controls. For
instance, if you create a message dialog, it will be converted during compilation to the platform-specific
message dialog. As a result, in such a “Write once, run anywhere (WORA)” approach, you can indeed
compile the same code across various platforms at the cost of flexibility. Finally, if your goal is to extensively
utilize platform-specific APIs, you will choose Xamarin.iOS or Xamarin.Android. These let you develop

xv
■ Introduction

native apps with C# or F#. Xamarin.iOS and Xamarin.Android provide an additional thin layer that maps C#
or F# code onto the native platform API. You typically use Xamarin.iOS and Xamarin.Android to implement
logic and design the UI separately for each platform. Although you have the extra work of creating platform-
specific UIs, you can still share the platform-independent code between various apps. Such an approach
gives you two important advantages:
• Your app is native. So, it looks like any other built-in app, as it utilizes native visual
controls.
• Your app is written in modern programming language. As a result, you have easy
access to numerous libraries and a wide community. This is especially important
when you are C# programmer who wants to start developing mobile apps.
In this book, we will learn how to use Xamarin.iOS to develop apps for Apple devices: iPhone and iPad
(iOS), Apple Watch (watchOS), and Apple TV (tvOS). We will first prepare the development tools (Visual Studio
for Mac) and will get to know available project templates (Chapter 1). Subsequently, I will explicitly show how
Xamarin.iOS is related to the native SDKs delivered by Apple, and we will investigate the app structure and
lifecycle (Chapter 2). Then, we will learn how to create views (Chapter 3) and implement navigation between
them (Chapter 4). Afterward, we will work with touch gestures (Chapter 5), study how to achieve high-quality
apps with automatic testing (Chapter 6), and consume data from RESTful web services (Chapter 7). Finally,
we will learn how to develop apps for Apple Watches (Chapter 8) and Apple TVs (Chapter 9).
In this book, however, we will not learn how to reuse code between various platforms nor how to
develop WORA apps with Xamarin.Forms. You can find more information about this in this book Beginning
Visual Studio for Mac: Build Cross-Platform Apps with Xamarin and .NET Core by Alessandro Del Sole.

xvi
CHAPTER 1

Fundamentals

In this chapter, I will guide you through the installation of the development tools you will need for this book.
Specifically, we will install Visual Studio for Mac as well as Xcode. The latter is the native toolset for Mac
developers. It delivers IDE, SDKs, and also the device simulators we will use. If you have these tools already
installed, you can skip to the subsequent section.
After ensuring that all tools are ready, we will create the first Xamarin.iOS app for the iPhone and iPad.
This app, shown in Figure 1-1, displays various alerts and responds to user actions. I will also discuss the
available project templates that are delivered by Visual Studio. The same templates are available in Xcode, so
Xamarin.iOS and Visual Studio let you access iOS platform–specific programming interfaces in a way similar
to native development tools but with the ease and smoothness provided by the C# programming language.
In this chapter, I will also discuss the basic aspects of designing user interfaces in Visual Studio and show
you how to associate event handlers with events fired by visual controls.

■■Note In this chapter, I will not discuss Visual Studio for Mac in detail. I will only discuss the necessary
elements of this IDE. You can find a comprehensive description of Visual Studio for Mac in the book Beginning
Visual Studio for Mac. Build Cross-Platform Apps with Xamarin and .NET Core by Alessandro Del Sole.

© Dawid Borycki 2018 1


D. Borycki, Beginning Xamarin Development for the Mac, https://doi.org/10.1007/978-1-4842-3132-6_1
Chapter 1 ■ Fundamentals

Figure 1-1. The Hello, World! app we will build in this chapter. The app is executed in the iPhone X simulator.

Setting Up the Development Environment


To install Visual Studio for Mac, you’ll need a Mac with macOS Sierra 10.12 or above. Here, I’ll be using either
a MacBook Pro or iMac with macOS Sierra 10.16. Once you know that you meet basic platform requirements,
you can download the Visual Studio installer from the following website: http://bit.ly/vs-mac. Once you
have downloaded the installation package, run the installer. A window appears, as shown in Figure 1-2. In this
window, you double-click the icon with a down arrow. Subsequently, you will see a dialog informing you that
the installer was downloaded from the internet (Figure 1-3). Click the Open button to continue.

2
Chapter 1 ■ Fundamentals

Figure 1-2. An installer for Visual Studio for Mac

Figure 1-3. A confirmation dialog

Visual Studio installer will now verify your system configuration (Figure 1-4). More specifically, it looks
for installed components (like Mono Framework, Java SDK, and so on) in order to verify which of them have
to be downloaded and installed. Once this is done, another dialog appears on top of the window shown in
Figure 1-4. Its header tells you “Thank you for downloading Visual Studio.” In this dialog, you simply press
the Continue button.

3
Chapter 1 ■ Fundamentals

Figure 1-4. Visual Studio installer is inspecting the operating system

At this point, the Visual Studio installer might prompt you to install Xcode (Figure 1-5). This happens
only if you do not have Xcode already installed. According to this dialog, you can install Xcode concurrently
with the Visual Studio installation. Note that the Xcode installation is optional and depends on your current
system configuration. I assume that you start with a clean install of macOS and therefore explicitly show how
to install Xcode.

4
Chapter 1 ■ Fundamentals

Figure 1-5. A dialog prompting for Xcode installation

To install Xcode, you can press the Get Xcode button shown in Figure 1-5. This will direct you to a
website, where you click the View in Mac App Store or Install App button. It opens the Xcode page in the
App Store, on which you only need to click the Install App button (Figure 1-6). Alternatively, to install Xcode
you can open the Mac App Store locally and then look up Xcode. Irrespective of which method you choose,
Xcode and all related developer tools will be downloaded and installed in the background. So, you can now
go back to Visual Studio installer.

5
Chapter 1 ■ Fundamentals

Figure 1-6. Xcode page in the Mac App Store

The Visual Studio installer will now let you choose which components to install (Figure 1-7). To reduce
installation size, I uncheck the “Android + Xamarin.Forms” entry and only install iOS- and macOS-related
components. Then, after you click the Install button, the actual installation process begins.

6
Chapter 1 ■ Fundamentals

Figure 1-7. Choosing components to install

Visual Studio will now download and install the components. This will take a while, depending on
network speed. You will be informed about each installation step and the overall progress, as shown in
Figure 1-8. Also, as depicted in this figure, macOS may prompt you for the administrator password several
times during installation. Once installation has finished, an appropriate dialog appears. Note that to build
and run apps in the simulator, you will need to wait until Xcode installation has finished.

7
Chapter 1 ■ Fundamentals

Figure 1-8. Installing Visual Studio for Mac

Hello, World! App


After installing the development tools, we can start building the first app. To jumpstart the Xamarin.iOS
development, I will tell you how to create the project using the Single View app template. Then, we will
supplement the app with a single button. This button will react to taps such that the native alert will be
displayed. Subsequently, we will add specific actions to this alert. Displaying alerts is a typical functionality
of not only introductory apps, but also real apps, where it is used to collect user input or get confirmation for
performing irreversible operations.

Creating the Project


To create the project, open Visual Studio for Mac. A welcome screen, depicted in Figure 1-9, appears. Then,
you either choose File/New Solution in the menu bar or click the New Project button, located under the
“Recent” header. This activates the New Project window, shown in Figure 1-10.

8
Chapter 1 ■ Fundamentals

Figure 1-9. A welcome screen for Visual Studio for Mac

9
Chapter 1 ■ Fundamentals

Figure 1-10. Project template selection

The New Project creator lets you choose a template for your project. To filter the list of templates to
items directly related to iOS apps, you click App entry under the iOS tab. A list of available project templates
will then appear on the right. This list is divided into two categories: General and Games. In this book, we
will only use project templates from the General group. This category contains the following templates:
• Single View App — You use this template to create the app, which comprises a single
view; i.e., an app without any navigation, like the app shown in Figure 1-1.
• Master-Detail App — This template creates apps that use Master-Detail interface. In
such cases, a list displays short descriptions of objects. Once you choose an object from
this list (master), corresponding details will be displayed in the dedicated area (detail).
Master-Detail interface is used, for example, in the Stocks iOS app (Figure 1-11).

10
Chapter 1 ■ Fundamentals

Figure 1-11. Representational view of a Master-Detail iOS app. The list of objects (companies) is shown on
top. When you tap any of these objects, corresponding details (stock values) appear at the bottom.

• Tabbed App — You use this template to create a multi-tab application in which you
can arrange visual controls in multiple tabs. User then navigates between tabs using
labeled icons shown at the botton of the screen. Such navigation is used in the Clock
iOS app (Figure 1-12).

11
Chapter 1 ■ Fundamentals

Figure 1-12. An example of Tabbed iOS application. You switch between tabs using labeled icons displayed in
the bottom part of the view

• Page-based App — Use this template to create a multi-view app in which controls are
arranged in pages. The user swipes between pages with touch gestures. For instance,
such page-based navigation is utilized in the Weather iOS app, shown in Figure 1-13.

12
Chapter 1 ■ Fundamentals

Figure 1-13. Page-based navigation is utilized in the Weather app to switch between weather forecasts

• WebView App — You use this template to jumpstart hybrid app development. This
project template creates a view with an embedded WebView control. The latter
renders a website written with HTML, CSS, and JavaScript. I will tell you more about
WebView in Chapter 3.
To proceed further, let’s pick the Single View app project template and keep the default language
selection of C#. Then, you will have the option to specify the name of your app and organization identifier
(Figure 1-14). I set these values to HelloWorld and com.db, respectively. The next group of controls in app
configuration lets you specify which devices will be supported by your app. In this case, I made my app
universal and chose iPad and iPhone. The very last control in the app configuration screen is the Target
drop-down list. You use this list to select the minimum iOS version that will be supported by your app. I
set this to iOS 9.0. After configuring the app, press the Next button, which activates the view depicted in
Figure 1-15.

13
Chapter 1 ■ Fundamentals

Figure 1-14. iOS app configuration

The Project Summary window shown in Figure 1-15 displays the project and solution names. You can
also use this screen to set the location for your source code, enable version control, and add an automated
UI test project. Here, I keep the settings at their default values. I will tell you more about unit testing in
Chapter 6. So, go ahead and press the Create button to proceed further. You will quickly see the Getting
Started screen of Visual Studio (Figure 1-16).

14
Chapter 1 ■ Fundamentals

Figure 1-15. Project summary

The Getting Started screen displays several options for you. Specifically, it lets you start designing
the user interface (UI) of your app, add a mobile backend, and unit test the project. Also, on the left-hand
side of this window you will see the Solution Explorer, which displays the structure of the HelloWorld app.
Specifically, there is a HelloWorld solution, under which you can find the project of the same name (refer to
Figure 1-15). This project contains the files that make up your app. They are discussed in more detail in the
next chapter. For now, let’s create a simple UI for the HelloWorld app using the Storyboard (or iOS) Designer.

15
Chapter 1 ■ Fundamentals

Figure 1-16. HelloWorld project open in Visual Studio

Storyboard Designer
To start creating the UI, you can click the Open Storyboard Designer button. This will open the Main.
storyboard file and activate the Visual Interface or Storyboard Designer (or simply iOS Designer) of Visual
Studio. This designer is shown in Figure 1-17. Three elements of this designer should be discussed in more
detail, as follows:
• Visual preview of the app. This element covers the central part of the designer
and lets you see how your views will be displayed in the device without your
having to run your app. For multi-view apps, the visual preview will also depict the
relationships between views (tabs or pages) through which the user can navigate.
• Toolbox, which is in the top-right corner, contains a list of visual objects you can drag
on the view.
• Properties window, located below the Toolbox. You use the Properties window to
change the appearance of and configure visual controls, to define the layout, and to
wire methods to events (like tap or input) fired by controls.
Note that you can also activate the preceding windows or pads using an appropriate menu option in
Visual Studio: View ➤ Pads (see Figure 1-18). There is also one useful drop-down list in the preview mode.
That is the View As list, which you can find on the top pane of the visual preview. The View As drop-down list
lets you choose the device type to use for the preview. As shown in Figure 1-17, I set this device to iPhone 6.

16
Exploring the Variety of Random
Documents with Different Content
Fig. 26. Another type of dwelling house.

Some of the tree-embowered farm houses have such a restful look


and often embody such true lines of beauty that it seems almost
sacrilegious to change them. On the other hand, some of them are
so ill adapted to farm life, so unhandy and uncomfortable, that
radical changes should be made. After the farmer has prospered, he
naturally has a desire to build a new house or to transform the old
one, not only to secure needed conveniences, but that greater
beauty and a more luxurious home may be secured. It is difficult for
him to find adequate help to solve the problem if he keeps the cost
within reasonable limits. He may know where to begin; he seldom
knows where he will end. Usually the first thought should be to
preserve the old home, or the greater part of it. The architect is
almost certain to advise demolition and the erection of a new house,
asserting that the new structure will be no more expensive than the
remodeling of the old, which may or may not be true. But he does
not always know what is best, as he is usually unfamiliar with the
farmers’ needs and traditions. Sacred associations usually cluster
round the old farm house; every room and door and window may be
associated with some epoch in life’s history. Through yonder door
came the happy bride a half century ago; in yonder room the children
were born;—every nook and corner has some tale to tell, some
happy association. We cross oceans and mountains to view the
birthplaces and homes (which happily sometimes are preserved and
held sacred) of a Burns and a Shakespeare. Then is it not well to
preserve the farm houses, where possibly are the birthplaces of
many “Cromwells guiltless of their country’s blood.”
The first thought, then, should be to save and improve the old
house, not to destroy it. But most of these farm houses are either too
low or too high: that is, they are neither one- nor two-storied, but a
story and a half. A two-story wing may often be placed either at the
front or side, and may serve to give dignity to the house; or a lower
room or two, a few comfortable chambers, and an entrance hall or
vestibule may be added. Such addition would make it possible to
remove the low, flat-roofed, leaky kitchen to more appropriate
quarters. The formerly unused parlor might be transformed into a
living-room, the former living-room into a dining-room, and the old
dining-room into a kitchen. The details by which this evolution is
made must, of necessity, be worked out by those who are to occupy
the house. That home is enjoyed best which is planned by those who
have to pay the bills; therefore, I shall not go into detail of
arrangement. My object will have been accomplished if I succeed in
creating a greater respect and love for the houses of our ancestors,
and shall have stayed the hand of the iconoclast. Any one can
destroy, but few can create.
So reasoned the college graduate on his return to the old
homestead. The old house (Fig. 27) was improved by making slight
additions and some minor changes. Even the green window blinds
and the white siding were not disturbed, only brightened by the use
of old-fashioned, unadulterated paints. The major effort was along
the line of improving the live stock and making the acres more
productive, soon resulting in surplus funds, which were used to erect
the large and commodious barn. Simultaneously with the barn came
the icehouse, and the windmill for pumping water. The observant
passer-by instinctively knows that here are all the outward
indications of morality, intelligence, and a rational and progressive
system of agriculture. If the family be judged by what is seen in this
picture of the farm above ground, the conclusion must be reached
that here is a true home.
How different the impression is when we look through the open
roadside gate in the next picture (Fig. 28)! Lack of intelligent purpose
and of neatness and thrift is written upon every structure, and is
especially shown by the want of any logical plan in the arrangement
of the numerous small structures. The house, which stands just to
the right of the beautiful tree, is modern in many respects, but the
front is supported by numerous Grecian columns nearly twenty feet
long, as inappropriate and as useless for a farm-house as is a coon’s
tail on a lady’s hat.
Fig. 27. The old homestead.
Fig. 28. Lack of intelligent purpose.

Instinctively we judge people at first sight, and largely by the


clothes they wear and the manner of wearing them. So we judge,
and often very accurately, of families by the houses which shelter
them and the objects which surround them. One can easily tell much
of the character of a man by the style and tip of his hat. What noble
deeds, what lofty aspirations in this day and age of plenty and
opportunity, should we expect to have birth and fruition in the house
shown in illustration Fig. 29! This building is not located in the
country, but in the suburbs of a small, prosperous inland city.
Unfortunately, this village is unlike many beautiful country villages
and small cities in western New York in which there are no poor
people. What a depressing effect this building must have on the well
bred country lad who passes it weekly on his journey to and from the
post office!
But how easy to go from one extreme to the other! Too many farm
houses stand alone, unrelieved by noble trees or by modest planting
of appropriate shrubbery, looking in the distance at the setting sun
like lofty, whitewashed sepulchres. On the other hand, the house
may be made dark and damp by over-planting. The house shown in
Fig. 30 is a comfortable, fairly attractive stone structure, but is made
gloomy and damp by the superabundance of evergreen and
deciduous trees which fill all the space, barely thirty feet, between
the house and the highway.

Fig. 29. Environment often makes the man.

The church, as well as the farm house, is or should be the home of


the farmer; but the church, like the individual, may become proud, in
which case the old meeting-house is demolished and replaced by a
modern new one, which may serve for a time to stimulate laggards
and appear to take the place of changed purposes in life. But the
debt saddled on the congregation tends to drive the church-goers to
the rear seats and eventually out of doors. I have sometimes thought
that a country church could not well be too small. Man is a
gregarious animal, and does not enjoy church-going when the seats
are but partially occupied.

Fig. 30. Buried in trees. The opposite extreme from Fig. 26.

The plain, substantial stone church shown in Fig. 31 is located in a


sparsely settled district on the windy prairies of Kansas. It is certainly
most appropriate and fits its environment; all it lacks to make it
beautiful is a suitable setting of trees and shrubbery. It would then
serve as a reminder of “God’s first temple not made with hands,” and
not of one made with a jig-saw.
Fig. 31. A plain, substantial stone church.

“It is a plain, rugged, austere structure, like the men who built it,
and any proposal to modernize it would be received with disfavor; for
it means more to the people than merely a church building—it is a
sacred possession that is a part of their life,” and it is an appropriate
monument to the sturdy religious character of the pioneers who
stood in the forefront as a wall guarding human rights and liberties in
those stormy days of the past. The country church should be as truly
a part of the farm structure as are the house and barn, located on
land held in fee simple.
Fig. 32. Where horses are kept.
Fig. 33. Where boys and girls are taught.

The school-house also, as well as the church, should form a part


of the farm above ground. We sometimes build parlors for the
pictures, and palaces for the horses and cattle, and neglect the
school-house. A city of 12,000 inhabitants in central New York has
many expensive stables, some of them works of art. The barn shown
in Fig. 32 is not more than half a mile from the school-house shown
in Fig. 33. The beautiful stable might serve as a well appointed
dwelling house by making a few minor changes. While such
buildings are being constructed, the country school-house, the pride
of the American, is left to fall into decay; or, if rebuilt, it is located too
often on a little scrap of land which may be almost worthless, as
though land in America were the most precious of all our inheritance.
This school-house is designed to provide accommodations for both
farm and city children living in the suburbs. The school-house has
not a tree for shade nor a shrub to admire, situated on the commons
among weeds and rocks, provided with one dilapidated outhouse
unscreened by fence or tree or vine or shrub, while the stable is
surrounded with rare trees and shrubs artistically arranged and a
smoothly shaven lawn. Are horses and cattle worth more than boys
and girls?
To leave the reader to infer that all school-houses are like the one
shown would be misleading. A more pleasing illustration is presented
in Fig. 34. Here the meeting-house, the school-house, and a bit of
the farm are shown in juxtaposition, as they were found at the
meeting of the roads in a shady grove. Since moral character should
be the foundation upon which to symmetrically build intelligence and
industry, the church may be treated first. While taking the
photograph, I was struck by the inexpensive character of the
meeting-house. The outside covering was of plain, matched, vertical
boards, but they were kept well painted and therefore looked neat,
and the seats were entirely comfortable. I judge that here true,
practical religion finds a congenial home, for a long line of
comfortable sheds were being built to house the horses during the
hours of devotion. Then, too, the sheds will serve a doubly humane
purpose, for where the pupils live long distances from the school the
horse driven in the morning will have comfortable quarters until the
school closes in the evening. A public water-trough near by, kept full
from a spring, gave evidence that this little church and the school-
house were potent factors in promoting civilization. To the right is
seen a lad plowing. Here, then, in this picture is represented the
three great corner-stones of civilization upon which to build a
symmetrical, beautiful superstructure. To build on either one alone is
to insure disappointment; when life is grounded on all three the result
is practical religion and intelligence eventuating in a better
understanding of the complex soil and the interrelations of nature’s
modes of action. It means steady and effective employment, the
abandonment of nomadic life, and in lieu thereof a permanent home
and an abundant supply of the necessaries and comforts of life. The
Bible, the school book, and the plow should all be engraven and
intertwined in our modern civilization.
Fig. 34. School house and church at the corners.

So far the general characteristics, fitness, durability and beauty of


the country farm house have been discussed and illustrated,
together with such public buildings as are directly related to rural life.
But having discussed the size, best proportions, and most suitable
materials for the house, and having put them into visible form, the
building may be made hideous and unnecessarily expensive by
careless or ignorant treatment of external details.
Fig. 35. The sway-back house.

Most of the farmers who now occupy the country west of the
Alleghanies came from the east and brought with them a varied
assortment of styles of architecture inherited from the many
European countries from which they or their ancestors came. These
people, though of limited means, had pride and tenacity of purpose,
and they could not easily change to the plain and appropriate
exterior treatment of the farm house. This inheritance and
persistence, as shown in the farm houses of the middle states, is fitly
illustrated by the expensive and heavy return cornice, the massive
columns, and the complicated and ornate entablatures which are
supposed to adorn an otherwise plain house.
Fig. 36. The expensive box cornice.

I have said that there is no place for the story-and-a-half house.


Here is shown (Fig. 35) the results of two serious mistakes; viz., an
effort to build a cheap frame of such a form that it is almost
impossible to tie the building together, with the result that the roof is
in danger of collapsing; and the attempt to beautify this cheap
structure by over-heavy, complicated cornices. An enlarged detailed
drawing of a typical return cornice is shown in Fig. 36. On the right is
shown a cross-section outline of the members of the cornice. There
are ten of them. The mouldings are now “stuck” by machinery, but
these were made by hand, and 10 and 8 were formed of two pieces
each, making twelve members in all. The infinite pains and labor in
preparing the material and placing it cannot be realized except by a
carpenter who has spent weeks and months in sawing out, in planing
and “sticking,” and mitering such an elaborate system of useless
ornamentation. Compare this with the cornice, or rather projection, of
a house (Fig. 19) which cost $6,000. Fig. 36 shows a projecting eave
of scarcely one foot. The next illustration (Fig. 37) shows one of
nearly two feet. The latter is far superior to the former in that it is
quite as beautiful, is
inexpensive, and
protects the external
paint and woodwork
far more than does
the former. The piece
at the top of the rafter
serves to cover the
projecting cornice,
and as a roof-board
as well, and gives
opportunity to place
the eave trough well
outside, which
prevents damage to
the house should it
ever leak. The frieze
Fig. 37. A plain and durable cornice. board is simple and
serves its purpose
well. It has taken a long time to learn that a wooden roof which is at
least one-third pitch is far more durable than the flat roof shown in
Fig. 38. Here the return cornice is carried across the entire end of
the house, and the gable is ceiled with plain matched boards, both
likely to leak and to rapidly become paintless.
Many veranda and porch floors and outside doors have no roof
over them, or other protection. This is poor economy. It would be
better to reduce the cornice to the fewest possible members, if it
were necessary to do so, in order to secure means to roof the
veranda, which, unprotected, decays rapidly. Or the money
expended on the cornice, which results in neither use nor beauty,
might well suffice for the building of an additional room, or to provide
many conveniences, such as hot and cold water, storm sash, and
window screens.
Fig. 38. The old-time gable end cornice.

Fig. 39. Framework of a ship.


When the farmer reached the fertile, treeless prairies he was
compelled to economize in lumber. Some genius soon discovered
that the best and most scientific method of constructing the frame of
a house was along the lines of ship construction (Fig. 39): that is,
ribs, joined to a sill or sills, encircling the entire structure and placed
at equal distances apart. Two keels or sills joined together by joists,
straight ribs—joists—instead of curved ones, a roof instead of a
deck, and the balloon frame (Fig. 40)—the best of all frames when
properly constructed,—was invented. Unwittingly the ship
construction, slightly modified, was adopted. In this frame the
westerner departed radically from the style of his ancestors, but he
could not be satisfied with a plain oversail projection. He could not
afford the heavy box cornice. Having succeeded so well on the
frame, he set about inventing a new style of decoration for the
projecting eaves, but the cornice was not a success. The
decorations shown in Figs. 41 and 42 serve to make hideous many a
cheap dry-goods-box house, which blisters and cracks in the hot
prairie winds. These houses sometimes receive no paint or one coat,
or at most two, and in a few years, what with storm and sun,
mischievous boys and wind cracks, this ginger-bread, dog-eared
cornice, made of inch lumber by the use of scroll saw, looks as
dilapidated as a college boy after a cane-rush.
Fig. 40. The balloon frame.
Fig. 42. Fig. 41.
The jig-saw cornice. Too elaborate and short-lived.

The thought of permanent beauty, as well as economy and


usefulness, should enter into the plans of a house. But what is
beauty? I am well aware that many of my readers will not agree with
me, for
“The standard of beauty ofttimes it doth vary:
Two pretty girls are Eliza and Mary.”

They may be very unlike, yet both beautiful. From the farmer’s
standpoint it may be said that the chief characteristics of beauty are
fitness, naturalness and simplicity.
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

textbookfull.com

You might also like