• Complain

Yanis Zafiropulos - Swift Cookbook

Here you can read online Yanis Zafiropulos - Swift Cookbook full text of the book (entire story) in english for free. Download pdf and epub, get meaning, cover and reviews about this ebook. year: 2017, publisher: CodeFluence, genre: Home and family. Description of the work, (preface) as well as reviews are available. Best literature library LitArk.com created for fans of good reading and offers a wide selection of genres:

Romance novel Science fiction Adventure Detective Science History Home and family Prose Art Politics Computer Non-fiction Religion Business Children Humor

Choose a favorite category and find really read worthwhile books. Enjoy immersion in the world of imagination, feel the emotions of the characters or learn something new for yourself, make an fascinating discovery.

Yanis Zafiropulos Swift Cookbook

Swift Cookbook: summary, description and annotation

We offer to read an annotation, description, summary or preface (depends on what the author of the book "Swift Cookbook" wrote himself). If you haven't found the necessary information about the book — write in the comments, we will try to find it.

Swift Cookbook is a carefully compiled collection of more than 340 useful hand-picked code snippets, all tried and tested, for Swift 3 - that solve everyday coding problems. Designed to be easy to use, with step-by-step instructions, suitable both for beginners and the seasoned Swift developers, Swift Cookbook will become your go-to guide for your daily... coding recipes.

Yanis Zafiropulos: author's other books


Who wrote Swift Cookbook? Find out the surname, the name of the author of the book and a list of all author's works by series.

Swift Cookbook — read online for free the complete book (whole text) full work

Below is the text of the book, divided by pages. System saving the place of the last page read, allows you to conveniently read the book "Swift Cookbook" online for free, without having to search again every time where you left off. Put a bookmark, and you can go to the page where you finished reading at any time.

Light

Font size:

Reset

Interval:

Bookmark:

Make
Swift Cookbook
Everything you always wanted to know about Swift,
but were afraid to ask (for)
Yanis Zafiropulos
Swift Cookbook by Yanis Zafiropulos Copyright 2015-2017 Yanis Zafiropulos - photo 1

Swift Cookbook
by Yanis Zafiropulos

Copyright 2015-2017, Yanis Zafiropulos. All rights reserved.

Edited and published by CodeFluence.

First Edition: October 2015
Second Edition: March 2017

While the publisher and the authors have used good faith efforts to ensure that the information and instructions contained in this work are accurate, the publisher and the authors disclaim all responsibility for errors or omissions, including without limitation responsibility for damages resulting from the use of or reliance on this work. Use of the information and instructions contained in this work is at your own risk. If any code samples or other technology this work contains or describes is subject to open source licenses or the intellectual property rights of others, it is your responsibility to ensure that your use thereof complies with such licenses and/or rights.

No part of this book may be reproduced or utilized in any form or by any means, elec- tronic or mechanical, including photocopying, recording, or by any information storage and retrieval system, without permission in writing from the author.

Apple, Swift and the Apple logo are trademarks of Apple Inc., registered in the U.S. and other countries. Mac App Store is a service mark of Apple Inc.

Contents
Preface
About this book

Long textbooks and huge reference manuals are nice. But only for taking up space in our bookcase.

What most programmers really want is a handy pocket book that they can carry with them, use it for reference at any time and cherry-pick the exact piece of information they need at that specific moment - pretty much like a chef who wants to quickly look up some ingredient and make sure he got the recipe right. And this is how the Swift Cookbook was born.

