Swift 4 Recipes

所需积分/C币:3 2018-12-29 09:31:45 2.11MB PDF
8
收藏 收藏
举报

Get the most out of Swift 4 with this carefully compiled collection of select code snippets designed to solve everyday coding problems. This book features the Apress easy-to-use recipe format, with step-by-step instructions, and a no-fuss approach. You'll explore a wide range of topics, all neatly o
Swift 4 Recipes: Hundreds of Useful Hand-picked Code Snippets Yanis Zafiropulos Granada, Spain ISBN-13(pbk):978-1-4842-4181-3 ISBN-13( electronic:978-1-4842-4182-0 https://doi.org/10.1007/978-1-4842-4182-0 Library of Congress Control Number: 2018963844 Copyright o 2019 by Yanis Zafiropulos 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, log 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 Managing Director, Apress Media LLC: Welmoed Spahr Acquisitions Editor: Aaron Black Development Editor: James Markham Coordinating Editor: Jessica Vakili CoverimagedesignedbyFreepik(www.freepik.com) 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-mailorders-ny@springer-sbm.comorvisitwww.springeronline.comApressMedia,Llcisa California LLC and the sole member(owner) is Springer Science Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation Forinformationontranslationspleasee-mailrights@apress.comorvisithttp://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 andebooKBulkSaleswebpageathttp://www.apress.com/bulk-sales Any source code or other supplementary material referenced by the author in this book is available toreadersonGithubviathebooksproductpagelocatedatwww.apress.com/978-1-4842-4181 Formoredetailedinformationpleasevisithttp://www.apress.com/source-code Printed on acid-free paper To my father For having introduced me to the world of programming, 25 years ago; and with the hope that he will finally get himself a mac Table of contents About the author ■■■■■ Vii About the technical reviewer lix Acknowledgments ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ Part l: Beginner Chapter 1: Introduction m mant ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 1-1. Getting Familiar with Swift Problem ■a Solution,……3 How It Works ■Da 1-2. Scripting in Swift Problem Solution 5555 How It Works 1-3. Summary… Chapter 2: Basics. ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■口■■口■■■■■口■a日■■ 2-1. Create a Hello world Problem Solution 77777 How It Works TABLE OF CONTENTS 2-2 Declare variables 8 Problem 8 Solution How It Works…8 2-3 Declare constants Problem Solution How It works 2-4 Declare multiple variables 10 Problem 10 Solution,…10 How It Works 10 2-5, Declare Unicode constants and variables Problem 10 Solution How It Works…1 2-6. Declare a range Prob|em.…11 Solution…………1 How It Works 12 2-7. Define an enumeration type mmmmmmmmmmmmmmm12 Problem 12 So| ution,,…… How| t Works…13 2-8. Define a type alias Problem 重面重D重重DD重夏重■D重DD面重D面重面面重1 14 Solution 14 How It Works…14 TABLE OF CONTENTS 2-9. Use semicolons …144 Prob|em,…14 Solution How| t Works… 5 2-10. Use comments ■重重面重D重a 15 Problem n15 Solution How It Works ■a 16 2-11. Summary Chapter 3: Conditionals ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■口■■■■■■■■■■■口■■■■■■■■■ 3-1. Write an if statement Problem Solution…17 How| t Works… 3-2. Write an if/else statement 18 Prob|em… Solution How It works…18 3-3. Write multiple if/else/if statements Problem ■Dm Sout0n………19 How It Works 19 3-4, Write a switch statement Problem …19 Solution…19 How It Works TABLE OF CONTENTS 3-5. Write a switch statement with intervals Problem 20 Solution ■■ How It Works…21 3-6. Write a switch statement with enumeration values 22 oblem 22 Solution……22 How| t Works…123 3-7. Write a switch statement with compound cases ■■■■D■口■■面■口■■D 23 Problem 23 Sout0n………23 How It Works 24 3-8. Write a switch statement with tuples..m.... tt.. 24 Problem 24 Solution 24 How It Works…125 3-9. Write a switch statement with value bindings Prob|em.…125 Sout0n…………25 How It Works 26 3-10. Use the ternary conditional operator. emnmnmammemnnmnn, 26 Problem 26 Solution 26 How It Works ■■国■■■D面■国■■■D面■■■■D■■■■D■■D■D■D■D■目■口■D■■D■ 3-11. Use the nil coalescing operator Problem 重面面重D重DD重夏重■D重,DD面重D面重夏D面面重D Solution 27 How It Works…128 TABLE OF CONTENTS 3-12. Use the logical and operator 128 Prob|em……28 Solution How| t Works… 3-13. Use the logical not operator ammememeannmmannnmeacnnmamenn. 29 Problem 29 Solution 29 How It Works ■aDam 3-14. Use the logical or operator Problem 29 Solution………130 How It Works∴, n30 3-15. Use the logical xor operator……130 Prob|em…130 Solution n30 How It works 3-16. Summary ■重 Chapter 4: Loops. ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 33 4-1. Write a for loop . Problem 33 Sout0n………33 ow It Works…344 4-2. Write a while loop 34 Problem 134 Solution…34 How It Works TABLE OF CONTENTS 4-3. Write a repeat-while loop …35 Problem Solution ■■ How It Works…136 4-4. Summary…,, Chapter 5: Functions ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 37 5-1. Define and call a function Problem Solution How It Works 38 5-2. Define and call a function with arguments Problem S0ut0n………38 How It Works……39 5-3. Define and call a function with argument labels. mmmm.mmmmmmm 39 Problem 39 Solution How It Works 40 5-4. Define and call a function without argument labels Problem So| ution,,,… ow It Works… 5-5. Define and call a function with default parameter values 42 Prob|em…242 Solution 42 How It Works 43

...展开详情
试读 127P Swift 4 Recipes
立即下载
限时抽奖 低至0.43元/次
身份认证后 购VIP低至7折
一个资源只可评论一次,评论内容不能少于5个字
您会向同学/朋友/同事推荐我们的CSDN下载吗?
谢谢参与!您的真实评价是我们改进的动力~
  • 签到新秀

  • 分享王者

关注 私信
上传资源赚钱or赚积分
最新推荐
Swift 4 Recipes 3积分/C币 立即下载
1/127
Swift 4 Recipes第1页
Swift 4 Recipes第2页
Swift 4 Recipes第3页
Swift 4 Recipes第4页
Swift 4 Recipes第5页
Swift 4 Recipes第6页
Swift 4 Recipes第7页
Swift 4 Recipes第8页
Swift 4 Recipes第9页
Swift 4 Recipes第10页
Swift 4 Recipes第11页
Swift 4 Recipes第12页
Swift 4 Recipes第13页
Swift 4 Recipes第14页
Swift 4 Recipes第15页
Swift 4 Recipes第16页
Swift 4 Recipes第17页
Swift 4 Recipes第18页
Swift 4 Recipes第19页
Swift 4 Recipes第20页

试读结束, 可继续阅读

3积分/C币 立即下载