What this book is not:
  • A real cookbook (if you expect to find your next curry recipe here, I'm sorry but I'll have to let you down...)
  • A complete Swift library reference
  • A collection of every possible solution to every possible Swift-related problem you can think of (although I've done my best to cover a decent part)
What this book is:
  • A quick Swift reference
  • A collection of 340+ useful hand-crafted recipes - some shorter, some not - that solve everyday coding problems - all organized by categories
  • Your next go-to everyday guide for (almost) anything Swift-related; although you might not know it yet
  • A compilation of working and thoroughly tested Swift code snippets (you'll be amazed how many actually... work)
About the author
Q: Who are you?

Answer: A 30-something, Spain-based - originally Greek - programmer who has been in love with the Art of Code since he was a 8-year-old kid. He usually goes by the nickname Dr.Kameleon. Ah, and - in some former life - he's been a Med student but decided this life's too short for that. Hence, the "Dr. part.

Q: Why did you write this book?

Answer: To challenge myself, whether I can share my personal experiments with Swift, the things I myself had to learn step-by-step, so that it makes a rather pleasant and useful reading for every Swift programmer; a book, the way I've always envisaged code cookbooks: simple, concise and to the point.

Q: What did you say your name was?

Answer: Yanis. IPA: /'jan-is/. Pronounced like... oh, let's leave that here, shall we?

Introduction
How to run a Swift program

Now, that you got your hands on this little book, let's get them a bit... dirty. And what's better than delving into our first program?

Our first program

So, fire up your favorite editor and let's write this very... complicated one line of code.

print ( "Hello Swift!" );

Now we already have our code file, let's save this as hello.swift. The next rather logical question is: how do we actually run this thing?

Executing it

Well, you might be expecting something along the lines of Open Xcode, etc, etc, but - since I'm rather old-school and prefer having total control over what goes on, why/how it is executed, and so on - what could be better than doing it straight from the command line?

So, just open the Terminal app and let's go to the location where your hello.swift resides. Now, all there's left provided that you already have Xcode installed (and the accompanying developer tools) is running our script:

swift hello.swift

That was easy, wasn't it? Pretty much like with any scripting language (see: PHP, Python, Ruby, Perl, etc). But wait: is Swift a scripting language? Well, not quite...

Compiling it

What if we actually want to compile this code of ours and have a binary, which we can then use, without having to re-compile or having the Swift compiler around?

Let's see...

swiftc hello.swift

Super-easy again, nope? Just note the use of swiftc (the Swift compiler) instead of swift.

Now, if you look again into your folder contents, you'll notice a single hello binary, which you can execute, like any normal binary:

./hello

And that was it.

Scripting in Swift

So, can Swift be used for Scripting, pretty much like any regular interpreted language like PHP, Python, Ruby, Perl or... even Bash?

Well, here's the catch: given its speed, it sure can; at least for smaller scripts. Plus, since Apple has already launched it as open-source software (already having been ported to Linux), this makes it a not so Mac-only thing.

So, the answer is: why not?

Our first script

Let's get started then, with the same... ultra-complex Hello World we played with in the previous section.

And now let's add the magic shebang line:

#!/usr/bin/env swift print ( "Hello Swift!" )

We save it as hello_script.swift. And that was it.

Executing it

First, we make it "officially" executable by:

sudo chmod +x hello_script.swift

We can now execute it as we would execute any script:

./hello_script.swift

Yay! Now, it's time to rock'n'roll! :)

Basics
Create a Hello World

Wanna get started? Well... There's nothing better than a good old Hello World program.

// A single line does the trick. Hello World! print ( "Hello World!" )Hello World!
Declare variables

Variables are at the very core of every program. Basically, they consist of an identifier (symbolic name) associated with a value, which - in contrast with constants - can change.

// Declare a variable, without type. var surname = "Doe" // Declare a variable, with type var fullName : String = "John Doe" // And another one var age : Int = // Now, since it's a variable, why not change it? age = // So, let's see what we've done... print ( "My name is \( surname ) . \( fullName ) . And I'm \( age ) years old." )My name is Doe. John Doe. And I'm 30 years old.
Next page
Light

Font size:

Reset

Interval:

Bookmark:

Make

Similar books «Swift Cookbook»

Look at similar books to Swift Cookbook. We have selected literature similar in name and meaning in the hope of providing readers with more options to find new, interesting, not yet read works.


Reviews about «Swift Cookbook»

Discussion, reviews of the book Swift Cookbook and just readers' own opinions. Leave your comments, write what you think about the work, its meaning or the main characters. Specify what exactly you liked and what you didn't like, and why you think so.