├── Ch11-Backend └── vapor-example │ ├── .swift-version │ ├── Config │ ├── secrets │ │ ├── .gitkeep │ │ └── app.json │ ├── development │ │ └── app.json │ ├── production │ │ ├── app.json │ │ └── servers.json │ ├── app.json │ └── servers.json │ ├── Procfile │ ├── .gitignore │ ├── Resources │ └── Views │ │ ├── template.leaf │ │ ├── embeds │ │ └── header.leaf │ │ └── welcome.html │ ├── Localization │ ├── en.json │ ├── es.json │ └── default.json │ ├── Public │ └── images │ │ └── vapor-logo.png │ ├── app.json │ ├── VaporApp.xcodeproj │ ├── Configs │ │ └── Project.xcconfig │ ├── xcshareddata │ │ └── xcschemes │ │ │ └── xcschememanagement.plist │ ├── Console_Info.plist │ ├── Core_Info.plist │ ├── Fluent_Info.plist │ ├── HMAC_Info.plist │ ├── HTTP_Info.plist │ ├── JSON_Info.plist │ ├── Node_Info.plist │ ├── Routing_Info.plist │ ├── SMTP_Info.plist │ ├── Socks_Info.plist │ ├── URI_Info.plist │ ├── Vapor_Info.plist │ ├── libc_Info.plist │ ├── HTTPRouting_Info.plist │ ├── Polymorphic_Info.plist │ ├── SocksCore_Info.plist │ ├── Transport_Info.plist │ ├── WebSockets_Info.plist │ ├── PathIndexable_Info.plist │ └── TypeSafeRouting_Info.plist │ ├── .travis.yml │ ├── Package.swift │ └── Sources │ └── App │ ├── Middleware │ └── SampleMiddleware.swift │ └── Models │ └── User.swift ├── Ch11-Frontend └── TodoApp │ ├── Pods │ ├── Target Support Files │ │ ├── Argo │ │ │ ├── Argo-prefix.pch │ │ │ ├── Argo.modulemap │ │ │ ├── Argo-dummy.m │ │ │ ├── Argo-umbrella.h │ │ │ └── Argo.xcconfig │ │ ├── Curry │ │ │ ├── Curry-prefix.pch │ │ │ ├── Curry.modulemap │ │ │ ├── Curry-dummy.m │ │ │ ├── Curry-umbrella.h │ │ │ └── Curry.xcconfig │ │ ├── Delta │ │ │ ├── Delta-prefix.pch │ │ │ ├── Delta.modulemap │ │ │ ├── Delta-dummy.m │ │ │ ├── Delta-umbrella.h │ │ │ └── Delta.xcconfig │ │ ├── Result │ │ │ ├── Result-prefix.pch │ │ │ ├── Result.modulemap │ │ │ ├── Result-dummy.m │ │ │ ├── Result-umbrella.h │ │ │ └── Result.xcconfig │ │ ├── Runes │ │ │ ├── Runes-prefix.pch │ │ │ ├── Runes.modulemap │ │ │ ├── Runes-dummy.m │ │ │ ├── Runes-umbrella.h │ │ │ └── Runes.xcconfig │ │ ├── Alamofire │ │ │ ├── Alamofire-prefix.pch │ │ │ ├── Alamofire.modulemap │ │ │ ├── Alamofire-dummy.m │ │ │ ├── Alamofire-umbrella.h │ │ │ └── Alamofire.xcconfig │ │ ├── ReactiveCocoa │ │ │ ├── ReactiveCocoa-prefix.pch │ │ │ ├── ReactiveCocoa-dummy.m │ │ │ ├── ReactiveCocoa.modulemap │ │ │ └── ReactiveCocoa.xcconfig │ │ ├── ReactiveSwift │ │ │ ├── ReactiveSwift-prefix.pch │ │ │ ├── ReactiveSwift.modulemap │ │ │ ├── ReactiveSwift-dummy.m │ │ │ ├── ReactiveSwift-umbrella.h │ │ │ └── ReactiveSwift.xcconfig │ │ ├── Pods-TodoApp │ │ │ ├── Pods-TodoApp.modulemap │ │ │ ├── Pods-TodoApp-dummy.m │ │ │ └── Pods-TodoApp-umbrella.h │ │ └── Pods-TodoAppTests │ │ │ ├── Pods-TodoAppTests.modulemap │ │ │ ├── Pods-TodoAppTests-dummy.m │ │ │ ├── Pods-TodoAppTests-acknowledgements.markdown │ │ │ ├── Pods-TodoAppTests-umbrella.h │ │ │ ├── Pods-TodoAppTests.debug.xcconfig │ │ │ └── Pods-TodoAppTests.release.xcconfig │ ├── ReactiveCocoa │ │ └── ReactiveCocoa │ │ │ ├── NSObject+ReactiveExtensionsProvider.swift │ │ │ ├── module.modulemap │ │ │ ├── Deprecations+Removals.swift │ │ │ ├── UIKit │ │ │ ├── UITableView.swift │ │ │ ├── UICollectionView.swift │ │ │ ├── UIProgressView.swift │ │ │ ├── UIActivityIndicatorView.swift │ │ │ ├── UIImageView.swift │ │ │ ├── iOS │ │ │ │ ├── UIDatePicker.swift │ │ │ │ └── UIStepper.swift │ │ │ ├── ReusableComponents.swift │ │ │ ├── UIBarItem.swift │ │ │ ├── UISegmentedControl.swift │ │ │ ├── UILabel.swift │ │ │ └── UIView.swift │ │ │ ├── ReactiveCocoa.h │ │ │ ├── Shared │ │ │ └── NSLayoutConstraint.swift │ │ │ ├── NSObject+ObjCRuntime.swift │ │ │ ├── ObjCRuntimeAliases.m │ │ │ ├── ObjCRuntimeAliases.h │ │ │ ├── NSObject+Synchronizing.swift │ │ │ └── ObjC+Runtime.swift │ ├── Argo │ │ └── Sources │ │ │ └── Argo │ │ │ ├── Extensions │ │ │ ├── NSNumber.swift │ │ │ └── Dictionary.swift │ │ │ ├── Operators │ │ │ └── Argo.swift │ │ │ └── Types │ │ │ └── Decoded │ │ │ └── FailureCoalescing.swift │ ├── Delta │ │ └── Sources │ │ │ └── Delta.h │ ├── ReactiveSwift │ │ └── Sources │ │ │ └── ResultExtensions.swift │ └── Local Podspecs │ │ ├── Delta.podspec.json │ │ └── Curry.podspec.json │ ├── TodoApp.xcodeproj │ └── project.xcworkspace │ │ └── contents.xcworkspacedata │ ├── TodoApp │ ├── Actions │ │ ├── SetFilterAction.swift │ │ ├── DeleteTodoAction.swift │ │ ├── ClearCompletedTodosAction.swift │ │ ├── LoadTodosAction.swift │ │ ├── CreateTodoAction.swift │ │ └── ToggleCompletedAction.swift │ ├── Models │ │ ├── TodoViewModel.swift │ │ ├── TodosViewModel.swift │ │ └── RequestProtocol.swift │ ├── Stores │ │ └── Store.swift │ └── State │ │ └── State.swift │ ├── TodoApp.xcworkspace │ └── contents.xcworkspacedata │ ├── Podfile │ └── TodoAppTests │ └── Info.plist └── Playgrounds ├── Ch10-BestOfBothWorlds.playground └── contents.xcplayground ├── Ch01-Introduction.playground ├── Pages │ ├── Immutability.xcplaygroundpage │ │ └── Contents.swift │ ├── LazyEvaluation.xcplaygroundpage │ │ └── Contents.swift │ ├── Initialization.xcplaygroundpage │ │ └── Contents.swift │ ├── Methods.xcplaygroundpage │ │ └── Contents.swift │ ├── Tuples.xcplaygroundpage │ │ └── Contents.swift │ ├── ARC.xcplaygroundpage │ │ └── Contents.swift │ ├── Generics.xcplaygroundpage │ │ └── Contents.swift │ ├── Subscripts.xcplaygroundpage │ │ └── Contents.swift │ ├── ErrorHandling.xcplaygroundpage │ │ └── Contents.swift │ ├── Types.xcplaygroundpage │ │ └── Contents.swift │ ├── DeclarativeImperative.xcplaygroundpage │ │ └── Contents.swift │ ├── Protocols.xcplaygroundpage │ │ └── Contents.swift │ ├── Collections.xcplaygroundpage │ │ └── Contents.swift │ ├── Strings.xcplaygroundpage │ │ └── Contents.swift │ └── AnyAnyObject.xcplaygroundpage │ │ └── Contents.swift └── Resources │ └── Ch01-Introduction.playground │ ├── Pages │ ├── Immutability.xcplaygroundpage │ │ └── Contents.swift │ ├── LazyEvaluation.xcplaygroundpage │ │ └── Contents.swift │ ├── Initialization.xcplaygroundpage │ │ └── Contents.swift │ ├── Methods.xcplaygroundpage │ │ └── Contents.swift │ ├── Tuples.xcplaygroundpage │ │ └── Contents.swift │ ├── ARC.xcplaygroundpage │ │ └── Contents.swift │ ├── Generics.xcplaygroundpage │ │ └── Contents.swift │ ├── ErrorHandling.xcplaygroundpage │ │ └── Contents.swift │ ├── Subscripts.xcplaygroundpage │ │ └── Contents.swift │ ├── Types.xcplaygroundpage │ │ └── Contents.swift │ ├── DeclarativeImperative.xcplaygroundpage │ │ └── Contents.swift │ ├── Protocols.xcplaygroundpage │ │ └── Contents.swift │ └── Collections.xcplaygroundpage │ │ └── Contents.swift │ └── Resources │ └── Ch01-Introduction.playground │ ├── Pages │ ├── Immutability.xcplaygroundpage │ │ └── Contents.swift │ ├── LazyEvaluation.xcplaygroundpage │ │ └── Contents.swift │ ├── Initialization.xcplaygroundpage │ │ └── Contents.swift │ ├── Methods.xcplaygroundpage │ │ └── Contents.swift │ ├── Tuples.xcplaygroundpage │ │ └── Contents.swift │ ├── ARC.xcplaygroundpage │ │ └── Contents.swift │ ├── Generics.xcplaygroundpage │ │ └── Contents.swift │ ├── Subscripts.xcplaygroundpage │ │ └── Contents.swift │ ├── ErrorHandling.xcplaygroundpage │ │ └── Contents.swift │ ├── Types.xcplaygroundpage │ │ └── Contents.swift │ ├── DeclarativeImperative.xcplaygroundpage │ │ └── Contents.swift │ └── Protocols.xcplaygroundpage │ │ └── Contents.swift │ └── Resources │ └── Ch01-Introduction.playground │ ├── Pages │ ├── Immutability.xcplaygroundpage │ │ └── Contents.swift │ ├── LazyEvaluation.xcplaygroundpage │ │ └── Contents.swift │ ├── Initialization.xcplaygroundpage │ │ └── Contents.swift │ ├── Methods.xcplaygroundpage │ │ └── Contents.swift │ ├── Tuples.xcplaygroundpage │ │ └── Contents.swift │ ├── ARC.xcplaygroundpage │ │ └── Contents.swift │ ├── Generics.xcplaygroundpage │ │ └── Contents.swift │ ├── Subscripts.xcplaygroundpage │ │ └── Contents.swift │ ├── ErrorHandling.xcplaygroundpage │ │ └── Contents.swift │ ├── Types.xcplaygroundpage │ │ └── Contents.swift │ ├── DeclarativeImperative.xcplaygroundpage │ │ └── Contents.swift │ └── Protocols.xcplaygroundpage │ │ └── Contents.swift │ └── Resources │ └── Ch01-Introduction.playground │ ├── Pages │ ├── Immutability.xcplaygroundpage │ │ └── Contents.swift │ ├── LazyEvaluation.xcplaygroundpage │ │ └── Contents.swift │ ├── Initialization.xcplaygroundpage │ │ └── Contents.swift │ ├── Methods.xcplaygroundpage │ │ └── Contents.swift │ ├── Tuples.xcplaygroundpage │ │ └── Contents.swift │ ├── ARC.xcplaygroundpage │ │ └── Contents.swift │ ├── Generics.xcplaygroundpage │ │ └── Contents.swift │ ├── Subscripts.xcplaygroundpage │ │ └── Contents.swift │ ├── ErrorHandling.xcplaygroundpage │ │ └── Contents.swift │ ├── Types.xcplaygroundpage │ │ └── Contents.swift │ ├── DeclarativeImperative.xcplaygroundpage │ │ └── Contents.swift │ └── Protocols.xcplaygroundpage │ │ └── Contents.swift │ └── Resources │ └── Ch01-Introduction.playground │ ├── Pages │ ├── Immutability.xcplaygroundpage │ │ └── Contents.swift │ ├── LazyEvaluation.xcplaygroundpage │ │ └── Contents.swift │ ├── Initialization.xcplaygroundpage │ │ └── Contents.swift │ ├── Methods.xcplaygroundpage │ │ └── Contents.swift │ ├── Tuples.xcplaygroundpage │ │ └── Contents.swift │ ├── ARC.xcplaygroundpage │ │ └── Contents.swift │ ├── Generics.xcplaygroundpage │ │ └── Contents.swift │ ├── Subscripts.xcplaygroundpage │ │ └── Contents.swift │ ├── ErrorHandling.xcplaygroundpage │ │ └── Contents.swift │ ├── Types.xcplaygroundpage │ │ └── Contents.swift │ └── DeclarativeImperative.xcplaygroundpage │ │ └── Contents.swift │ └── Resources │ └── Ch01-Introduction.playground │ ├── Pages │ ├── Immutability.xcplaygroundpage │ │ └── Contents.swift │ ├── LazyEvaluation.xcplaygroundpage │ │ └── Contents.swift │ ├── Initialization.xcplaygroundpage │ │ └── Contents.swift │ ├── Methods.xcplaygroundpage │ │ └── Contents.swift │ ├── Tuples.xcplaygroundpage │ │ └── Contents.swift │ ├── ARC.xcplaygroundpage │ │ └── Contents.swift │ ├── Generics.xcplaygroundpage │ │ └── Contents.swift │ ├── ErrorHandling.xcplaygroundpage │ │ └── Contents.swift │ ├── Subscripts.xcplaygroundpage │ │ └── Contents.swift │ ├── Types.xcplaygroundpage │ │ └── Contents.swift │ └── DeclarativeImperative.xcplaygroundpage │ │ └── Contents.swift │ └── Resources │ └── Ch01-Introduction.playground │ ├── Pages │ ├── Immutability.xcplaygroundpage │ │ └── Contents.swift │ ├── LazyEvaluation.xcplaygroundpage │ │ └── Contents.swift │ ├── Initialization.xcplaygroundpage │ │ └── Contents.swift │ ├── Methods.xcplaygroundpage │ │ └── Contents.swift │ ├── Tuples.xcplaygroundpage │ │ └── Contents.swift │ ├── ARC.xcplaygroundpage │ │ └── Contents.swift │ ├── Generics.xcplaygroundpage │ │ └── Contents.swift │ ├── Subscripts.xcplaygroundpage │ │ └── Contents.swift │ ├── ErrorHandling.xcplaygroundpage │ │ └── Contents.swift │ ├── Types.xcplaygroundpage │ │ └── Contents.swift │ └── DeclarativeImperative.xcplaygroundpage │ │ └── Contents.swift │ └── Resources │ └── Ch01-Introduction.playground │ ├── Pages │ ├── Immutability.xcplaygroundpage │ │ └── Contents.swift │ ├── LazyEvaluation.xcplaygroundpage │ │ └── Contents.swift │ ├── Initialization.xcplaygroundpage │ │ └── Contents.swift │ ├── Methods.xcplaygroundpage │ │ └── Contents.swift │ ├── Tuples.xcplaygroundpage │ │ └── Contents.swift │ ├── ARC.xcplaygroundpage │ │ └── Contents.swift │ ├── Generics.xcplaygroundpage │ │ └── Contents.swift │ ├── Subscripts.xcplaygroundpage │ │ └── Contents.swift │ ├── ErrorHandling.xcplaygroundpage │ │ └── Contents.swift │ ├── Types.xcplaygroundpage │ │ └── Contents.swift │ └── DeclarativeImperative.xcplaygroundpage │ │ └── Contents.swift │ └── Resources │ └── Ch01-Introduction.playground │ ├── Pages │ ├── Immutability.xcplaygroundpage │ │ └── Contents.swift │ ├── LazyEvaluation.xcplaygroundpage │ │ └── Contents.swift │ ├── Initialization.xcplaygroundpage │ │ └── Contents.swift │ ├── Methods.xcplaygroundpage │ │ └── Contents.swift │ ├── Tuples.xcplaygroundpage │ │ └── Contents.swift │ ├── ARC.xcplaygroundpage │ │ └── Contents.swift │ ├── Generics.xcplaygroundpage │ │ └── Contents.swift │ ├── Subscripts.xcplaygroundpage │ │ └── Contents.swift │ ├── ErrorHandling.xcplaygroundpage │ │ └── Contents.swift │ └── Types.xcplaygroundpage │ │ └── Contents.swift │ └── Resources │ └── Ch01-Introduction.playground │ ├── Pages │ ├── Immutability.xcplaygroundpage │ │ └── Contents.swift │ ├── LazyEvaluation.xcplaygroundpage │ │ └── Contents.swift │ ├── Initialization.xcplaygroundpage │ │ └── Contents.swift │ ├── Methods.xcplaygroundpage │ │ └── Contents.swift │ ├── Tuples.xcplaygroundpage │ │ └── Contents.swift │ ├── ARC.xcplaygroundpage │ │ └── Contents.swift │ ├── Generics.xcplaygroundpage │ │ └── Contents.swift │ ├── Subscripts.xcplaygroundpage │ │ └── Contents.swift │ └── ErrorHandling.xcplaygroundpage │ │ └── Contents.swift │ └── Resources │ └── Ch01-Introduction.playground │ ├── Pages │ ├── Immutability.xcplaygroundpage │ │ └── Contents.swift │ ├── LazyEvaluation.xcplaygroundpage │ │ └── Contents.swift │ ├── Initialization.xcplaygroundpage │ │ └── Contents.swift │ ├── Methods.xcplaygroundpage │ │ └── Contents.swift │ ├── Tuples.xcplaygroundpage │ │ └── Contents.swift │ ├── ARC.xcplaygroundpage │ │ └── Contents.swift │ ├── Generics.xcplaygroundpage │ │ └── Contents.swift │ ├── ErrorHandling.xcplaygroundpage │ │ └── Contents.swift │ └── Subscripts.xcplaygroundpage │ │ └── Contents.swift │ └── Resources │ └── Ch01-Introduction.playground │ ├── Pages │ ├── Immutability.xcplaygroundpage │ │ └── Contents.swift │ ├── LazyEvaluation.xcplaygroundpage │ │ └── Contents.swift │ ├── Initialization.xcplaygroundpage │ │ └── Contents.swift │ ├── Methods.xcplaygroundpage │ │ └── Contents.swift │ ├── Tuples.xcplaygroundpage │ │ └── Contents.swift │ ├── ARC.xcplaygroundpage │ │ └── Contents.swift │ └── Generics.xcplaygroundpage │ │ └── Contents.swift │ └── Resources │ └── Ch01-Introduction.playground │ ├── Pages │ ├── Immutability.xcplaygroundpage │ │ └── Contents.swift │ ├── LazyEvaluation.xcplaygroundpage │ │ └── Contents.swift │ ├── Initialization.xcplaygroundpage │ │ └── Contents.swift │ ├── Methods.xcplaygroundpage │ │ └── Contents.swift │ └── Tuples.xcplaygroundpage │ │ └── Contents.swift │ └── Resources │ └── Ch01-Introduction.playground │ ├── Pages │ ├── Immutability.xcplaygroundpage │ │ └── Contents.swift │ ├── LazyEvaluation.xcplaygroundpage │ │ └── Contents.swift │ ├── Initialization.xcplaygroundpage │ │ └── Contents.swift │ └── Methods.xcplaygroundpage │ │ └── Contents.swift │ └── Resources │ └── Ch01-Introduction.playground │ └── Pages │ └── Immutability.xcplaygroundpage │ └── Contents.swift ├── Ch09-ImportanceOfImmutability.playground ├── Pages │ ├── TableOfContents.xcplaygroundpage │ │ └── Contents.swift │ └── FunctionalExample.xcplaygroundpage │ │ └── Contents.swift └── contents.xcplayground ├── Ch04-EnumsPatternMatching.playground ├── Pages │ └── TableOfContents.xcplaygroundpage │ │ └── Contents.swift └── contents.xcplayground ├── Ch08-FunctionalDataStructures.playground ├── Pages │ └── TableOfContents.xcplaygroundpage │ │ └── Contents.swift └── contents.xcplayground ├── Ch06-MapFilterReduce.playground ├── Pages │ ├── Zip.xcplaygroundpage │ │ └── Contents.swift │ ├── Joined.xcplaygroundpage │ │ └── Contents.swift │ ├── Apply.xcplaygroundpage │ │ └── Contents.swift │ ├── TableOfContents.xcplaygroundpage │ │ └── Contents.swift │ ├── Higher-KindedTypes.xcplaygroundpage │ │ └── Contents.swift │ ├── ChainingHigherOrderFuncs.xcplaygroundpage │ │ └── Contents.swift │ ├── Join.xcplaygroundpage │ │ └── Contents.swift │ ├── FlatMap.xcplaygroundpage │ │ └── Contents.swift │ └── Filter.xcplaygroundpage │ │ └── Contents.swift └── contents.xcplayground ├── Ch02-FuncsClosures.playground ├── Pages │ ├── FirstClassFunctions.xcplaygroundpage │ │ └── Contents.swift │ ├── NestedFunctions.xcplaygroundpage │ │ └── Contents.swift │ ├── TailRecursion.xcplaygroundpage │ │ └── Contents.swift │ ├── CapturingValues.xcplaygroundpage │ │ └── Contents.swift │ └── TableOfContents.xcplaygroundpage │ │ └── Contents.swift └── contents.xcplayground ├── Ch05-Generics.playground ├── Pages │ ├── SubclassingGenericClasses.xcplaygroundpage │ │ └── Contents.swift │ ├── TableOfContents.xcplaygroundpage │ │ └── Contents.swift │ └── ExtendingGenericTypes.xcplaygroundpage │ │ └── Contents.swift └── contents.xcplayground ├── Ch07-Optionals.playground ├── Pages │ ├── ImplicitlyUnwrappedOptionals.xcplaygroundpage │ │ └── Contents.swift │ ├── TableOfContents.xcplaygroundpage │ │ └── Contents.swift │ ├── OptionalChaining.xcplaygroundpage │ │ └── Contents.swift │ ├── Definition.xcplaygroundpage │ │ └── Contents.swift │ └── Guard.xcplaygroundpage │ │ └── Contents.swift └── contents.xcplayground └── Ch03-Types.playground ├── Pages ├── TypeCheckingCasting.xcplaygroundpage │ └── Contents.swift ├── TableOfContents.xcplaygroundpage │ └── Contents.swift ├── MixingValueReferenceTypes.xcplaygroundpage │ └── Contents.swift ├── Copying.xcplaygroundpage │ └── Contents.swift └── EqualityVsIdentity.xcplaygroundpage │ └── Contents.swift └── contents.xcplayground /Ch11-Backend/vapor-example/.swift-version: -------------------------------------------------------------------------------- 1 | system -------------------------------------------------------------------------------- /Ch11-Backend/vapor-example/Config/secrets/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Ch11-Backend/vapor-example/Config/secrets/app.json: -------------------------------------------------------------------------------- 1 | { 2 | "key": "secret-key" 3 | } -------------------------------------------------------------------------------- /Ch11-Backend/vapor-example/Procfile: -------------------------------------------------------------------------------- 1 | web: App --env=production --workdir="./" 2 | -------------------------------------------------------------------------------- /Ch11-Backend/vapor-example/.gitignore: -------------------------------------------------------------------------------- 1 | Packages 2 | .build 3 | xcuserdata 4 | *.xcodeproj 5 | -------------------------------------------------------------------------------- /Ch11-Backend/vapor-example/Config/development/app.json: -------------------------------------------------------------------------------- 1 | { 2 | "key": "development-key" 3 | } -------------------------------------------------------------------------------- /Ch11-Backend/vapor-example/Config/production/app.json: -------------------------------------------------------------------------------- 1 | { 2 | "key": "$VAPOR_APP_KEY" 3 | } -------------------------------------------------------------------------------- /Ch11-Backend/vapor-example/Config/app.json: -------------------------------------------------------------------------------- 1 | { 2 | "key": "default-key", 3 | "foo": "bar" 4 | } -------------------------------------------------------------------------------- /Ch11-Backend/vapor-example/Config/production/servers.json: -------------------------------------------------------------------------------- 1 | { 2 | "production": { 3 | "port": "$PORT" 4 | } 5 | } -------------------------------------------------------------------------------- /Ch11-Backend/vapor-example/Resources/Views/template.leaf: -------------------------------------------------------------------------------- 1 | #embed("embeds/header") 2 | 3 |

#(greeting)

4 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/Target Support Files/Argo/Argo-prefix.pch: -------------------------------------------------------------------------------- 1 | #ifdef __OBJC__ 2 | #import 3 | #endif 4 | 5 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/Target Support Files/Curry/Curry-prefix.pch: -------------------------------------------------------------------------------- 1 | #ifdef __OBJC__ 2 | #import 3 | #endif 4 | 5 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/Target Support Files/Delta/Delta-prefix.pch: -------------------------------------------------------------------------------- 1 | #ifdef __OBJC__ 2 | #import 3 | #endif 4 | 5 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/Target Support Files/Result/Result-prefix.pch: -------------------------------------------------------------------------------- 1 | #ifdef __OBJC__ 2 | #import 3 | #endif 4 | 5 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/Target Support Files/Runes/Runes-prefix.pch: -------------------------------------------------------------------------------- 1 | #ifdef __OBJC__ 2 | #import 3 | #endif 4 | 5 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/Target Support Files/Alamofire/Alamofire-prefix.pch: -------------------------------------------------------------------------------- 1 | #ifdef __OBJC__ 2 | #import 3 | #endif 4 | 5 | -------------------------------------------------------------------------------- /Ch11-Backend/vapor-example/Config/servers.json: -------------------------------------------------------------------------------- 1 | { 2 | "default": { 3 | "port": 8080, 4 | "host": "0.0.0.0", 5 | "securityLayer": "none" 6 | } 7 | } -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/Target Support Files/ReactiveCocoa/ReactiveCocoa-prefix.pch: -------------------------------------------------------------------------------- 1 | #ifdef __OBJC__ 2 | #import 3 | #endif 4 | 5 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/Target Support Files/ReactiveSwift/ReactiveSwift-prefix.pch: -------------------------------------------------------------------------------- 1 | #ifdef __OBJC__ 2 | #import 3 | #endif 4 | 5 | -------------------------------------------------------------------------------- /Ch11-Backend/vapor-example/Localization/en.json: -------------------------------------------------------------------------------- 1 | { 2 | "welcome": { 3 | "title": "Welcome to Vapor!", 4 | "body": "A web framework for Swift." 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /Ch11-Backend/vapor-example/Resources/Views/embeds/header.leaf: -------------------------------------------------------------------------------- 1 | 2 | 7 | -------------------------------------------------------------------------------- /Ch11-Backend/vapor-example/Localization/es.json: -------------------------------------------------------------------------------- 1 | { 2 | "welcome": { 3 | "title": "¡Bienvenidos a Vapor!", 4 | "body": "Un framework web de Swift." 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /Ch11-Backend/vapor-example/Public/images/vapor-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Swift-3-Functional-Programming/HEAD/Ch11-Backend/vapor-example/Public/images/vapor-logo.png -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/Target Support Files/Argo/Argo.modulemap: -------------------------------------------------------------------------------- 1 | framework module Argo { 2 | umbrella header "Argo-umbrella.h" 3 | 4 | export * 5 | module * { export * } 6 | } 7 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/Target Support Files/Curry/Curry.modulemap: -------------------------------------------------------------------------------- 1 | framework module Curry { 2 | umbrella header "Curry-umbrella.h" 3 | 4 | export * 5 | module * { export * } 6 | } 7 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/Target Support Files/Delta/Delta.modulemap: -------------------------------------------------------------------------------- 1 | framework module Delta { 2 | umbrella header "Delta-umbrella.h" 3 | 4 | export * 5 | module * { export * } 6 | } 7 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/Target Support Files/Runes/Runes.modulemap: -------------------------------------------------------------------------------- 1 | framework module Runes { 2 | umbrella header "Runes-umbrella.h" 3 | 4 | export * 5 | module * { export * } 6 | } 7 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/Target Support Files/Argo/Argo-dummy.m: -------------------------------------------------------------------------------- 1 | #import 2 | @interface PodsDummy_Argo : NSObject 3 | @end 4 | @implementation PodsDummy_Argo 5 | @end 6 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/Target Support Files/Result/Result.modulemap: -------------------------------------------------------------------------------- 1 | framework module Result { 2 | umbrella header "Result-umbrella.h" 3 | 4 | export * 5 | module * { export * } 6 | } 7 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/ReactiveCocoa/ReactiveCocoa/NSObject+ReactiveExtensionsProvider.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | import ReactiveSwift 3 | 4 | extension NSObject: ReactiveExtensionsProvider {} 5 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/Target Support Files/Curry/Curry-dummy.m: -------------------------------------------------------------------------------- 1 | #import 2 | @interface PodsDummy_Curry : NSObject 3 | @end 4 | @implementation PodsDummy_Curry 5 | @end 6 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/Target Support Files/Delta/Delta-dummy.m: -------------------------------------------------------------------------------- 1 | #import 2 | @interface PodsDummy_Delta : NSObject 3 | @end 4 | @implementation PodsDummy_Delta 5 | @end 6 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/Target Support Files/Runes/Runes-dummy.m: -------------------------------------------------------------------------------- 1 | #import 2 | @interface PodsDummy_Runes : NSObject 3 | @end 4 | @implementation PodsDummy_Runes 5 | @end 6 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/Target Support Files/Result/Result-dummy.m: -------------------------------------------------------------------------------- 1 | #import 2 | @interface PodsDummy_Result : NSObject 3 | @end 4 | @implementation PodsDummy_Result 5 | @end 6 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/Target Support Files/Alamofire/Alamofire.modulemap: -------------------------------------------------------------------------------- 1 | framework module Alamofire { 2 | umbrella header "Alamofire-umbrella.h" 3 | 4 | export * 5 | module * { export * } 6 | } 7 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/Target Support Files/Alamofire/Alamofire-dummy.m: -------------------------------------------------------------------------------- 1 | #import 2 | @interface PodsDummy_Alamofire : NSObject 3 | @end 4 | @implementation PodsDummy_Alamofire 5 | @end 6 | -------------------------------------------------------------------------------- /Ch11-Backend/vapor-example/Localization/default.json: -------------------------------------------------------------------------------- 1 | { 2 | "welcome": { 3 | "title": "Default Welcome Message", 4 | "body": "Default welcome body." 5 | }, 6 | "other-key": "example" 7 | } 8 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/Target Support Files/Pods-TodoApp/Pods-TodoApp.modulemap: -------------------------------------------------------------------------------- 1 | framework module Pods_TodoApp { 2 | umbrella header "Pods-TodoApp-umbrella.h" 3 | 4 | export * 5 | module * { export * } 6 | } 7 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/Argo/Sources/Argo/Extensions/NSNumber.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | extension NSNumber { 4 | var isBool: Bool { 5 | return type(of: self) == type(of: NSNumber(value: true)) 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/Target Support Files/ReactiveSwift/ReactiveSwift.modulemap: -------------------------------------------------------------------------------- 1 | framework module ReactiveSwift { 2 | umbrella header "ReactiveSwift-umbrella.h" 3 | 4 | export * 5 | module * { export * } 6 | } 7 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/Target Support Files/Pods-TodoApp/Pods-TodoApp-dummy.m: -------------------------------------------------------------------------------- 1 | #import 2 | @interface PodsDummy_Pods_TodoApp : NSObject 3 | @end 4 | @implementation PodsDummy_Pods_TodoApp 5 | @end 6 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/Target Support Files/ReactiveCocoa/ReactiveCocoa-dummy.m: -------------------------------------------------------------------------------- 1 | #import 2 | @interface PodsDummy_ReactiveCocoa : NSObject 3 | @end 4 | @implementation PodsDummy_ReactiveCocoa 5 | @end 6 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/Target Support Files/ReactiveSwift/ReactiveSwift-dummy.m: -------------------------------------------------------------------------------- 1 | #import 2 | @interface PodsDummy_ReactiveSwift : NSObject 3 | @end 4 | @implementation PodsDummy_ReactiveSwift 5 | @end 6 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/ReactiveCocoa/ReactiveCocoa/module.modulemap: -------------------------------------------------------------------------------- 1 | framework module ReactiveCocoa { 2 | umbrella header "ReactiveCocoa.h" 3 | private header "ObjCRuntimeAliases.h" 4 | 5 | export * 6 | module * { export * } 7 | } 8 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/Target Support Files/Pods-TodoAppTests/Pods-TodoAppTests.modulemap: -------------------------------------------------------------------------------- 1 | framework module Pods_TodoAppTests { 2 | umbrella header "Pods-TodoAppTests-umbrella.h" 3 | 4 | export * 5 | module * { export * } 6 | } 7 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/Target Support Files/Argo/Argo-umbrella.h: -------------------------------------------------------------------------------- 1 | #ifdef __OBJC__ 2 | #import 3 | #endif 4 | 5 | 6 | FOUNDATION_EXPORT double ArgoVersionNumber; 7 | FOUNDATION_EXPORT const unsigned char ArgoVersionString[]; 8 | 9 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/Target Support Files/Pods-TodoAppTests/Pods-TodoAppTests-dummy.m: -------------------------------------------------------------------------------- 1 | #import 2 | @interface PodsDummy_Pods_TodoAppTests : NSObject 3 | @end 4 | @implementation PodsDummy_Pods_TodoAppTests 5 | @end 6 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/Target Support Files/Curry/Curry-umbrella.h: -------------------------------------------------------------------------------- 1 | #ifdef __OBJC__ 2 | #import 3 | #endif 4 | 5 | 6 | FOUNDATION_EXPORT double CurryVersionNumber; 7 | FOUNDATION_EXPORT const unsigned char CurryVersionString[]; 8 | 9 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/Target Support Files/Pods-TodoAppTests/Pods-TodoAppTests-acknowledgements.markdown: -------------------------------------------------------------------------------- 1 | # Acknowledgements 2 | This application makes use of the following third party libraries: 3 | Generated by CocoaPods - https://cocoapods.org 4 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/Target Support Files/ReactiveCocoa/ReactiveCocoa.modulemap: -------------------------------------------------------------------------------- 1 | framework module ReactiveCocoa { 2 | umbrella header "ReactiveCocoa.h" 3 | private header "ObjCRuntimeAliases.h" 4 | 5 | export * 6 | module * { export * } 7 | } 8 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/Target Support Files/Runes/Runes-umbrella.h: -------------------------------------------------------------------------------- 1 | #ifdef __OBJC__ 2 | #import 3 | #endif 4 | 5 | 6 | FOUNDATION_EXPORT double RunesVersionNumber; 7 | FOUNDATION_EXPORT const unsigned char RunesVersionString[]; 8 | 9 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/Target Support Files/Result/Result-umbrella.h: -------------------------------------------------------------------------------- 1 | #ifdef __OBJC__ 2 | #import 3 | #endif 4 | 5 | 6 | FOUNDATION_EXPORT double ResultVersionNumber; 7 | FOUNDATION_EXPORT const unsigned char ResultVersionString[]; 8 | 9 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/TodoApp.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Playgrounds/Ch10-BestOfBothWorlds.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/Target Support Files/Alamofire/Alamofire-umbrella.h: -------------------------------------------------------------------------------- 1 | #ifdef __OBJC__ 2 | #import 3 | #endif 4 | 5 | 6 | FOUNDATION_EXPORT double AlamofireVersionNumber; 7 | FOUNDATION_EXPORT const unsigned char AlamofireVersionString[]; 8 | 9 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/Target Support Files/Pods-TodoApp/Pods-TodoApp-umbrella.h: -------------------------------------------------------------------------------- 1 | #ifdef __OBJC__ 2 | #import 3 | #endif 4 | 5 | 6 | FOUNDATION_EXPORT double Pods_TodoAppVersionNumber; 7 | FOUNDATION_EXPORT const unsigned char Pods_TodoAppVersionString[]; 8 | 9 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/Target Support Files/Delta/Delta-umbrella.h: -------------------------------------------------------------------------------- 1 | #ifdef __OBJC__ 2 | #import 3 | #endif 4 | 5 | #import "Delta.h" 6 | 7 | FOUNDATION_EXPORT double DeltaVersionNumber; 8 | FOUNDATION_EXPORT const unsigned char DeltaVersionString[]; 9 | 10 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/Target Support Files/ReactiveSwift/ReactiveSwift-umbrella.h: -------------------------------------------------------------------------------- 1 | #ifdef __OBJC__ 2 | #import 3 | #endif 4 | 5 | 6 | FOUNDATION_EXPORT double ReactiveSwiftVersionNumber; 7 | FOUNDATION_EXPORT const unsigned char ReactiveSwiftVersionString[]; 8 | 9 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/ReactiveCocoa/ReactiveCocoa/Deprecations+Removals.swift: -------------------------------------------------------------------------------- 1 | import ReactiveSwift 2 | 3 | extension Action { 4 | @available(*, unavailable, message:"Use the `CocoaAction` initializers instead.") 5 | public var unsafeCocoaAction: CocoaAction { fatalError() } 6 | } 7 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/ReactiveCocoa/ReactiveCocoa/UIKit/UITableView.swift: -------------------------------------------------------------------------------- 1 | import ReactiveSwift 2 | import UIKit 3 | 4 | extension Reactive where Base: UITableView { 5 | public var reloadData: BindingTarget<()> { 6 | return makeBindingTarget { base, _ in base.reloadData() } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/TodoApp/Actions/SetFilterAction.swift: -------------------------------------------------------------------------------- 1 | import Delta 2 | 3 | struct SetFilterAction: ActionType { 4 | let filter: TodoFilter 5 | 6 | func reduce(state: State) -> State { 7 | state.filter.value = filter 8 | return state 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/Target Support Files/Pods-TodoAppTests/Pods-TodoAppTests-umbrella.h: -------------------------------------------------------------------------------- 1 | #ifdef __OBJC__ 2 | #import 3 | #endif 4 | 5 | 6 | FOUNDATION_EXPORT double Pods_TodoAppTestsVersionNumber; 7 | FOUNDATION_EXPORT const unsigned char Pods_TodoAppTestsVersionString[]; 8 | 9 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/ReactiveCocoa/ReactiveCocoa/UIKit/UICollectionView.swift: -------------------------------------------------------------------------------- 1 | import ReactiveSwift 2 | import UIKit 3 | 4 | extension Reactive where Base: UICollectionView { 5 | public var reloadData: BindingTarget<()> { 6 | return makeBindingTarget { base, _ in base.reloadData() } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Ch11-Backend/vapor-example/app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vapor-example", 3 | "scripts": {}, 4 | "env": {}, 5 | "formation": {}, 6 | "addons": [], 7 | "buildpacks": [ 8 | { 9 | "url": "https://github.com/kylef/heroku-buildpack-swift" 10 | } 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/TodoApp/Models/TodoViewModel.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TodoViewModel.swift 3 | // TodoApp 4 | // 5 | // Created by Fatih Nayebi on 2016-04-29. 6 | // Copyright © 2016 Fatih Nayebi. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | struct TodoViewModel { 12 | let todo: Todo? 13 | } 14 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Pages/Immutability.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Immutability vs. Mutability 6 | 7 | var aMutableString = "This is a variable String" 8 | let aConstString = "This is a constant String" 9 | 10 | //: [Next](@next) 11 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/TodoApp.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Playgrounds/Ch09-ImportanceOfImmutability.playground/Pages/TableOfContents.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | /*: Markdown documentation 2 | 3 | ### Table of contents 4 | * [Definition](Definition) 5 | * [Functional Example](FunctionalExample) 6 | * [Copy Constructor](CopyConstructor) 7 | * [Lens](Lens) 8 | */ 9 | 10 | 11 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/ReactiveCocoa/ReactiveCocoa/ReactiveCocoa.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | //! Project version number for ReactiveCocoa. 4 | FOUNDATION_EXPORT double ReactiveCocoaVersionNumber; 5 | 6 | //! Project version string for ReactiveCocoa. 7 | FOUNDATION_EXPORT const unsigned char ReactiveCocoaVersionString[]; 8 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/TodoApp/Actions/DeleteTodoAction.swift: -------------------------------------------------------------------------------- 1 | import Delta 2 | 3 | struct DeleteTodoAction: ActionType { 4 | let todo: Todo 5 | 6 | func reduce(state: State) -> State { 7 | state.todos.value = state.todos.value.filter { $0 != self.todo } 8 | 9 | return state 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Podfile: -------------------------------------------------------------------------------- 1 | platform :ios, ‘9.0’ 2 | use_frameworks! 3 | 4 | target 'TodoApp' do 5 | pod 'Alamofire', '~> 4.0' 6 | pod 'Argo' 7 | pod 'Curry' 8 | pod 'ReactiveCocoa', '~> 5.0.0' 9 | pod 'Delta', :git => "https://github.com/conqueror/Delta.git" 10 | end 11 | 12 | target 'TodoAppTests' do 13 | 14 | end 15 | 16 | -------------------------------------------------------------------------------- /Playgrounds/Ch04-EnumsPatternMatching.playground/Pages/TableOfContents.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | 2 | /*: Markdown documentation 3 | 4 | ### Table of contents 5 | * [Definition](Definition) 6 | * [Algebraic Data Types](AlgebraicDataTypes) 7 | * [Pattern Matching](PatternMatching) 8 | * [Patterns](Patterns) 9 | 10 | */ 11 | -------------------------------------------------------------------------------- /Playgrounds/Ch08-FunctionalDataStructures.playground/Pages/TableOfContents.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | /*: Markdown documentation 2 | 3 | ### Table of contents 4 | * [Semigroup](Semigroup) 5 | * [Monoid](Monoid) 6 | * [Trees](Trees) 7 | * [Linked List](LinkedList) 8 | * [Stack](Stack) 9 | * [Lazy List](LazyList) 10 | */ 11 | 12 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Pages/LazyEvaluation.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | //: ### Lazy evaluation 3 | 4 | import Foundation 5 | 6 | let oneToFour = [1, 2, 3, 4] 7 | let firstNumber = oneToFour.lazy.map({ $0 * 3}).first! 8 | print(firstNumber) // The result is going to be 3 9 | //: [Next](@next) 10 | -------------------------------------------------------------------------------- /Playgrounds/Ch06-MapFilterReduce.playground/Pages/Zip.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | let numbers = [3, 5, 9, 10] 6 | let alphabeticNumbers = ["Three", "Five", "Nine", "Ten"] 7 | 8 | let zipped = zip(alphabeticNumbers, numbers).map { $0 } 9 | 10 | zipped 11 | 12 | //: [Next](@next) 13 | -------------------------------------------------------------------------------- /Ch11-Backend/vapor-example/VaporApp.xcodeproj/Configs/Project.xcconfig: -------------------------------------------------------------------------------- 1 | PRODUCT_NAME = $(TARGET_NAME) 2 | SUPPORTED_PLATFORMS = macosx iphoneos iphonesimulator appletvos appletvsimulator watchos watchsimulator 3 | MACOSX_DEPLOYMENT_TARGET = 10.10 4 | DYLIB_INSTALL_NAME_BASE = @rpath 5 | OTHER_SWIFT_FLAGS = -DXcode 6 | COMBINE_HIDPI_IMAGES = YES 7 | USE_HEADERMAP = NO 8 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Pages/Initialization.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Initialization 6 | 7 | class ShoppingItem { 8 | var name: String? 9 | var quantity = 1 10 | var purchased = false 11 | } 12 | 13 | var item = ShoppingItem() 14 | 15 | //: [Next](@next) 16 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/ReactiveCocoa/ReactiveCocoa/UIKit/UIProgressView.swift: -------------------------------------------------------------------------------- 1 | import ReactiveSwift 2 | import UIKit 3 | 4 | extension Reactive where Base: UIProgressView { 5 | /// Sets the relative progress to be reflected by the progress view. 6 | public var progress: BindingTarget { 7 | return makeBindingTarget { $0.progress = $1 } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Immutability.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Immutability vs. Mutability 6 | 7 | var aMutableString = "This is a variable String" 8 | let aConstString = "This is a constant String" 9 | 10 | //: [Next](@next) 11 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Pages/Methods.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Methods 6 | 7 | class AClass { 8 | class func someTypeMethod() { 9 | // type method body 10 | } 11 | } 12 | 13 | // We can call this method as follows: 14 | AClass.someTypeMethod() 15 | 16 | //: [Next](@next) 17 | -------------------------------------------------------------------------------- /Ch11-Backend/vapor-example/.travis.yml: -------------------------------------------------------------------------------- 1 | os: 2 | - linux 3 | - osx 4 | language: generic 5 | sudo: required 6 | dist: trusty 7 | osx_image: xcode8 8 | install: 9 | - eval "$(curl -sL https://gist.githubusercontent.com/kylef/5c0475ff02b7c7671d2a/raw/02090c7ede5a637b76e6df1710e83cd0bbe7dcdf/swiftenv-install.sh)" 10 | script: 11 | - swift build 12 | - swift build -c release 13 | -------------------------------------------------------------------------------- /Ch11-Backend/vapor-example/VaporApp.xcodeproj/xcshareddata/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | SchemeUserState 5 | 6 | VaporApp.xcscheme 7 | 8 | 9 | SuppressBuildableAutocreation 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/LazyEvaluation.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | //: ### Lazy evaluation 3 | 4 | import Foundation 5 | 6 | let oneToFour = [1, 2, 3, 4] 7 | let firstNumber = oneToFour.lazy.map({ $0 * 3}).first! 8 | print(firstNumber) // The result is going to be 3 9 | //: [Next](@next) 10 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/TodoApp/Actions/ClearCompletedTodosAction.swift: -------------------------------------------------------------------------------- 1 | import Delta 2 | 3 | struct ClearCompletedTodosAction: DynamicActionType { 4 | func call() { 5 | let todos = store.completedTodos.first()?.value ?? [] 6 | 7 | todos.forEach { 8 | todo in 9 | store.dispatch(DeleteTodoAction(todo: todo)) 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Initialization.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Initialization 6 | 7 | class ShoppingItem { 8 | var name: String? 9 | var quantity = 1 10 | var purchased = false 11 | } 12 | 13 | var item = ShoppingItem() 14 | 15 | //: [Next](@next) 16 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Immutability.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Immutability vs. Mutability 6 | 7 | var aMutableString = "This is a variable String" 8 | let aConstString = "This is a constant String" 9 | 10 | //: [Next](@next) 11 | -------------------------------------------------------------------------------- /Playgrounds/Ch02-FuncsClosures.playground/Pages/FirstClassFunctions.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | let name: String = "Grace" 6 | 7 | func sayHello(name: String) { 8 | print("Hello, \(name)") 9 | } 10 | 11 | sayHello(name: "Your name") // or 12 | sayHello(name: name) 13 | 14 | var sayHelloFunc = sayHello 15 | 16 | //: [Next](@next) 17 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/ReactiveCocoa/ReactiveCocoa/Shared/NSLayoutConstraint.swift: -------------------------------------------------------------------------------- 1 | import ReactiveSwift 2 | 3 | #if os(macOS) 4 | import AppKit 5 | #else 6 | import UIKit 7 | #endif 8 | 9 | extension Reactive where Base: NSLayoutConstraint { 10 | 11 | /// Sets the constant. 12 | public var constant: BindingTarget { 13 | return makeBindingTarget { $0.constant = $1 } 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/ReactiveCocoa/ReactiveCocoa/UIKit/UIActivityIndicatorView.swift: -------------------------------------------------------------------------------- 1 | import ReactiveSwift 2 | import UIKit 3 | 4 | extension Reactive where Base: UIActivityIndicatorView { 5 | /// Sets whether the activity indicator should be animating. 6 | public var isAnimating: BindingTarget { 7 | return makeBindingTarget { $1 ? $0.startAnimating() : $0.stopAnimating() } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Playgrounds/Ch05-Generics.playground/Pages/SubclassingGenericClasses.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | class Container { 6 | } 7 | 8 | // GenericContainer stays generic 9 | class GenericContainer: Container { 10 | } 11 | 12 | // SpecificContainer becomes a container of Int type 13 | class SpecificContainer: Container { 14 | } 15 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Methods.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Methods 6 | 7 | class AClass { 8 | class func someTypeMethod() { 9 | // type method body 10 | } 11 | } 12 | 13 | // We can call this method as follows: 14 | AClass.someTypeMethod() 15 | 16 | //: [Next](@next) 17 | -------------------------------------------------------------------------------- /Playgrounds/Ch06-MapFilterReduce.playground/Pages/Joined.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | let twoDimensionalArray = [[1, 3, 5], [2, 4, 6]] 6 | 7 | let oneDimArray2 = twoDimensionalArray.joined().map { $0 } 8 | oneDimArray2 9 | 10 | let oneDimensionalArray = twoDimensionalArray.joined().map { $0 + 2 } 11 | print(oneDimensionalArray) 12 | //: [Next](@next) 13 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Pages/Tuples.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Tuples 6 | 7 | let http400Error = (400, "Bad Request") 8 | // http400Error is of type (Int, String), and equals (400, "Bad Request") 9 | 10 | // Decompose a Tuple's content 11 | let (requestStatusCode, requestStatusMessage) = http400Error 12 | 13 | //: [Next](@next) 14 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/ReactiveCocoa/ReactiveCocoa/NSObject+ObjCRuntime.swift: -------------------------------------------------------------------------------- 1 | extension NSObject { 2 | /// The class of the instance reported by the ObjC `-class:` message. 3 | /// 4 | /// - note: `type(of:)` might return the runtime subclass, while this property 5 | /// always returns the original class. 6 | @nonobjc internal var objcClass: AnyClass { 7 | return (self as AnyObject).objcClass 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Pages/ARC.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // ARC 6 | class AClassWithLazyClosure { 7 | lazy var aClosure: (Int, String) -> String = { 8 | [unowned self] (index: Int, stringToProcess: String) -> String in 9 | // closure body goes here 10 | return "" 11 | } 12 | } 13 | 14 | //: [Next](@next) 15 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/LazyEvaluation.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | //: ### Lazy evaluation 3 | 4 | import Foundation 5 | 6 | let oneToFour = [1, 2, 3, 4] 7 | let firstNumber = oneToFour.lazy.map({ $0 * 3}).first! 8 | print(firstNumber) // The result is going to be 3 9 | //: [Next](@next) 10 | -------------------------------------------------------------------------------- /Ch11-Backend/vapor-example/Package.swift: -------------------------------------------------------------------------------- 1 | import PackageDescription 2 | 3 | let package = Package( 4 | name: "VaporApp", 5 | dependencies: [ 6 | .Package(url: "https://github.com/vapor/vapor.git", majorVersion: 1, minor: 3) 7 | ], 8 | exclude: [ 9 | "Config", 10 | "Database", 11 | "Localization", 12 | "Public", 13 | "Resources", 14 | "Tests", 15 | ] 16 | ) 17 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/Delta/Sources/Delta.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | //! Project version number for Delta. 4 | FOUNDATION_EXPORT double DeltaVersionNumber; 5 | 6 | //! Project version string for Delta. 7 | FOUNDATION_EXPORT const unsigned char DeltaVersionString[]; 8 | 9 | // In this header, you should import all the public headers of your framework using statements like #import 10 | 11 | 12 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Pages/Generics.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Generics 6 | 7 | func swapTwoIntegers( a: inout Int, b: inout Int) { 8 | let tempA = a 9 | a = b 10 | b = tempA 11 | } 12 | 13 | func swapTwoValues( a: inout T, b: inout T) { 14 | let tempA = a 15 | a = b 16 | b = tempA 17 | } 18 | 19 | //: [Next](@next) 20 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Initialization.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Initialization 6 | 7 | class ShoppingItem { 8 | var name: String? 9 | var quantity = 1 10 | var purchased = false 11 | } 12 | 13 | var item = ShoppingItem() 14 | 15 | //: [Next](@next) 16 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Immutability.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Immutability vs. Mutability 6 | 7 | var aMutableString = "This is a variable String" 8 | let aConstString = "This is a constant String" 9 | 10 | //: [Next](@next) 11 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/Argo/Sources/Argo/Operators/Argo.swift: -------------------------------------------------------------------------------- 1 | import Runes 2 | 3 | precedencegroup ArgoDecodePrecedence { 4 | associativity: left 5 | higherThan: RunesApplicativeSequencePrecedence 6 | lowerThan: NilCoalescingPrecedence 7 | } 8 | 9 | infix operator <| : ArgoDecodePrecedence 10 | infix operator <|? : ArgoDecodePrecedence 11 | infix operator <|| : ArgoDecodePrecedence 12 | infix operator <||? : ArgoDecodePrecedence 13 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/ReactiveCocoa/ReactiveCocoa/ObjCRuntimeAliases.m: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | const IMP _rac_objc_msgForward = _objc_msgForward; 5 | 6 | void _rac_objc_setAssociatedObject(const void* object, const void* key, id value, objc_AssociationPolicy policy) { 7 | __unsafe_unretained id obj = (__bridge typeof(obj)) object; 8 | objc_setAssociatedObject(obj, key, value, policy); 9 | } 10 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/TodoApp/Models/TodosViewModel.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Todos.swift 3 | // TodoApp 4 | // 5 | // Created by Fatih Nayebi on 2016-04-24. 6 | // Copyright © 2016 Fatih Nayebi. All rights reserved. 7 | // 8 | 9 | import ReactiveCocoa 10 | 11 | struct TodosViewModel { 12 | let todos: [Todo] 13 | 14 | func todoForIndexPath(_ indexPath: IndexPath) -> Todo { 15 | return todos[indexPath.row] 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/Target Support Files/Pods-TodoAppTests/Pods-TodoAppTests.debug.xcconfig: -------------------------------------------------------------------------------- 1 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = NO 2 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 3 | LD_RUNPATH_SEARCH_PATHS = $(inherited) '@executable_path/Frameworks' '@loader_path/Frameworks' 4 | PODS_BUILD_DIR = $BUILD_DIR 5 | PODS_CONFIGURATION_BUILD_DIR = $PODS_BUILD_DIR/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 6 | PODS_ROOT = ${SRCROOT}/Pods 7 | -------------------------------------------------------------------------------- /Playgrounds/Ch02-FuncsClosures.playground/Pages/NestedFunctions.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | func choosePlusMinus(isPlus: Bool) -> (Int, Int) -> Int { 6 | func plus(a: Int, b: Int) -> Int { 7 | return a + b 8 | } 9 | func minus(a: Int, b: Int) -> Int { 10 | return a - b 11 | } 12 | return isPlus ? plus : minus 13 | } 14 | 15 | //: [Next](@next) 16 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/Target Support Files/Pods-TodoAppTests/Pods-TodoAppTests.release.xcconfig: -------------------------------------------------------------------------------- 1 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = NO 2 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 3 | LD_RUNPATH_SEARCH_PATHS = $(inherited) '@executable_path/Frameworks' '@loader_path/Frameworks' 4 | PODS_BUILD_DIR = $BUILD_DIR 5 | PODS_CONFIGURATION_BUILD_DIR = $PODS_BUILD_DIR/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 6 | PODS_ROOT = ${SRCROOT}/Pods 7 | -------------------------------------------------------------------------------- /Playgrounds/Ch06-MapFilterReduce.playground/Pages/Apply.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | func apply(fn: ([T]) -> V, args: [T]) -> V { 6 | return fn(args) 7 | } 8 | 9 | let numbers = [1, 3, 5] 10 | 11 | func incrementValues(a: [Int]) -> [Int] { 12 | return a.map { $0 + 1 } 13 | } 14 | 15 | let applied = apply(fn: incrementValues, args: numbers) 16 | 17 | //: [Next](@next) 18 | -------------------------------------------------------------------------------- /Playgrounds/Ch09-ImportanceOfImmutability.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Tuples.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Tuples 6 | 7 | let http400Error = (400, "Bad Request") 8 | // http400Error is of type (Int, String), and equals (400, "Bad Request") 9 | 10 | // Decompose a Tuple's content 11 | let (requestStatusCode, requestStatusMessage) = http400Error 12 | 13 | //: [Next](@next) 14 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Methods.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Methods 6 | 7 | class AClass { 8 | class func someTypeMethod() { 9 | // type method body 10 | } 11 | } 12 | 13 | // We can call this method as follows: 14 | AClass.someTypeMethod() 15 | 16 | //: [Next](@next) 17 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/LazyEvaluation.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | //: ### Lazy evaluation 3 | 4 | import Foundation 5 | 6 | let oneToFour = [1, 2, 3, 4] 7 | let firstNumber = oneToFour.lazy.map({ $0 * 3}).first! 8 | print(firstNumber) // The result is going to be 3 9 | //: [Next](@next) 10 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/ARC.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // ARC 6 | class AClassWithLazyClosure { 7 | lazy var aClosure: (Int, String) -> String = { 8 | [unowned self] (index: Int, stringToProcess: String) -> String in 9 | // closure body goes here 10 | return "" 11 | } 12 | } 13 | 14 | //: [Next](@next) 15 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Generics.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Generics 6 | 7 | func swapTwoIntegers( a: inout Int, b: inout Int) { 8 | let tempA = a 9 | a = b 10 | b = tempA 11 | } 12 | 13 | func swapTwoValues( a: inout T, b: inout T) { 14 | let tempA = a 15 | a = b 16 | b = tempA 17 | } 18 | 19 | //: [Next](@next) 20 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Initialization.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Initialization 6 | 7 | class ShoppingItem { 8 | var name: String? 9 | var quantity = 1 10 | var purchased = false 11 | } 12 | 13 | var item = ShoppingItem() 14 | 15 | //: [Next](@next) 16 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Immutability.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Immutability vs. Mutability 6 | 7 | var aMutableString = "This is a variable String" 8 | let aConstString = "This is a constant String" 9 | 10 | //: [Next](@next) 11 | -------------------------------------------------------------------------------- /Playgrounds/Ch05-Generics.playground/Pages/TableOfContents.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | /*: Markdown documentation 2 | 3 | ### Table of contents 4 | * [Definition](Definition) 5 | * [Type Constraints](TypeConstraints) 6 | * [Generic Data Structures](GenericDataStructures) 7 | * [Associated Type Protocols](AssociatedTypeProtocols) 8 | * [Extending Generic Types](ExtendingGenericTypes) 9 | * [Subclassing Generic Classes](SubclassingGenericClasses) 10 | */ 11 | 12 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/TodoApp/Actions/LoadTodosAction.swift: -------------------------------------------------------------------------------- 1 | // 2 | // loadTodosAction.swift 3 | // TodoApp 4 | // 5 | // Created by Fatih Nayebi on 2016-04-29. 6 | // Copyright © 2016 Fatih Nayebi. All rights reserved. 7 | // 8 | 9 | import Delta 10 | 11 | struct LoadTodosAction: ActionType { 12 | let todos: [Todo] 13 | 14 | func reduce(state: State) -> State { 15 | state.todos.value = state.todos.value + todos 16 | return state 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Playgrounds/Ch07-Optionals.playground/Pages/ImplicitlyUnwrappedOptionals.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | 6 | let optionalDict: Dictionary? = ["One": 1, "Two": 2, "Three": 3] 7 | let implicitlyUnwrappedDict: Dictionary! = ["One": 1, "Two": 2, "Three": 3] 8 | 9 | let firstValue = optionalDict?["One"] 10 | let implictlyUnwrappedFirstValue = implicitlyUnwrappedDict["One"] 11 | 12 | //: [Next](@next) 13 | -------------------------------------------------------------------------------- /Playgrounds/Ch07-Optionals.playground/Pages/TableOfContents.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | /*: Markdown documentation 2 | 3 | ### Table of contents 4 | * [Definition](Definition) 5 | * [Unwrapping](Unwrapping) 6 | * [Guard](Guard) 7 | * [Implicitly Unwrapped Optionals](ImplicitlyUnwrappedOptionals) 8 | * [Error Handling to Avoid Optionals](ErrorHandlingToAvoidOptionals) 9 | * [Optional Chaining](OptionalChaining) 10 | * [Optional Mapping](OptionalMapping) 11 | */ 12 | 13 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Pages/Subscripts.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Subscripts 6 | 7 | struct TimesTable { 8 | let multiplier: Int 9 | subscript(index: Int) -> Int { 10 | return multiplier * index 11 | } 12 | } 13 | 14 | let fiveTimesTable = TimesTable(multiplier: 5) 15 | print("six times five is \(fiveTimesTable[6])") 16 | // prints "six times five is 30” 17 | 18 | //: [Next](@next) 19 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Tuples.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Tuples 6 | 7 | let http400Error = (400, "Bad Request") 8 | // http400Error is of type (Int, String), and equals (400, "Bad Request") 9 | 10 | // Decompose a Tuple's content 11 | let (requestStatusCode, requestStatusMessage) = http400Error 12 | 13 | //: [Next](@next) 14 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Methods.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Methods 6 | 7 | class AClass { 8 | class func someTypeMethod() { 9 | // type method body 10 | } 11 | } 12 | 13 | // We can call this method as follows: 14 | AClass.someTypeMethod() 15 | 16 | //: [Next](@next) 17 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Pages/ErrorHandling.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Error Protocol 6 | 7 | enum HttpError: Error { 8 | case badRequest 9 | case unauthorized 10 | case forbidden 11 | case requestTimeOut 12 | case unsupportedMediaType 13 | case internalServerError 14 | case notImplemented 15 | case badGateway 16 | case serviceUnavailable 17 | } 18 | 19 | //: [Next](@next) 20 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/ARC.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // ARC 6 | class AClassWithLazyClosure { 7 | lazy var aClosure: (Int, String) -> String = { 8 | [unowned self] (index: Int, stringToProcess: String) -> String in 9 | // closure body goes here 10 | return "" 11 | } 12 | } 13 | 14 | //: [Next](@next) 15 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/LazyEvaluation.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | //: ### Lazy evaluation 3 | 4 | import Foundation 5 | 6 | let oneToFour = [1, 2, 3, 4] 7 | let firstNumber = oneToFour.lazy.map({ $0 * 3}).first! 8 | print(firstNumber) // The result is going to be 3 9 | //: [Next](@next) 10 | -------------------------------------------------------------------------------- /Playgrounds/Ch03-Types.playground/Pages/TypeCheckingCasting.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | let aConstant = "String" 6 | 7 | if aConstant is String { 8 | print("aConstant is a String") 9 | } else { 10 | print("aConstant is not a String") 11 | } 12 | 13 | let anyString: Any = "string" 14 | 15 | if anyString is String { 16 | print("anyString is a String") 17 | } else { 18 | print("anyString is not a String") 19 | } 20 | 21 | -------------------------------------------------------------------------------- /Playgrounds/Ch04-EnumsPatternMatching.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Playgrounds/Ch08-FunctionalDataStructures.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Initialization.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Initialization 6 | 7 | class ShoppingItem { 8 | var name: String? 9 | var quantity = 1 10 | var purchased = false 11 | } 12 | 13 | var item = ShoppingItem() 14 | 15 | //: [Next](@next) 16 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Generics.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Generics 6 | 7 | func swapTwoIntegers( a: inout Int, b: inout Int) { 8 | let tempA = a 9 | a = b 10 | b = tempA 11 | } 12 | 13 | func swapTwoValues( a: inout T, b: inout T) { 14 | let tempA = a 15 | a = b 16 | b = tempA 17 | } 18 | 19 | //: [Next](@next) 20 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Immutability.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Immutability vs. Mutability 6 | 7 | var aMutableString = "This is a variable String" 8 | let aConstString = "This is a constant String" 9 | 10 | //: [Next](@next) 11 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/TodoApp/Stores/Store.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Store.swift 3 | // TodoApp 4 | // 5 | // Created by Fatih Nayebi on 2016-04-25. 6 | // Copyright © 2016 Fatih Nayebi. All rights reserved. 7 | // 8 | 9 | import ReactiveSwift 10 | import ReactiveCocoa 11 | import Delta 12 | 13 | struct Store: StoreType { 14 | var state: ObservableProperty 15 | 16 | init(state: State) { 17 | self.state = ObservableProperty(state) 18 | } 19 | } 20 | 21 | var store = Store(state: State()) 22 | -------------------------------------------------------------------------------- /Playgrounds/Ch06-MapFilterReduce.playground/Pages/TableOfContents.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | /*: Markdown documentation 2 | 3 | ### Table of contents 4 | * [Higher-Kinded Types](Higher-KindedTypes) 5 | * [map()](Map) 6 | * [flatMap()](FlatMap) 7 | * [flatten()](Flatten) 8 | * [filter()](Filter) 9 | * [reduce()](Reduce) 10 | * [apply()](Apply) 11 | * [join()](Join) 12 | * [Chaining Higher Order Functions](ChainingHigherOrderFuncs) 13 | * [zip()](Zip) 14 | * [Practical Examples](Examples) 15 | */ 16 | 17 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/ReactiveCocoa/ReactiveCocoa/ObjCRuntimeAliases.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | NS_ASSUME_NONNULL_BEGIN 5 | 6 | extern const IMP _rac_objc_msgForward; 7 | 8 | /// A trampoline of `objc_setAssociatedObject` that is made to circumvent the 9 | /// reference counting calls in the imported version in Swift. 10 | void _rac_objc_setAssociatedObject(const void* object, const void* key, id _Nullable value, objc_AssociationPolicy policy); 11 | 12 | NS_ASSUME_NONNULL_END 13 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/ReactiveCocoa/ReactiveCocoa/NSObject+Synchronizing.swift: -------------------------------------------------------------------------------- 1 | extension NSObject { 2 | @nonobjc internal final func synchronized(execute: () throws -> Result) rethrows -> Result { 3 | objc_sync_enter(self) 4 | defer { objc_sync_exit(self) } 5 | return try execute() 6 | } 7 | } 8 | 9 | internal func synchronized(_ token: AnyObject, execute: () throws -> Result) rethrows -> Result { 10 | objc_sync_enter(token) 11 | defer { objc_sync_exit(token) } 12 | return try execute() 13 | } 14 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/ReactiveCocoa/ReactiveCocoa/UIKit/UIImageView.swift: -------------------------------------------------------------------------------- 1 | import ReactiveSwift 2 | import UIKit 3 | 4 | extension Reactive where Base: UIImageView { 5 | /// Sets the image of the image view. 6 | public var image: BindingTarget { 7 | return makeBindingTarget { $0.image = $1 } 8 | } 9 | 10 | /// Sets the image of the image view for its highlighted state. 11 | public var highlightedImage: BindingTarget { 12 | return makeBindingTarget { $0.highlightedImage = $1 } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/ReactiveCocoa/ReactiveCocoa/UIKit/iOS/UIDatePicker.swift: -------------------------------------------------------------------------------- 1 | import ReactiveSwift 2 | import enum Result.NoError 3 | import UIKit 4 | 5 | extension Reactive where Base: UIDatePicker { 6 | /// Sets the date of the date picker. 7 | public var date: BindingTarget { 8 | return makeBindingTarget { $0.date = $1 } 9 | } 10 | 11 | /// A signal of dates emitted by the date picker. 12 | public var dates: Signal { 13 | return controlEvents(.valueChanged).map { $0.date } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/ErrorHandling.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Error Protocol 6 | 7 | enum HttpError: Error { 8 | case badRequest 9 | case unauthorized 10 | case forbidden 11 | case requestTimeOut 12 | case unsupportedMediaType 13 | case internalServerError 14 | case notImplemented 15 | case badGateway 16 | case serviceUnavailable 17 | } 18 | 19 | //: [Next](@next) 20 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Subscripts.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Subscripts 6 | 7 | struct TimesTable { 8 | let multiplier: Int 9 | subscript(index: Int) -> Int { 10 | return multiplier * index 11 | } 12 | } 13 | 14 | let fiveTimesTable = TimesTable(multiplier: 5) 15 | print("six times five is \(fiveTimesTable[6])") 16 | // prints "six times five is 30” 17 | 18 | //: [Next](@next) 19 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Tuples.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Tuples 6 | 7 | let http400Error = (400, "Bad Request") 8 | // http400Error is of type (Int, String), and equals (400, "Bad Request") 9 | 10 | // Decompose a Tuple's content 11 | let (requestStatusCode, requestStatusMessage) = http400Error 12 | 13 | //: [Next](@next) 14 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Methods.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Methods 6 | 7 | class AClass { 8 | class func someTypeMethod() { 9 | // type method body 10 | } 11 | } 12 | 13 | // We can call this method as follows: 14 | AClass.someTypeMethod() 15 | 16 | //: [Next](@next) 17 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/ARC.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // ARC 6 | class AClassWithLazyClosure { 7 | lazy var aClosure: (Int, String) -> String = { 8 | [unowned self] (index: Int, stringToProcess: String) -> String in 9 | // closure body goes here 10 | return "" 11 | } 12 | } 13 | 14 | //: [Next](@next) 15 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/LazyEvaluation.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | //: ### Lazy evaluation 3 | 4 | import Foundation 5 | 6 | let oneToFour = [1, 2, 3, 4] 7 | let firstNumber = oneToFour.lazy.map({ $0 * 3}).first! 8 | print(firstNumber) // The result is going to be 3 9 | //: [Next](@next) 10 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Generics.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Generics 6 | 7 | func swapTwoIntegers( a: inout Int, b: inout Int) { 8 | let tempA = a 9 | a = b 10 | b = tempA 11 | } 12 | 13 | func swapTwoValues( a: inout T, b: inout T) { 14 | let tempA = a 15 | a = b 16 | b = tempA 17 | } 18 | 19 | //: [Next](@next) 20 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Initialization.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Initialization 6 | 7 | class ShoppingItem { 8 | var name: String? 9 | var quantity = 1 10 | var purchased = false 11 | } 12 | 13 | var item = ShoppingItem() 14 | 15 | //: [Next](@next) 16 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Immutability.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Immutability vs. Mutability 6 | 7 | var aMutableString = "This is a variable String" 8 | let aConstString = "This is a constant String" 9 | 10 | //: [Next](@next) 11 | -------------------------------------------------------------------------------- /Playgrounds/Ch03-Types.playground/Pages/TableOfContents.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | 2 | /*: Markdown documentation 3 | 4 | ### Table of contents 5 | * [Value Types vs. Reference Types](ValueVsReferenceTypes) 6 | * [Mixing Value Types and Reference Types](MixingValueReferenceTypes) 7 | * [Copying](Copying) 8 | * [Copying Reference Types](CopyingReferenceTypes) 9 | * [Equality vs. Identity](EqualityVsIdentity) 10 | * [Equatable and Comparable](EquatableComparable) 11 | * [Type Checking and Type Casting](TypeCheckingCasting) 12 | 13 | */ 14 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/TodoApp/Models/RequestProtocol.swift: -------------------------------------------------------------------------------- 1 | // 2 | // RequestProtocol.swift 3 | // TodoApp 4 | // 5 | // Created by Fatih Nayebi on 2016-04-24. 6 | // Copyright © 2016 Fatih Nayebi. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | protocol RequestProtocol { 12 | subscript(key: String) -> (String?, String?) { get } 13 | } 14 | 15 | extension RequestProtocol { 16 | func getPropertyNames()-> [String] { 17 | return Mirror(reflecting: self).children.filter { $0.label != nil }.map { $0.label! } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/TodoApp/State/State.swift: -------------------------------------------------------------------------------- 1 | // 2 | // State.swift 3 | // TodoApp 4 | // 5 | // Created by Fatih Nayebi on 2016-04-25. 6 | // Copyright © 2016 Fatih Nayebi. All rights reserved. 7 | // 8 | 9 | import ReactiveSwift 10 | 11 | private let initialTodos: [Todo] = [] 12 | 13 | struct State { 14 | let todos = MutableProperty(initialTodos) 15 | let filter = MutableProperty(TodoFilter.all) 16 | let notSynced = MutableProperty(TodoFilter.notSyncedWithBackend) 17 | let selectedTodoItem = MutableProperty(TodoFilter.selected) 18 | } 19 | -------------------------------------------------------------------------------- /Playgrounds/Ch05-Generics.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Playgrounds/Ch06-MapFilterReduce.playground/Pages/Higher-KindedTypes.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | let intArray: Array = [1, 2, 3] 6 | let newArray = intArray.map { String($0) } // produces Array 7 | print(newArray) 8 | let intSet: Set = [1, 2, 3] 9 | let newSet = intSet.map { String($0) } // produces Set 10 | print(newSet) 11 | 12 | //protocol Functor { 13 | // associatedtype A 14 | // func fmap(f: A -> FB.A) -> FB 15 | //} 16 | //: [Next](@next) 17 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Pages/Types.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | //: ### Types 3 | import Foundation 4 | 5 | // Type inference 6 | 7 | let constString = "This is a string constant" 8 | let pi = 3.14159 9 | var primeNumber = 691 10 | let name = "my name" 11 | 12 | // Type annotation 13 | 14 | let pi2: Double = 3.14159 15 | let piAndPhi: (Double, Double) = (3.14159, 1.618) 16 | func ourFunction(a: Int) { /* ... */ } 17 | 18 | // Type aliases 19 | 20 | typealias UnsignedInteger = UInt32 21 | 22 | //: [Next](@next) 23 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Subscripts.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Subscripts 6 | 7 | struct TimesTable { 8 | let multiplier: Int 9 | subscript(index: Int) -> Int { 10 | return multiplier * index 11 | } 12 | } 13 | 14 | let fiveTimesTable = TimesTable(multiplier: 5) 15 | print("six times five is \(fiveTimesTable[6])") 16 | // prints "six times five is 30” 17 | 18 | //: [Next](@next) 19 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Methods.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Methods 6 | 7 | class AClass { 8 | class func someTypeMethod() { 9 | // type method body 10 | } 11 | } 12 | 13 | // We can call this method as follows: 14 | AClass.someTypeMethod() 15 | 16 | //: [Next](@next) 17 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/ErrorHandling.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Error Protocol 6 | 7 | enum HttpError: Error { 8 | case badRequest 9 | case unauthorized 10 | case forbidden 11 | case requestTimeOut 12 | case unsupportedMediaType 13 | case internalServerError 14 | case notImplemented 15 | case badGateway 16 | case serviceUnavailable 17 | } 18 | 19 | //: [Next](@next) 20 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Tuples.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Tuples 6 | 7 | let http400Error = (400, "Bad Request") 8 | // http400Error is of type (Int, String), and equals (400, "Bad Request") 9 | 10 | // Decompose a Tuple's content 11 | let (requestStatusCode, requestStatusMessage) = http400Error 12 | 13 | //: [Next](@next) 14 | -------------------------------------------------------------------------------- /Playgrounds/Ch06-MapFilterReduce.playground/Pages/ChainingHigherOrderFuncs.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | struct User { 6 | let name: String 7 | let age: Int 8 | } 9 | 10 | let users = [ 11 | User(name: "Fehiman", age: 60), 12 | User(name: "Neco", age: 29), 13 | User(name: "Grace", age: 1), 14 | User(name: "Tamina", age: 6), 15 | User(name: "Negar", age: 27) 16 | ] 17 | 18 | let totalAge = users.map { $0.age }.reduce(0) { $0 + $1 } 19 | totalAge 20 | 21 | //: [Next](@next) 22 | -------------------------------------------------------------------------------- /Playgrounds/Ch07-Optionals.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/ARC.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // ARC 6 | class AClassWithLazyClosure { 7 | lazy var aClosure: (Int, String) -> String = { 8 | [unowned self] (index: Int, stringToProcess: String) -> String in 9 | // closure body goes here 10 | return "" 11 | } 12 | } 13 | 14 | //: [Next](@next) 15 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/LazyEvaluation.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | //: ### Lazy evaluation 3 | 4 | import Foundation 5 | 6 | let oneToFour = [1, 2, 3, 4] 7 | let firstNumber = oneToFour.lazy.map({ $0 * 3}).first! 8 | print(firstNumber) // The result is going to be 3 9 | //: [Next](@next) 10 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/Target Support Files/Curry/Curry.xcconfig: -------------------------------------------------------------------------------- 1 | CONFIGURATION_BUILD_DIR = $PODS_CONFIGURATION_BUILD_DIR/Curry 2 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 3 | HEADER_SEARCH_PATHS = "${PODS_ROOT}/Headers/Private" "${PODS_ROOT}/Headers/Public" 4 | OTHER_SWIFT_FLAGS = $(inherited) "-D" "COCOAPODS" 5 | PODS_BUILD_DIR = $BUILD_DIR 6 | PODS_CONFIGURATION_BUILD_DIR = $PODS_BUILD_DIR/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 7 | PODS_ROOT = ${SRCROOT} 8 | PRODUCT_BUNDLE_IDENTIFIER = org.cocoapods.${PRODUCT_NAME:rfc1034identifier} 9 | SKIP_INSTALL = YES 10 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/Target Support Files/Delta/Delta.xcconfig: -------------------------------------------------------------------------------- 1 | CONFIGURATION_BUILD_DIR = $PODS_CONFIGURATION_BUILD_DIR/Delta 2 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 3 | HEADER_SEARCH_PATHS = "${PODS_ROOT}/Headers/Private" "${PODS_ROOT}/Headers/Public" 4 | OTHER_SWIFT_FLAGS = $(inherited) "-D" "COCOAPODS" 5 | PODS_BUILD_DIR = $BUILD_DIR 6 | PODS_CONFIGURATION_BUILD_DIR = $PODS_BUILD_DIR/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 7 | PODS_ROOT = ${SRCROOT} 8 | PRODUCT_BUNDLE_IDENTIFIER = org.cocoapods.${PRODUCT_NAME:rfc1034identifier} 9 | SKIP_INSTALL = YES 10 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/Target Support Files/Runes/Runes.xcconfig: -------------------------------------------------------------------------------- 1 | CONFIGURATION_BUILD_DIR = $PODS_CONFIGURATION_BUILD_DIR/Runes 2 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 3 | HEADER_SEARCH_PATHS = "${PODS_ROOT}/Headers/Private" "${PODS_ROOT}/Headers/Public" 4 | OTHER_SWIFT_FLAGS = $(inherited) "-D" "COCOAPODS" 5 | PODS_BUILD_DIR = $BUILD_DIR 6 | PODS_CONFIGURATION_BUILD_DIR = $PODS_BUILD_DIR/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 7 | PODS_ROOT = ${SRCROOT} 8 | PRODUCT_BUNDLE_IDENTIFIER = org.cocoapods.${PRODUCT_NAME:rfc1034identifier} 9 | SKIP_INSTALL = YES 10 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/ReactiveCocoa/ReactiveCocoa/UIKit/ReusableComponents.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | import ReactiveSwift 3 | import enum Result.NoError 4 | 5 | @objc public protocol Reusable: class { 6 | func prepareForReuse() 7 | } 8 | 9 | extension Reactive where Base: NSObject, Base: Reusable { 10 | public var prepareForReuse: Signal<(), NoError> { 11 | return trigger(for: #selector(base.prepareForReuse)) 12 | } 13 | } 14 | 15 | extension UITableViewCell: Reusable {} 16 | extension UITableViewHeaderFooterView: Reusable {} 17 | extension UICollectionReusableView: Reusable {} 18 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/Target Support Files/Result/Result.xcconfig: -------------------------------------------------------------------------------- 1 | CONFIGURATION_BUILD_DIR = $PODS_CONFIGURATION_BUILD_DIR/Result 2 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 3 | HEADER_SEARCH_PATHS = "${PODS_ROOT}/Headers/Private" "${PODS_ROOT}/Headers/Public" 4 | OTHER_SWIFT_FLAGS = $(inherited) "-D" "COCOAPODS" 5 | PODS_BUILD_DIR = $BUILD_DIR 6 | PODS_CONFIGURATION_BUILD_DIR = $PODS_BUILD_DIR/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 7 | PODS_ROOT = ${SRCROOT} 8 | PRODUCT_BUNDLE_IDENTIFIER = org.cocoapods.${PRODUCT_NAME:rfc1034identifier} 9 | SKIP_INSTALL = YES 10 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Generics.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Generics 6 | 7 | func swapTwoIntegers( a: inout Int, b: inout Int) { 8 | let tempA = a 9 | a = b 10 | b = tempA 11 | } 12 | 13 | func swapTwoValues( a: inout T, b: inout T) { 14 | let tempA = a 15 | a = b 16 | b = tempA 17 | } 18 | 19 | //: [Next](@next) 20 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Initialization.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Initialization 6 | 7 | class ShoppingItem { 8 | var name: String? 9 | var quantity = 1 10 | var purchased = false 11 | } 12 | 13 | var item = ShoppingItem() 14 | 15 | //: [Next](@next) 16 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Immutability.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Immutability vs. Mutability 6 | 7 | var aMutableString = "This is a variable String" 8 | let aConstString = "This is a constant String" 9 | 10 | //: [Next](@next) 11 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/Target Support Files/Alamofire/Alamofire.xcconfig: -------------------------------------------------------------------------------- 1 | CONFIGURATION_BUILD_DIR = $PODS_CONFIGURATION_BUILD_DIR/Alamofire 2 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 3 | HEADER_SEARCH_PATHS = "${PODS_ROOT}/Headers/Private" "${PODS_ROOT}/Headers/Public" 4 | OTHER_SWIFT_FLAGS = $(inherited) "-D" "COCOAPODS" 5 | PODS_BUILD_DIR = $BUILD_DIR 6 | PODS_CONFIGURATION_BUILD_DIR = $PODS_BUILD_DIR/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 7 | PODS_ROOT = ${SRCROOT} 8 | PRODUCT_BUNDLE_IDENTIFIER = org.cocoapods.${PRODUCT_NAME:rfc1034identifier} 9 | SKIP_INSTALL = YES 10 | -------------------------------------------------------------------------------- /Playgrounds/Ch03-Types.playground/Pages/MixingValueReferenceTypes.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | class User { 6 | var name: String 7 | init(name: String) { 8 | self.name = name 9 | } 10 | } 11 | let julie = User(name: "Julie") 12 | 13 | struct Student { 14 | var user: User 15 | } 16 | 17 | let student = Student(user:julie) 18 | student.user.name // prints "Julie" 19 | let anotherStudent = student 20 | julie.name = "Julie Jr." 21 | anotherStudent.user.name // prints "Julie Jr." 22 | 23 | //: [Next](@next) 24 | -------------------------------------------------------------------------------- /Playgrounds/Ch02-FuncsClosures.playground/Pages/TailRecursion.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | func factorial(n: Int, currentFactorial: Int = 1) -> Int { 6 | return n == 0 ? currentFactorial : factorial(n: n - 1, currentFactorial: currentFactorial * n) 7 | } 8 | 9 | print(factorial(n: 3)) 10 | 11 | /* 12 | factorial(n: 3, currentFactorial: 1) 13 | return factorial(n: 2, currentFactorial: 1 * 3) // n = 3 14 | return factorial(n: 1, currentFactorial: 3 * 2) // n = 2 15 | return 6 // n = 1 16 | */ 17 | 18 | 19 | 20 | //: [Next](@next) 21 | -------------------------------------------------------------------------------- /Playgrounds/Ch03-Types.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Playgrounds/Ch06-MapFilterReduce.playground/Pages/Join.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | func join(elements: [Element], separator: String) -> String { 6 | 7 | return elements.reduce("") { 8 | initial, element in 9 | let aSeparator = (element == elements.last) ? "" : separator 10 | return "\(initial)\(element)\(aSeparator)" 11 | } 12 | } 13 | 14 | let items = ["First", "Second", "Third"] 15 | let commaSeparatedItems = join(elements: items, separator: ", ") 16 | 17 | 18 | //: [Next](@next) 19 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Types.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | //: ### Types 3 | import Foundation 4 | 5 | // Type inference 6 | 7 | let constString = "This is a string constant" 8 | let pi = 3.14159 9 | var primeNumber = 691 10 | let name = "my name" 11 | 12 | // Type annotation 13 | 14 | let pi2: Double = 3.14159 15 | let piAndPhi: (Double, Double) = (3.14159, 1.618) 16 | func ourFunction(a: Int) { /* ... */ } 17 | 18 | // Type aliases 19 | 20 | typealias UnsignedInteger = UInt32 21 | 22 | //: [Next](@next) 23 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Subscripts.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Subscripts 6 | 7 | struct TimesTable { 8 | let multiplier: Int 9 | subscript(index: Int) -> Int { 10 | return multiplier * index 11 | } 12 | } 13 | 14 | let fiveTimesTable = TimesTable(multiplier: 5) 15 | print("six times five is \(fiveTimesTable[6])") 16 | // prints "six times five is 30” 17 | 18 | //: [Next](@next) 19 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Methods.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Methods 6 | 7 | class AClass { 8 | class func someTypeMethod() { 9 | // type method body 10 | } 11 | } 12 | 13 | // We can call this method as follows: 14 | AClass.someTypeMethod() 15 | 16 | //: [Next](@next) 17 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Pages/DeclarativeImperative.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | //: ### Declarative vs. Imperative 3 | 4 | let numbers = [9, 29, 19, 79] 5 | 6 | // Imperative example 7 | var tripledNumbers:[Int] = [] 8 | for number in numbers { 9 | tripledNumbers.append(number * 3) 10 | } 11 | print(tripledNumbers) 12 | 13 | // Declarative example 14 | let tripledIntNumbers = numbers.map({ 15 | number in 16 | number * 3 17 | }) 18 | print(tripledIntNumbers) 19 | 20 | let newTripledIntNumbers = numbers.map { $0 * 3 } 21 | 22 | //: [Next](@next) 23 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/ErrorHandling.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Error Protocol 6 | 7 | enum HttpError: Error { 8 | case badRequest 9 | case unauthorized 10 | case forbidden 11 | case requestTimeOut 12 | case unsupportedMediaType 13 | case internalServerError 14 | case notImplemented 15 | case badGateway 16 | case serviceUnavailable 17 | } 18 | 19 | //: [Next](@next) 20 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Tuples.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Tuples 6 | 7 | let http400Error = (400, "Bad Request") 8 | // http400Error is of type (Int, String), and equals (400, "Bad Request") 9 | 10 | // Decompose a Tuple's content 11 | let (requestStatusCode, requestStatusMessage) = http400Error 12 | 13 | //: [Next](@next) 14 | -------------------------------------------------------------------------------- /Playgrounds/Ch02-FuncsClosures.playground/Pages/CapturingValues.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | func sendRequest(completion: @escaping (_ response: String?, _ error: Error?) -> Void) { 6 | // execute some time consuming operation, if successfull { 7 | completion("Response", nil) 8 | //} 9 | } 10 | 11 | sendRequest() { 12 | (response: String?, error: Error?) in 13 | if let result = response { 14 | print(result) 15 | } else if let serverError = error { 16 | // Error 17 | } 18 | } 19 | 20 | //: [Next](@next) 21 | -------------------------------------------------------------------------------- /Playgrounds/Ch06-MapFilterReduce.playground/Pages/FlatMap.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | let twoDimArray = [[1, 3, 5], [2, 4, 6]] 6 | let oneDimArray = twoDimArray.flatMap { $0 } 7 | oneDimArray 8 | 9 | let oneDimArray2 = twoDimArray.joined().map { $0 } 10 | oneDimArray2 11 | 12 | 13 | let transofrmedOneDimArray = twoDimArray.flatMap { $0.map { $0 + 2 } } 14 | transofrmedOneDimArray 15 | 16 | 17 | let threeDimArray = [[1, [3, 5]], [2, [4, 6]]] 18 | let twoDimArray2 = threeDimArray.flatMap { $0 } 19 | twoDimArray2 20 | 21 | //: [Next](@next) 22 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/ARC.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // ARC 6 | class AClassWithLazyClosure { 7 | lazy var aClosure: (Int, String) -> String = { 8 | [unowned self] (index: Int, stringToProcess: String) -> String in 9 | // closure body goes here 10 | return "" 11 | } 12 | } 13 | 14 | //: [Next](@next) 15 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/LazyEvaluation.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | //: ### Lazy evaluation 3 | 4 | import Foundation 5 | 6 | let oneToFour = [1, 2, 3, 4] 7 | let firstNumber = oneToFour.lazy.map({ $0 * 3}).first! 8 | print(firstNumber) // The result is going to be 3 9 | //: [Next](@next) 10 | -------------------------------------------------------------------------------- /Playgrounds/Ch03-Types.playground/Pages/Copying.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | class User { 6 | var name: String 7 | init(name: String) { 8 | self.name = name 9 | } 10 | } 11 | 12 | let julie = User(name: "Julie") 13 | let steve = User(name: "Steve") 14 | let alain = User(name: "Alain") 15 | let users = [alain, julie, steve] 16 | 17 | let copyOfUsers = users 18 | users[0].name = "Jean-Marc" 19 | 20 | print(users[0].name) // prints "Jean-Marc" 21 | print(copyOfUsers[0].name) // prints "Jean-Marc" 22 | 23 | 24 | //: [Next](@next) 25 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/ReactiveCocoa/ReactiveCocoa/UIKit/UIBarItem.swift: -------------------------------------------------------------------------------- 1 | import ReactiveSwift 2 | import UIKit 3 | 4 | extension Reactive where Base: UIBarItem { 5 | /// Sets whether the bar item is enabled. 6 | public var isEnabled: BindingTarget { 7 | return makeBindingTarget { $0.isEnabled = $1 } 8 | } 9 | 10 | /// Sets image of bar item. 11 | public var image: BindingTarget { 12 | return makeBindingTarget { $0.image = $1 } 13 | } 14 | 15 | /// Sets the title of bar item. 16 | public var title: BindingTarget { 17 | return makeBindingTarget { $0.title = $1 } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Generics.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Generics 6 | 7 | func swapTwoIntegers( a: inout Int, b: inout Int) { 8 | let tempA = a 9 | a = b 10 | b = tempA 11 | } 12 | 13 | func swapTwoValues( a: inout T, b: inout T) { 14 | let tempA = a 15 | a = b 16 | b = tempA 17 | } 18 | 19 | //: [Next](@next) 20 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Initialization.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Initialization 6 | 7 | class ShoppingItem { 8 | var name: String? 9 | var quantity = 1 10 | var purchased = false 11 | } 12 | 13 | var item = ShoppingItem() 14 | 15 | //: [Next](@next) 16 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Immutability.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Immutability vs. Mutability 6 | 7 | var aMutableString = "This is a variable String" 8 | let aConstString = "This is a constant String" 9 | 10 | //: [Next](@next) 11 | -------------------------------------------------------------------------------- /Playgrounds/Ch07-Optionals.playground/Pages/OptionalChaining.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | class Residence { 6 | var numberOfRooms = 1 7 | } 8 | 9 | class Person { 10 | var residence: Residence? 11 | } 12 | 13 | let residence = Residence() 14 | residence.numberOfRooms = 5 15 | 16 | let sangeeth = Person() 17 | sangeeth.residence = residence 18 | 19 | if let roomCount = sangeeth.residence?.numberOfRooms { 20 | // Use the roomCount 21 | print(roomCount) 22 | } 23 | 24 | let roomCount = sangeeth.residence!.numberOfRooms 25 | 26 | 27 | //: [Next](@next) 28 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/ReactiveCocoa/ReactiveCocoa/UIKit/UISegmentedControl.swift: -------------------------------------------------------------------------------- 1 | import ReactiveSwift 2 | import enum Result.NoError 3 | import UIKit 4 | 5 | extension Reactive where Base: UISegmentedControl { 6 | /// Changes the selected segment of the segmented control. 7 | public var selectedSegmentIndex: BindingTarget { 8 | return makeBindingTarget { $0.selectedSegmentIndex = $1 } 9 | } 10 | 11 | /// A signal of indexes of selections emitted by the segmented control. 12 | public var selectedSegmentIndexes: Signal { 13 | return controlEvents(.valueChanged).map { $0.selectedSegmentIndex } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/ReactiveSwift/Sources/ResultExtensions.swift: -------------------------------------------------------------------------------- 1 | import Result 2 | 3 | /// Private alias of the free `materialize()` from `Result`. 4 | /// 5 | /// This exists because within a `Signal` or `SignalProducer` operator, 6 | /// `materialize()` refers to the operator with that name. 7 | /// Namespacing as `Result.materialize()` doesn't work either, 8 | /// because it tries to resolve a static member on the _type_ 9 | /// `Result`, rather than the free function in the _module_ 10 | /// of the same name. 11 | internal func materialize(_ f: () throws -> T) -> Result { 12 | return materialize(try f()) 13 | } 14 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Types.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | //: ### Types 3 | import Foundation 4 | 5 | // Type inference 6 | 7 | let constString = "This is a string constant" 8 | let pi = 3.14159 9 | var primeNumber = 691 10 | let name = "my name" 11 | 12 | // Type annotation 13 | 14 | let pi2: Double = 3.14159 15 | let piAndPhi: (Double, Double) = (3.14159, 1.618) 16 | func ourFunction(a: Int) { /* ... */ } 17 | 18 | // Type aliases 19 | 20 | typealias UnsignedInteger = UInt32 21 | 22 | //: [Next](@next) 23 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Subscripts.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Subscripts 6 | 7 | struct TimesTable { 8 | let multiplier: Int 9 | subscript(index: Int) -> Int { 10 | return multiplier * index 11 | } 12 | } 13 | 14 | let fiveTimesTable = TimesTable(multiplier: 5) 15 | print("six times five is \(fiveTimesTable[6])") 16 | // prints "six times five is 30” 17 | 18 | //: [Next](@next) 19 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Tuples.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Tuples 6 | 7 | let http400Error = (400, "Bad Request") 8 | // http400Error is of type (Int, String), and equals (400, "Bad Request") 9 | 10 | // Decompose a Tuple's content 11 | let (requestStatusCode, requestStatusMessage) = http400Error 12 | 13 | //: [Next](@next) 14 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Methods.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Methods 6 | 7 | class AClass { 8 | class func someTypeMethod() { 9 | // type method body 10 | } 11 | } 12 | 13 | // We can call this method as follows: 14 | AClass.someTypeMethod() 15 | 16 | //: [Next](@next) 17 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/DeclarativeImperative.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | //: ### Declarative vs. Imperative 3 | 4 | let numbers = [9, 29, 19, 79] 5 | 6 | // Imperative example 7 | var tripledNumbers:[Int] = [] 8 | for number in numbers { 9 | tripledNumbers.append(number * 3) 10 | } 11 | print(tripledNumbers) 12 | 13 | // Declarative example 14 | let tripledIntNumbers = numbers.map({ 15 | number in 16 | number * 3 17 | }) 18 | print(tripledIntNumbers) 19 | 20 | let newTripledIntNumbers = numbers.map { $0 * 3 } 21 | 22 | //: [Next](@next) 23 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/ErrorHandling.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Error Protocol 6 | 7 | enum HttpError: Error { 8 | case badRequest 9 | case unauthorized 10 | case forbidden 11 | case requestTimeOut 12 | case unsupportedMediaType 13 | case internalServerError 14 | case notImplemented 15 | case badGateway 16 | case serviceUnavailable 17 | } 18 | 19 | //: [Next](@next) 20 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/LazyEvaluation.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | //: ### Lazy evaluation 3 | 4 | import Foundation 5 | 6 | let oneToFour = [1, 2, 3, 4] 7 | let firstNumber = oneToFour.lazy.map({ $0 * 3}).first! 8 | print(firstNumber) // The result is going to be 3 9 | //: [Next](@next) 10 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/ARC.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // ARC 6 | class AClassWithLazyClosure { 7 | lazy var aClosure: (Int, String) -> String = { 8 | [unowned self] (index: Int, stringToProcess: String) -> String in 9 | // closure body goes here 10 | return "" 11 | } 12 | } 13 | 14 | //: [Next](@next) 15 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/Target Support Files/Argo/Argo.xcconfig: -------------------------------------------------------------------------------- 1 | CONFIGURATION_BUILD_DIR = $PODS_CONFIGURATION_BUILD_DIR/Argo 2 | FRAMEWORK_SEARCH_PATHS = $(inherited) "$PODS_CONFIGURATION_BUILD_DIR/Runes" 3 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 4 | HEADER_SEARCH_PATHS = "${PODS_ROOT}/Headers/Private" "${PODS_ROOT}/Headers/Public" 5 | OTHER_SWIFT_FLAGS = $(inherited) "-D" "COCOAPODS" 6 | PODS_BUILD_DIR = $BUILD_DIR 7 | PODS_CONFIGURATION_BUILD_DIR = $PODS_BUILD_DIR/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 8 | PODS_ROOT = ${SRCROOT} 9 | PRODUCT_BUNDLE_IDENTIFIER = org.cocoapods.${PRODUCT_NAME:rfc1034identifier} 10 | SKIP_INSTALL = YES 11 | -------------------------------------------------------------------------------- /Playgrounds/Ch06-MapFilterReduce.playground/Pages/Filter.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | let numbers = [10, 30, 91, 50, 100, 39, 74] 6 | let evenNumbers = numbers.filter { $0 % 2 == 0 } 7 | 8 | func filter(elements: [Element], predicate: ((Element) -> Bool)) -> [Element] { 9 | var result = [Element]() 10 | for element in elements { 11 | if predicate(element) { 12 | result.append(element) 13 | } 14 | } 15 | return result 16 | } 17 | 18 | let filteredArray = filter(elements: numbers) { $0 % 2 == 0 } 19 | filteredArray 20 | 21 | //: [Next](@next) 22 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/ReactiveCocoa/ReactiveCocoa/UIKit/UILabel.swift: -------------------------------------------------------------------------------- 1 | import ReactiveSwift 2 | import UIKit 3 | 4 | extension Reactive where Base: UILabel { 5 | /// Sets the text of the label. 6 | public var text: BindingTarget { 7 | return makeBindingTarget { $0.text = $1 } 8 | } 9 | 10 | /// Sets the attributed text of the label. 11 | public var attributedText: BindingTarget { 12 | return makeBindingTarget { $0.attributedText = $1 } 13 | } 14 | 15 | /// Sets the color of the text of the label. 16 | public var textColor: BindingTarget { 17 | return makeBindingTarget { $0.textColor = $1 } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Generics.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Generics 6 | 7 | func swapTwoIntegers( a: inout Int, b: inout Int) { 8 | let tempA = a 9 | a = b 10 | b = tempA 11 | } 12 | 13 | func swapTwoValues( a: inout T, b: inout T) { 14 | let tempA = a 15 | a = b 16 | b = tempA 17 | } 18 | 19 | //: [Next](@next) 20 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Initialization.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Initialization 6 | 7 | class ShoppingItem { 8 | var name: String? 9 | var quantity = 1 10 | var purchased = false 11 | } 12 | 13 | var item = ShoppingItem() 14 | 15 | //: [Next](@next) 16 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Immutability.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Immutability vs. Mutability 6 | 7 | var aMutableString = "This is a variable String" 8 | let aConstString = "This is a constant String" 9 | 10 | //: [Next](@next) 11 | -------------------------------------------------------------------------------- /Playgrounds/Ch05-Generics.playground/Pages/ExtendingGenericTypes.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | struct Queue { 6 | var elements = [Element]() 7 | mutating func enQueue(newElement: Element) { 8 | elements.append(newElement) 9 | } 10 | 11 | mutating func deQueue() -> Element? { 12 | guard !elements.isEmpty else { 13 | return nil 14 | } 15 | return elements.remove(at: 0) 16 | } 17 | } 18 | 19 | extension Queue { 20 | func peek() -> Element? { 21 | return elements.first 22 | } 23 | } 24 | 25 | //: [Next](@next) 26 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/Argo/Sources/Argo/Extensions/Dictionary.swift: -------------------------------------------------------------------------------- 1 | import Runes 2 | 3 | // pure merge for Dictionaries 4 | func + (lhs: [T: U], rhs: [T: U]) -> [T: U] { 5 | var merged = lhs 6 | for (key, val) in rhs { 7 | merged[key] = val 8 | } 9 | 10 | return merged 11 | } 12 | 13 | extension Dictionary { 14 | func map(_ f: (Value) -> T) -> [Key: T] { 15 | var accum = Dictionary(minimumCapacity: self.count) 16 | 17 | for (key, value) in self { 18 | accum[key] = f(value) 19 | } 20 | 21 | return accum 22 | } 23 | } 24 | 25 | func <^> (f: (T) -> U, x: [V: T]) -> [V: U] { 26 | return x.map(f) 27 | } 28 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Types.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | //: ### Types 3 | import Foundation 4 | 5 | // Type inference 6 | 7 | let constString = "This is a string constant" 8 | let pi = 3.14159 9 | var primeNumber = 691 10 | let name = "my name" 11 | 12 | // Type annotation 13 | 14 | let pi2: Double = 3.14159 15 | let piAndPhi: (Double, Double) = (3.14159, 1.618) 16 | func ourFunction(a: Int) { /* ... */ } 17 | 18 | // Type aliases 19 | 20 | typealias UnsignedInteger = UInt32 21 | 22 | //: [Next](@next) 23 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Subscripts.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Subscripts 6 | 7 | struct TimesTable { 8 | let multiplier: Int 9 | subscript(index: Int) -> Int { 10 | return multiplier * index 11 | } 12 | } 13 | 14 | let fiveTimesTable = TimesTable(multiplier: 5) 15 | print("six times five is \(fiveTimesTable[6])") 16 | // prints "six times five is 30” 17 | 18 | //: [Next](@next) 19 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Tuples.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Tuples 6 | 7 | let http400Error = (400, "Bad Request") 8 | // http400Error is of type (Int, String), and equals (400, "Bad Request") 9 | 10 | // Decompose a Tuple's content 11 | let (requestStatusCode, requestStatusMessage) = http400Error 12 | 13 | //: [Next](@next) 14 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Methods.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Methods 6 | 7 | class AClass { 8 | class func someTypeMethod() { 9 | // type method body 10 | } 11 | } 12 | 13 | // We can call this method as follows: 14 | AClass.someTypeMethod() 15 | 16 | //: [Next](@next) 17 | -------------------------------------------------------------------------------- /Playgrounds/Ch06-MapFilterReduce.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /Playgrounds/Ch07-Optionals.playground/Pages/Definition.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Optional value either contains a value or contains nil 6 | var optionalString: String? = "A String literal" 7 | optionalString = nil 8 | 9 | var aString: String = "A String literal" 10 | // aString = nil // Compile error 11 | 12 | /* ObjC 13 | 14 | NSString *searchedItem = [self searchItem:@"an item"]; 15 | NSString *text = @"Found item: "; 16 | NSString *message = [text stringByAppendingString:searchedItem]; 17 | 18 | */ 19 | 20 | enum Optional { 21 | case None 22 | case Some(T) 23 | } 24 | 25 | //: [Next](@next) 26 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/DeclarativeImperative.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | //: ### Declarative vs. Imperative 3 | 4 | let numbers = [9, 29, 19, 79] 5 | 6 | // Imperative example 7 | var tripledNumbers:[Int] = [] 8 | for number in numbers { 9 | tripledNumbers.append(number * 3) 10 | } 11 | print(tripledNumbers) 12 | 13 | // Declarative example 14 | let tripledIntNumbers = numbers.map({ 15 | number in 16 | number * 3 17 | }) 18 | print(tripledIntNumbers) 19 | 20 | let newTripledIntNumbers = numbers.map { $0 * 3 } 21 | 22 | //: [Next](@next) 23 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/ErrorHandling.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Error Protocol 6 | 7 | enum HttpError: Error { 8 | case badRequest 9 | case unauthorized 10 | case forbidden 11 | case requestTimeOut 12 | case unsupportedMediaType 13 | case internalServerError 14 | case notImplemented 15 | case badGateway 16 | case serviceUnavailable 17 | } 18 | 19 | //: [Next](@next) 20 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/ARC.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // ARC 6 | class AClassWithLazyClosure { 7 | lazy var aClosure: (Int, String) -> String = { 8 | [unowned self] (index: Int, stringToProcess: String) -> String in 9 | // closure body goes here 10 | return "" 11 | } 12 | } 13 | 14 | //: [Next](@next) 15 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/LazyEvaluation.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | //: ### Lazy evaluation 3 | 4 | import Foundation 5 | 6 | let oneToFour = [1, 2, 3, 4] 7 | let firstNumber = oneToFour.lazy.map({ $0 * 3}).first! 8 | print(firstNumber) // The result is going to be 3 9 | //: [Next](@next) 10 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Initialization.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Initialization 6 | 7 | class ShoppingItem { 8 | var name: String? 9 | var quantity = 1 10 | var purchased = false 11 | } 12 | 13 | var item = ShoppingItem() 14 | 15 | //: [Next](@next) 16 | -------------------------------------------------------------------------------- /Playgrounds/Ch02-FuncsClosures.playground/Pages/TableOfContents.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | 2 | /*: Markdown documentation 3 | 4 | ### Table of contents 5 | * [Function Definition and usage](Definition) 6 | * [Function Types](FunctionTypes) 7 | * [Nested Functions](NestedFunctions) 8 | * [First Class Functions](FirstClassFunctions) 9 | * [Higher Order Functions](HigherOrderFunctions) 10 | * [Function Compostion](FunctionComposition) 11 | * [Closures](Closures) 12 | * [Capturing Values with Closures](CapturingValues) 13 | * [Function Currying](FunctionCurrying) 14 | * [Recursion](Recursion) 15 | * [Tail Recursion](TailRecursion) 16 | * [Memoization](Memoization) 17 | 18 | */ 19 | -------------------------------------------------------------------------------- /Playgrounds/Ch03-Types.playground/Pages/EqualityVsIdentity.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | class User { 6 | var name: String 7 | init(name: String) { 8 | self.name = name 9 | } 10 | } 11 | 12 | let firstNumber = 1 13 | let secondNumber = 1 14 | 15 | if firstNumber == secondNumber { 16 | print("Two numbers are equal") // prints "Two numbers are equal\n" 17 | } 18 | 19 | let tarang = User(name: "Tarang") 20 | let sangeeth = User(name: "Sangeeth") 21 | 22 | if tarang === sangeeth { 23 | print("Identical") 24 | } else { 25 | print("Not identical") // prints "Not identical" 26 | } 27 | 28 | //: [Next](@next) 29 | -------------------------------------------------------------------------------- /Playgrounds/Ch07-Optionals.playground/Pages/Guard.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | func greet(person: [String: String]) { 6 | guard let name = person["name"] else { 7 | return 8 | } 9 | print("Hello Ms \(name)!") 10 | } 11 | 12 | greet(person: ["name": "Neco"]) // prints "Hello Ms Neco!" 13 | 14 | func extractValue(dict: [String: Int]) { 15 | guard let firstValue = dict["One"], 16 | let secondValue = dict["Two"], 17 | let thirdValue = dict["Three"] 18 | else { 19 | return 20 | } 21 | print("\(firstValue) \(secondValue) \(thirdValue)") 22 | } 23 | 24 | //: [Next](@next) 25 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Generics.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Generics 6 | 7 | func swapTwoIntegers( a: inout Int, b: inout Int) { 8 | let tempA = a 9 | a = b 10 | b = tempA 11 | } 12 | 13 | func swapTwoValues( a: inout T, b: inout T) { 14 | let tempA = a 15 | a = b 16 | b = tempA 17 | } 18 | 19 | //: [Next](@next) 20 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Immutability.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Immutability vs. Mutability 6 | 7 | var aMutableString = "This is a variable String" 8 | let aConstString = "This is a constant String" 9 | 10 | //: [Next](@next) 11 | -------------------------------------------------------------------------------- /Ch11-Backend/vapor-example/Resources/Views/welcome.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Vapor 5 | 6 | 7 | 8 | 9 |
10 |

Vapor

11 | 12 | 21 |
22 | 23 |
24 |

Powered by Swift. Built by Tanner.

25 |
26 | 27 | 28 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Types.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | //: ### Types 3 | import Foundation 4 | 5 | // Type inference 6 | 7 | let constString = "This is a string constant" 8 | let pi = 3.14159 9 | var primeNumber = 691 10 | let name = "my name" 11 | 12 | // Type annotation 13 | 14 | let pi2: Double = 3.14159 15 | let piAndPhi: (Double, Double) = (3.14159, 1.618) 16 | func ourFunction(a: Int) { /* ... */ } 17 | 18 | // Type aliases 19 | 20 | typealias UnsignedInteger = UInt32 21 | 22 | //: [Next](@next) 23 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/DeclarativeImperative.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | //: ### Declarative vs. Imperative 3 | 4 | let numbers = [9, 29, 19, 79] 5 | 6 | // Imperative example 7 | var tripledNumbers:[Int] = [] 8 | for number in numbers { 9 | tripledNumbers.append(number * 3) 10 | } 11 | print(tripledNumbers) 12 | 13 | // Declarative example 14 | let tripledIntNumbers = numbers.map({ 15 | number in 16 | number * 3 17 | }) 18 | print(tripledIntNumbers) 19 | 20 | let newTripledIntNumbers = numbers.map { $0 * 3 } 21 | 22 | //: [Next](@next) 23 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/ErrorHandling.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Error Protocol 6 | 7 | enum HttpError: Error { 8 | case badRequest 9 | case unauthorized 10 | case forbidden 11 | case requestTimeOut 12 | case unsupportedMediaType 13 | case internalServerError 14 | case notImplemented 15 | case badGateway 16 | case serviceUnavailable 17 | } 18 | 19 | //: [Next](@next) 20 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Subscripts.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Subscripts 6 | 7 | struct TimesTable { 8 | let multiplier: Int 9 | subscript(index: Int) -> Int { 10 | return multiplier * index 11 | } 12 | } 13 | 14 | let fiveTimesTable = TimesTable(multiplier: 5) 15 | print("six times five is \(fiveTimesTable[6])") 16 | // prints "six times five is 30” 17 | 18 | //: [Next](@next) 19 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Tuples.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Tuples 6 | 7 | let http400Error = (400, "Bad Request") 8 | // http400Error is of type (Int, String), and equals (400, "Bad Request") 9 | 10 | // Decompose a Tuple's content 11 | let (requestStatusCode, requestStatusMessage) = http400Error 12 | 13 | //: [Next](@next) 14 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Methods.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Methods 6 | 7 | class AClass { 8 | class func someTypeMethod() { 9 | // type method body 10 | } 11 | } 12 | 13 | // We can call this method as follows: 14 | AClass.someTypeMethod() 15 | 16 | //: [Next](@next) 17 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/Target Support Files/ReactiveCocoa/ReactiveCocoa.xcconfig: -------------------------------------------------------------------------------- 1 | CONFIGURATION_BUILD_DIR = $PODS_CONFIGURATION_BUILD_DIR/ReactiveCocoa 2 | FRAMEWORK_SEARCH_PATHS = $(inherited) "$PODS_CONFIGURATION_BUILD_DIR/ReactiveSwift" "$PODS_CONFIGURATION_BUILD_DIR/Result" 3 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 4 | HEADER_SEARCH_PATHS = "${PODS_ROOT}/Headers/Private" "${PODS_ROOT}/Headers/Public" 5 | OTHER_SWIFT_FLAGS = $(inherited) "-D" "COCOAPODS" 6 | PODS_BUILD_DIR = $BUILD_DIR 7 | PODS_CONFIGURATION_BUILD_DIR = $PODS_BUILD_DIR/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 8 | PODS_ROOT = ${SRCROOT} 9 | PRODUCT_BUNDLE_IDENTIFIER = org.cocoapods.${PRODUCT_NAME:rfc1034identifier} 10 | SKIP_INSTALL = YES 11 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/TodoApp/Actions/CreateTodoAction.swift: -------------------------------------------------------------------------------- 1 | import Delta 2 | 3 | struct CreateTodoAction: ActionType { 4 | let todoId: Int 5 | let name: String 6 | let description: String 7 | let notes: String 8 | 9 | var todo: Todo { 10 | return Todo(todoId: todoId, 11 | name: name, 12 | description: description, 13 | notes: notes, 14 | completed: false, 15 | synced: false, 16 | selected: false) 17 | } 18 | 19 | func reduce(state: State) -> State { 20 | state.todos.value = state.todos.value + [todo] 21 | 22 | return state 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/ARC.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // ARC 6 | class AClassWithLazyClosure { 7 | lazy var aClosure: (Int, String) -> String = { 8 | [unowned self] (index: Int, stringToProcess: String) -> String in 9 | // closure body goes here 10 | return "" 11 | } 12 | } 13 | 14 | //: [Next](@next) 15 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/LazyEvaluation.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | //: ### Lazy evaluation 3 | 4 | import Foundation 5 | 6 | let oneToFour = [1, 2, 3, 4] 7 | let firstNumber = oneToFour.lazy.map({ $0 * 3}).first! 8 | print(firstNumber) // The result is going to be 3 9 | //: [Next](@next) 10 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Pages/Protocols.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | protocol HttpProtocol{ 6 | func didRecieveResults(results: Any) 7 | } 8 | 9 | struct WebServiceManager { 10 | var delegate:HttpProtocol? 11 | let data: Data 12 | func test() { 13 | do { 14 | let jsonResult = try JSONSerialization.jsonObject(with: self.data, options: JSONSerialization.ReadingOptions.mutableContainers) 15 | self.delegate?.didRecieveResults(results: jsonResult) 16 | } catch let error as NSError { 17 | print("json error" + error.localizedDescription) 18 | } 19 | } 20 | } 21 | 22 | //: [Next](@next) 23 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Generics.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Generics 6 | 7 | func swapTwoIntegers( a: inout Int, b: inout Int) { 8 | let tempA = a 9 | a = b 10 | b = tempA 11 | } 12 | 13 | func swapTwoValues( a: inout T, b: inout T) { 14 | let tempA = a 15 | a = b 16 | b = tempA 17 | } 18 | 19 | //: [Next](@next) 20 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Initialization.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Initialization 6 | 7 | class ShoppingItem { 8 | var name: String? 9 | var quantity = 1 10 | var purchased = false 11 | } 12 | 13 | var item = ShoppingItem() 14 | 15 | //: [Next](@next) 16 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/Target Support Files/ReactiveSwift/ReactiveSwift.xcconfig: -------------------------------------------------------------------------------- 1 | CONFIGURATION_BUILD_DIR = $PODS_CONFIGURATION_BUILD_DIR/ReactiveSwift 2 | FRAMEWORK_SEARCH_PATHS = $(inherited) "$PODS_CONFIGURATION_BUILD_DIR/Result" 3 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 4 | HEADER_SEARCH_PATHS = "${PODS_ROOT}/Headers/Private" "${PODS_ROOT}/Headers/Public" 5 | OTHER_SWIFT_FLAGS = $(inherited) "-D" "COCOAPODS" 6 | OTHER_SWIFT_FLAGS[config=Release] = -suppress-warnings 7 | PODS_BUILD_DIR = $BUILD_DIR 8 | PODS_CONFIGURATION_BUILD_DIR = $PODS_BUILD_DIR/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 9 | PODS_ROOT = ${SRCROOT} 10 | PRODUCT_BUNDLE_IDENTIFIER = org.cocoapods.${PRODUCT_NAME:rfc1034identifier} 11 | SKIP_INSTALL = YES 12 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Immutability.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Immutability vs. Mutability 6 | 7 | var aMutableString = "This is a variable String" 8 | let aConstString = "This is a constant String" 9 | 10 | //: [Next](@next) 11 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/Local Podspecs/Delta.podspec.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Delta", 3 | "version": "1.0.0", 4 | "summary": "Managing state is hard. Delta aims to make it simple.", 5 | "homepage": "https://github.com/conqueror/Delta", 6 | "license": { 7 | "type": "MIT", 8 | "file": "LICENSE" 9 | }, 10 | "authors": { 11 | "Jake Craige": "james.craige@gmail.com", 12 | "Giles Van Gruisen": "giles@thoughtbot.com", 13 | "thoughtbot": null 14 | }, 15 | "source": { 16 | "git": "https://github.com/conqueror/Delta.git", 17 | "tag": "v1.0.0", 18 | "submodules": true 19 | }, 20 | "source_files": "Sources/**/*.{h,swift}", 21 | "requires_arc": true, 22 | "platforms": { 23 | "ios": "8.0" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Types.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | //: ### Types 3 | import Foundation 4 | 5 | // Type inference 6 | 7 | let constString = "This is a string constant" 8 | let pi = 3.14159 9 | var primeNumber = 691 10 | let name = "my name" 11 | 12 | // Type annotation 13 | 14 | let pi2: Double = 3.14159 15 | let piAndPhi: (Double, Double) = (3.14159, 1.618) 16 | func ourFunction(a: Int) { /* ... */ } 17 | 18 | // Type aliases 19 | 20 | typealias UnsignedInteger = UInt32 21 | 22 | //: [Next](@next) 23 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Subscripts.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Subscripts 6 | 7 | struct TimesTable { 8 | let multiplier: Int 9 | subscript(index: Int) -> Int { 10 | return multiplier * index 11 | } 12 | } 13 | 14 | let fiveTimesTable = TimesTable(multiplier: 5) 15 | print("six times five is \(fiveTimesTable[6])") 16 | // prints "six times five is 30” 17 | 18 | //: [Next](@next) 19 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Methods.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Methods 6 | 7 | class AClass { 8 | class func someTypeMethod() { 9 | // type method body 10 | } 11 | } 12 | 13 | // We can call this method as follows: 14 | AClass.someTypeMethod() 15 | 16 | //: [Next](@next) 17 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/DeclarativeImperative.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | //: ### Declarative vs. Imperative 3 | 4 | let numbers = [9, 29, 19, 79] 5 | 6 | // Imperative example 7 | var tripledNumbers:[Int] = [] 8 | for number in numbers { 9 | tripledNumbers.append(number * 3) 10 | } 11 | print(tripledNumbers) 12 | 13 | // Declarative example 14 | let tripledIntNumbers = numbers.map({ 15 | number in 16 | number * 3 17 | }) 18 | print(tripledIntNumbers) 19 | 20 | let newTripledIntNumbers = numbers.map { $0 * 3 } 21 | 22 | //: [Next](@next) 23 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/ErrorHandling.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Error Protocol 6 | 7 | enum HttpError: Error { 8 | case badRequest 9 | case unauthorized 10 | case forbidden 11 | case requestTimeOut 12 | case unsupportedMediaType 13 | case internalServerError 14 | case notImplemented 15 | case badGateway 16 | case serviceUnavailable 17 | } 18 | 19 | //: [Next](@next) 20 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Tuples.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Tuples 6 | 7 | let http400Error = (400, "Bad Request") 8 | // http400Error is of type (Int, String), and equals (400, "Bad Request") 9 | 10 | // Decompose a Tuple's content 11 | let (requestStatusCode, requestStatusMessage) = http400Error 12 | 13 | //: [Next](@next) 14 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/ARC.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // ARC 6 | class AClassWithLazyClosure { 7 | lazy var aClosure: (Int, String) -> String = { 8 | [unowned self] (index: Int, stringToProcess: String) -> String in 9 | // closure body goes here 10 | return "" 11 | } 12 | } 13 | 14 | //: [Next](@next) 15 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/LazyEvaluation.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | //: ### Lazy evaluation 3 | 4 | import Foundation 5 | 6 | let oneToFour = [1, 2, 3, 4] 7 | let firstNumber = oneToFour.lazy.map({ $0 * 3}).first! 8 | print(firstNumber) // The result is going to be 3 9 | //: [Next](@next) 10 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/Local Podspecs/Curry.podspec.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Curry", 3 | "version": "3.0.0", 4 | "summary": "Function Currying for Swift", 5 | "homepage": "https://github.com/thoughtbot/curry", 6 | "license": { 7 | "type": "MIT", 8 | "file": "LICENSE" 9 | }, 10 | "authors": { 11 | "Gordon Fontenot": "gordon@thoughtbot.com", 12 | "thoughtbot": null 13 | }, 14 | "social_media_url": "http://twitter.com/thoughtbot", 15 | "source": { 16 | "git": "https://github.com/thoughtbot/curry.git", 17 | "tag": "v3.0.0" 18 | }, 19 | "source_files": "Source/**/*.{h,swift}", 20 | "requires_arc": true, 21 | "platforms": { 22 | "ios": "8.0", 23 | "osx": "10.9", 24 | "watchos": "2.0", 25 | "tvos": "9.0" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Protocols.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | protocol HttpProtocol{ 6 | func didRecieveResults(results: Any) 7 | } 8 | 9 | struct WebServiceManager { 10 | var delegate:HttpProtocol? 11 | let data: Data 12 | func test() { 13 | do { 14 | let jsonResult = try JSONSerialization.jsonObject(with: self.data, options: JSONSerialization.ReadingOptions.mutableContainers) 15 | self.delegate?.didRecieveResults(results: jsonResult) 16 | } catch let error as NSError { 17 | print("json error" + error.localizedDescription) 18 | } 19 | } 20 | } 21 | 22 | //: [Next](@next) 23 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Generics.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Generics 6 | 7 | func swapTwoIntegers( a: inout Int, b: inout Int) { 8 | let tempA = a 9 | a = b 10 | b = tempA 11 | } 12 | 13 | func swapTwoValues( a: inout T, b: inout T) { 14 | let tempA = a 15 | a = b 16 | b = tempA 17 | } 18 | 19 | //: [Next](@next) 20 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Initialization.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Initialization 6 | 7 | class ShoppingItem { 8 | var name: String? 9 | var quantity = 1 10 | var purchased = false 11 | } 12 | 13 | var item = ShoppingItem() 14 | 15 | //: [Next](@next) 16 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Immutability.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Immutability vs. Mutability 6 | 7 | var aMutableString = "This is a variable String" 8 | let aConstString = "This is a constant String" 9 | 10 | //: [Next](@next) 11 | -------------------------------------------------------------------------------- /Playgrounds/Ch02-FuncsClosures.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/TodoApp/Actions/ToggleCompletedAction.swift: -------------------------------------------------------------------------------- 1 | import Delta 2 | 3 | struct ToggleCompletedAction: ActionType { 4 | let todo: Todo 5 | 6 | func reduce(state: State) -> State { 7 | state.todos.value = state.todos.value.map { 8 | todo in 9 | guard todo == self.todo else { return todo } 10 | 11 | return Todo(todoId: todo.todoId, 12 | name: todo.name, 13 | description: todo.description, 14 | notes: todo.notes, 15 | completed: !todo.completed, 16 | synced: !todo.synced, 17 | selected: todo.selected) 18 | } 19 | 20 | return state 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Types.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | //: ### Types 3 | import Foundation 4 | 5 | // Type inference 6 | 7 | let constString = "This is a string constant" 8 | let pi = 3.14159 9 | var primeNumber = 691 10 | let name = "my name" 11 | 12 | // Type annotation 13 | 14 | let pi2: Double = 3.14159 15 | let piAndPhi: (Double, Double) = (3.14159, 1.618) 16 | func ourFunction(a: Int) { /* ... */ } 17 | 18 | // Type aliases 19 | 20 | typealias UnsignedInteger = UInt32 21 | 22 | //: [Next](@next) 23 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Subscripts.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Subscripts 6 | 7 | struct TimesTable { 8 | let multiplier: Int 9 | subscript(index: Int) -> Int { 10 | return multiplier * index 11 | } 12 | } 13 | 14 | let fiveTimesTable = TimesTable(multiplier: 5) 15 | print("six times five is \(fiveTimesTable[6])") 16 | // prints "six times five is 30” 17 | 18 | //: [Next](@next) 19 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Methods.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Methods 6 | 7 | class AClass { 8 | class func someTypeMethod() { 9 | // type method body 10 | } 11 | } 12 | 13 | // We can call this method as follows: 14 | AClass.someTypeMethod() 15 | 16 | //: [Next](@next) 17 | -------------------------------------------------------------------------------- /Playgrounds/Ch09-ImportanceOfImmutability.playground/Pages/FunctionalExample.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | struct Producer { 6 | let name: String 7 | let address: String 8 | } 9 | 10 | struct FunctionalProduct { 11 | let name: String 12 | let price: Double 13 | let quantity: Int 14 | let producer: Producer 15 | } 16 | 17 | struct FunctionalProductTracker { 18 | let products: [FunctionalProduct] 19 | let lastModified: Date 20 | 21 | func addNewProduct(item: FunctionalProduct) -> (date: Date, products: [FunctionalProduct]) { 22 | let newProducts = self.products + [item] 23 | return (date: Date(), products: newProducts) 24 | } 25 | } 26 | 27 | 28 | 29 | //: [Next](@next) 30 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/DeclarativeImperative.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | //: ### Declarative vs. Imperative 3 | 4 | let numbers = [9, 29, 19, 79] 5 | 6 | // Imperative example 7 | var tripledNumbers:[Int] = [] 8 | for number in numbers { 9 | tripledNumbers.append(number * 3) 10 | } 11 | print(tripledNumbers) 12 | 13 | // Declarative example 14 | let tripledIntNumbers = numbers.map({ 15 | number in 16 | number * 3 17 | }) 18 | print(tripledIntNumbers) 19 | 20 | let newTripledIntNumbers = numbers.map { $0 * 3 } 21 | 22 | //: [Next](@next) 23 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/ErrorHandling.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Error Protocol 6 | 7 | enum HttpError: Error { 8 | case badRequest 9 | case unauthorized 10 | case forbidden 11 | case requestTimeOut 12 | case unsupportedMediaType 13 | case internalServerError 14 | case notImplemented 15 | case badGateway 16 | case serviceUnavailable 17 | } 18 | 19 | //: [Next](@next) 20 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Tuples.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Tuples 6 | 7 | let http400Error = (400, "Bad Request") 8 | // http400Error is of type (Int, String), and equals (400, "Bad Request") 9 | 10 | // Decompose a Tuple's content 11 | let (requestStatusCode, requestStatusMessage) = http400Error 12 | 13 | //: [Next](@next) 14 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/ARC.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // ARC 6 | class AClassWithLazyClosure { 7 | lazy var aClosure: (Int, String) -> String = { 8 | [unowned self] (index: Int, stringToProcess: String) -> String in 9 | // closure body goes here 10 | return "" 11 | } 12 | } 13 | 14 | //: [Next](@next) 15 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/LazyEvaluation.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | //: ### Lazy evaluation 3 | 4 | import Foundation 5 | 6 | let oneToFour = [1, 2, 3, 4] 7 | let firstNumber = oneToFour.lazy.map({ $0 * 3}).first! 8 | print(firstNumber) // The result is going to be 3 9 | //: [Next](@next) 10 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/Argo/Sources/Argo/Types/Decoded/FailureCoalescing.swift: -------------------------------------------------------------------------------- 1 | /** 2 | Return the unwrapped value of the `Decoded` value on the left if it is 3 | `.Success`, otherwise return the default on the right. 4 | 5 | - If the left hand side is `.Success`, this will return the unwrapped value 6 | from the left hand side argument. 7 | - If the left hand side is `.Failure`, this will return the default value on 8 | the right hand side. 9 | 10 | - parameter lhs: A value of type `Decoded` 11 | - parameter rhs: An autoclosure returning a value of type `T` 12 | 13 | - returns: A value of type `T` 14 | */ 15 | public func ?? (lhs: Decoded, rhs: @autoclosure () -> T) -> T { 16 | switch lhs { 17 | case let .success(x): return x 18 | case .failure: return rhs() 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Protocols.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | protocol HttpProtocol{ 6 | func didRecieveResults(results: Any) 7 | } 8 | 9 | struct WebServiceManager { 10 | var delegate:HttpProtocol? 11 | let data: Data 12 | func test() { 13 | do { 14 | let jsonResult = try JSONSerialization.jsonObject(with: self.data, options: JSONSerialization.ReadingOptions.mutableContainers) 15 | self.delegate?.didRecieveResults(results: jsonResult) 16 | } catch let error as NSError { 17 | print("json error" + error.localizedDescription) 18 | } 19 | } 20 | } 21 | 22 | //: [Next](@next) 23 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Generics.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Generics 6 | 7 | func swapTwoIntegers( a: inout Int, b: inout Int) { 8 | let tempA = a 9 | a = b 10 | b = tempA 11 | } 12 | 13 | func swapTwoValues( a: inout T, b: inout T) { 14 | let tempA = a 15 | a = b 16 | b = tempA 17 | } 18 | 19 | //: [Next](@next) 20 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Initialization.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Initialization 6 | 7 | class ShoppingItem { 8 | var name: String? 9 | var quantity = 1 10 | var purchased = false 11 | } 12 | 13 | var item = ShoppingItem() 14 | 15 | //: [Next](@next) 16 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Immutability.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Immutability vs. Mutability 6 | 7 | var aMutableString = "This is a variable String" 8 | let aConstString = "This is a constant String" 9 | 10 | //: [Next](@next) 11 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Types.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | //: ### Types 3 | import Foundation 4 | 5 | // Type inference 6 | 7 | let constString = "This is a string constant" 8 | let pi = 3.14159 9 | var primeNumber = 691 10 | let name = "my name" 11 | 12 | // Type annotation 13 | 14 | let pi2: Double = 3.14159 15 | let piAndPhi: (Double, Double) = (3.14159, 1.618) 16 | func ourFunction(a: Int) { /* ... */ } 17 | 18 | // Type aliases 19 | 20 | typealias UnsignedInteger = UInt32 21 | 22 | //: [Next](@next) 23 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Subscripts.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Subscripts 6 | 7 | struct TimesTable { 8 | let multiplier: Int 9 | subscript(index: Int) -> Int { 10 | return multiplier * index 11 | } 12 | } 13 | 14 | let fiveTimesTable = TimesTable(multiplier: 5) 15 | print("six times five is \(fiveTimesTable[6])") 16 | // prints "six times five is 30” 17 | 18 | //: [Next](@next) 19 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Tuples.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Tuples 6 | 7 | let http400Error = (400, "Bad Request") 8 | // http400Error is of type (Int, String), and equals (400, "Bad Request") 9 | 10 | // Decompose a Tuple's content 11 | let (requestStatusCode, requestStatusMessage) = http400Error 12 | 13 | //: [Next](@next) 14 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Methods.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Methods 6 | 7 | class AClass { 8 | class func someTypeMethod() { 9 | // type method body 10 | } 11 | } 12 | 13 | // We can call this method as follows: 14 | AClass.someTypeMethod() 15 | 16 | //: [Next](@next) 17 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/ReactiveCocoa/ReactiveCocoa/ObjC+Runtime.swift: -------------------------------------------------------------------------------- 1 | /// Search in `class` for any method that matches the supplied selector without 2 | /// propagating to the ancestors. 3 | /// 4 | /// - parameters: 5 | /// - class: The class to search the method in. 6 | /// - selector: The selector of the method. 7 | /// 8 | /// - returns: 9 | /// The matching method, or `nil` if none is found. 10 | internal func class_getImmediateMethod(_ `class`: AnyClass, _ selector: Selector) -> Method? { 11 | if let buffer = class_copyMethodList(`class`, nil) { 12 | defer { free(buffer) } 13 | 14 | var iterator = buffer 15 | while let method = iterator.pointee { 16 | if method_getName(method) == selector { 17 | return method 18 | } 19 | iterator = iterator.advanced(by: 1) 20 | } 21 | } 22 | 23 | return nil 24 | } 25 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Pages/Collections.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Collections 6 | 7 | // Arrays and Dictionaries 8 | var cheeses = ["Brie", "Tete de Moine", "Cambozola", "Camembert"] 9 | cheeses[2] = "Roquefort" 10 | var cheeseWinePairs = [ 11 | "Brie":"Chardonnay", 12 | "Camembert":"Champagne", 13 | "Gruyere":"Sauvignon Blanc" 14 | ] 15 | 16 | cheeseWinePairs ["Cheddar"] = "Cabarnet Sauvignon" 17 | // To create an empty array or dictionary 18 | let emptyArray = [String]() 19 | let emptyDictionary = Dictionary() 20 | cheeses = [] 21 | cheeseWinePairs = [:] 22 | 23 | 24 | // Iteration over dictionaries 25 | 26 | for (cheese, wine) in cheeseWinePairs { 27 | print("\(cheese): \(wine)") 28 | } 29 | 30 | //: [Next](@next) 31 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/DeclarativeImperative.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | //: ### Declarative vs. Imperative 3 | 4 | let numbers = [9, 29, 19, 79] 5 | 6 | // Imperative example 7 | var tripledNumbers:[Int] = [] 8 | for number in numbers { 9 | tripledNumbers.append(number * 3) 10 | } 11 | print(tripledNumbers) 12 | 13 | // Declarative example 14 | let tripledIntNumbers = numbers.map({ 15 | number in 16 | number * 3 17 | }) 18 | print(tripledIntNumbers) 19 | 20 | let newTripledIntNumbers = numbers.map { $0 * 3 } 21 | 22 | //: [Next](@next) 23 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/ErrorHandling.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Error Protocol 6 | 7 | enum HttpError: Error { 8 | case badRequest 9 | case unauthorized 10 | case forbidden 11 | case requestTimeOut 12 | case unsupportedMediaType 13 | case internalServerError 14 | case notImplemented 15 | case badGateway 16 | case serviceUnavailable 17 | } 18 | 19 | //: [Next](@next) 20 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/LazyEvaluation.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | //: ### Lazy evaluation 3 | 4 | import Foundation 5 | 6 | let oneToFour = [1, 2, 3, 4] 7 | let firstNumber = oneToFour.lazy.map({ $0 * 3}).first! 8 | print(firstNumber) // The result is going to be 3 9 | //: [Next](@next) 10 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/ARC.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // ARC 6 | class AClassWithLazyClosure { 7 | lazy var aClosure: (Int, String) -> String = { 8 | [unowned self] (index: Int, stringToProcess: String) -> String in 9 | // closure body goes here 10 | return "" 11 | } 12 | } 13 | 14 | //: [Next](@next) 15 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/ReactiveCocoa/ReactiveCocoa/UIKit/UIView.swift: -------------------------------------------------------------------------------- 1 | import ReactiveSwift 2 | import UIKit 3 | 4 | extension Reactive where Base: UIView { 5 | /// Sets the alpha value of the view. 6 | public var alpha: BindingTarget { 7 | return makeBindingTarget { $0.alpha = $1 } 8 | } 9 | 10 | /// Sets whether the view is hidden. 11 | public var isHidden: BindingTarget { 12 | return makeBindingTarget { $0.isHidden = $1 } 13 | } 14 | 15 | /// Sets whether the view accepts user interactions. 16 | public var isUserInteractionEnabled: BindingTarget { 17 | return makeBindingTarget { $0.isUserInteractionEnabled = $1 } 18 | } 19 | 20 | /// Sets the background color of the view. 21 | public var backgroundColor: BindingTarget { 22 | return makeBindingTarget { $0.backgroundColor = $1 } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Protocols.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | protocol HttpProtocol{ 6 | func didRecieveResults(results: Any) 7 | } 8 | 9 | struct WebServiceManager { 10 | var delegate:HttpProtocol? 11 | let data: Data 12 | func test() { 13 | do { 14 | let jsonResult = try JSONSerialization.jsonObject(with: self.data, options: JSONSerialization.ReadingOptions.mutableContainers) 15 | self.delegate?.didRecieveResults(results: jsonResult) 16 | } catch let error as NSError { 17 | print("json error" + error.localizedDescription) 18 | } 19 | } 20 | } 21 | 22 | //: [Next](@next) 23 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Generics.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Generics 6 | 7 | func swapTwoIntegers( a: inout Int, b: inout Int) { 8 | let tempA = a 9 | a = b 10 | b = tempA 11 | } 12 | 13 | func swapTwoValues( a: inout T, b: inout T) { 14 | let tempA = a 15 | a = b 16 | b = tempA 17 | } 18 | 19 | //: [Next](@next) 20 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Initialization.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Initialization 6 | 7 | class ShoppingItem { 8 | var name: String? 9 | var quantity = 1 10 | var purchased = false 11 | } 12 | 13 | var item = ShoppingItem() 14 | 15 | //: [Next](@next) 16 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Immutability.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Immutability vs. Mutability 6 | 7 | var aMutableString = "This is a variable String" 8 | let aConstString = "This is a constant String" 9 | 10 | //: [Next](@next) 11 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/TodoAppTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Types.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | //: ### Types 3 | import Foundation 4 | 5 | // Type inference 6 | 7 | let constString = "This is a string constant" 8 | let pi = 3.14159 9 | var primeNumber = 691 10 | let name = "my name" 11 | 12 | // Type annotation 13 | 14 | let pi2: Double = 3.14159 15 | let piAndPhi: (Double, Double) = (3.14159, 1.618) 16 | func ourFunction(a: Int) { /* ... */ } 17 | 18 | // Type aliases 19 | 20 | typealias UnsignedInteger = UInt32 21 | 22 | //: [Next](@next) 23 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Subscripts.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Subscripts 6 | 7 | struct TimesTable { 8 | let multiplier: Int 9 | subscript(index: Int) -> Int { 10 | return multiplier * index 11 | } 12 | } 13 | 14 | let fiveTimesTable = TimesTable(multiplier: 5) 15 | print("six times five is \(fiveTimesTable[6])") 16 | // prints "six times five is 30” 17 | 18 | //: [Next](@next) 19 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Tuples.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Tuples 6 | 7 | let http400Error = (400, "Bad Request") 8 | // http400Error is of type (Int, String), and equals (400, "Bad Request") 9 | 10 | // Decompose a Tuple's content 11 | let (requestStatusCode, requestStatusMessage) = http400Error 12 | 13 | //: [Next](@next) 14 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Methods.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Methods 6 | 7 | class AClass { 8 | class func someTypeMethod() { 9 | // type method body 10 | } 11 | } 12 | 13 | // We can call this method as follows: 14 | AClass.someTypeMethod() 15 | 16 | //: [Next](@next) 17 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Collections.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Collections 6 | 7 | // Arrays and Dictionaries 8 | var cheeses = ["Brie", "Tete de Moine", "Cambozola", "Camembert"] 9 | cheeses[2] = "Roquefort" 10 | var cheeseWinePairs = [ 11 | "Brie":"Chardonnay", 12 | "Camembert":"Champagne", 13 | "Gruyere":"Sauvignon Blanc" 14 | ] 15 | 16 | cheeseWinePairs ["Cheddar"] = "Cabarnet Sauvignon" 17 | // To create an empty array or dictionary 18 | let emptyArray = [String]() 19 | let emptyDictionary = Dictionary() 20 | cheeses = [] 21 | cheeseWinePairs = [:] 22 | 23 | 24 | // Iteration over dictionaries 25 | 26 | for (cheese, wine) in cheeseWinePairs { 27 | print("\(cheese): \(wine)") 28 | } 29 | 30 | //: [Next](@next) 31 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/DeclarativeImperative.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | //: ### Declarative vs. Imperative 3 | 4 | let numbers = [9, 29, 19, 79] 5 | 6 | // Imperative example 7 | var tripledNumbers:[Int] = [] 8 | for number in numbers { 9 | tripledNumbers.append(number * 3) 10 | } 11 | print(tripledNumbers) 12 | 13 | // Declarative example 14 | let tripledIntNumbers = numbers.map({ 15 | number in 16 | number * 3 17 | }) 18 | print(tripledIntNumbers) 19 | 20 | let newTripledIntNumbers = numbers.map { $0 * 3 } 21 | 22 | //: [Next](@next) 23 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/ErrorHandling.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Error Protocol 6 | 7 | enum HttpError: Error { 8 | case badRequest 9 | case unauthorized 10 | case forbidden 11 | case requestTimeOut 12 | case unsupportedMediaType 13 | case internalServerError 14 | case notImplemented 15 | case badGateway 16 | case serviceUnavailable 17 | } 18 | 19 | //: [Next](@next) 20 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/ARC.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // ARC 6 | class AClassWithLazyClosure { 7 | lazy var aClosure: (Int, String) -> String = { 8 | [unowned self] (index: Int, stringToProcess: String) -> String in 9 | // closure body goes here 10 | return "" 11 | } 12 | } 13 | 14 | //: [Next](@next) 15 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/LazyEvaluation.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | //: ### Lazy evaluation 3 | 4 | import Foundation 5 | 6 | let oneToFour = [1, 2, 3, 4] 7 | let firstNumber = oneToFour.lazy.map({ $0 * 3}).first! 8 | print(firstNumber) // The result is going to be 3 9 | //: [Next](@next) 10 | -------------------------------------------------------------------------------- /Ch11-Backend/vapor-example/VaporApp.xcodeproj/Console_Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CFBundleDevelopmentRegion 5 | en 6 | CFBundleExecutable 7 | $(EXECUTABLE_NAME) 8 | CFBundleIdentifier 9 | $(PRODUCT_BUNDLE_IDENTIFIER) 10 | CFBundleInfoDictionaryVersion 11 | 6.0 12 | CFBundleName 13 | $(PRODUCT_NAME) 14 | CFBundlePackageType 15 | FMWK 16 | CFBundleShortVersionString 17 | 1.0 18 | CFBundleSignature 19 | ???? 20 | CFBundleVersion 21 | $(CURRENT_PROJECT_VERSION) 22 | NSPrincipalClass 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Ch11-Backend/vapor-example/VaporApp.xcodeproj/Core_Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CFBundleDevelopmentRegion 5 | en 6 | CFBundleExecutable 7 | $(EXECUTABLE_NAME) 8 | CFBundleIdentifier 9 | $(PRODUCT_BUNDLE_IDENTIFIER) 10 | CFBundleInfoDictionaryVersion 11 | 6.0 12 | CFBundleName 13 | $(PRODUCT_NAME) 14 | CFBundlePackageType 15 | FMWK 16 | CFBundleShortVersionString 17 | 1.0 18 | CFBundleSignature 19 | ???? 20 | CFBundleVersion 21 | $(CURRENT_PROJECT_VERSION) 22 | NSPrincipalClass 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Ch11-Backend/vapor-example/VaporApp.xcodeproj/Fluent_Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CFBundleDevelopmentRegion 5 | en 6 | CFBundleExecutable 7 | $(EXECUTABLE_NAME) 8 | CFBundleIdentifier 9 | $(PRODUCT_BUNDLE_IDENTIFIER) 10 | CFBundleInfoDictionaryVersion 11 | 6.0 12 | CFBundleName 13 | $(PRODUCT_NAME) 14 | CFBundlePackageType 15 | FMWK 16 | CFBundleShortVersionString 17 | 1.0 18 | CFBundleSignature 19 | ???? 20 | CFBundleVersion 21 | $(CURRENT_PROJECT_VERSION) 22 | NSPrincipalClass 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Ch11-Backend/vapor-example/VaporApp.xcodeproj/HMAC_Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CFBundleDevelopmentRegion 5 | en 6 | CFBundleExecutable 7 | $(EXECUTABLE_NAME) 8 | CFBundleIdentifier 9 | $(PRODUCT_BUNDLE_IDENTIFIER) 10 | CFBundleInfoDictionaryVersion 11 | 6.0 12 | CFBundleName 13 | $(PRODUCT_NAME) 14 | CFBundlePackageType 15 | FMWK 16 | CFBundleShortVersionString 17 | 1.0 18 | CFBundleSignature 19 | ???? 20 | CFBundleVersion 21 | $(CURRENT_PROJECT_VERSION) 22 | NSPrincipalClass 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Ch11-Backend/vapor-example/VaporApp.xcodeproj/HTTP_Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CFBundleDevelopmentRegion 5 | en 6 | CFBundleExecutable 7 | $(EXECUTABLE_NAME) 8 | CFBundleIdentifier 9 | $(PRODUCT_BUNDLE_IDENTIFIER) 10 | CFBundleInfoDictionaryVersion 11 | 6.0 12 | CFBundleName 13 | $(PRODUCT_NAME) 14 | CFBundlePackageType 15 | FMWK 16 | CFBundleShortVersionString 17 | 1.0 18 | CFBundleSignature 19 | ???? 20 | CFBundleVersion 21 | $(CURRENT_PROJECT_VERSION) 22 | NSPrincipalClass 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Ch11-Backend/vapor-example/VaporApp.xcodeproj/JSON_Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CFBundleDevelopmentRegion 5 | en 6 | CFBundleExecutable 7 | $(EXECUTABLE_NAME) 8 | CFBundleIdentifier 9 | $(PRODUCT_BUNDLE_IDENTIFIER) 10 | CFBundleInfoDictionaryVersion 11 | 6.0 12 | CFBundleName 13 | $(PRODUCT_NAME) 14 | CFBundlePackageType 15 | FMWK 16 | CFBundleShortVersionString 17 | 1.0 18 | CFBundleSignature 19 | ???? 20 | CFBundleVersion 21 | $(CURRENT_PROJECT_VERSION) 22 | NSPrincipalClass 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Ch11-Backend/vapor-example/VaporApp.xcodeproj/Node_Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CFBundleDevelopmentRegion 5 | en 6 | CFBundleExecutable 7 | $(EXECUTABLE_NAME) 8 | CFBundleIdentifier 9 | $(PRODUCT_BUNDLE_IDENTIFIER) 10 | CFBundleInfoDictionaryVersion 11 | 6.0 12 | CFBundleName 13 | $(PRODUCT_NAME) 14 | CFBundlePackageType 15 | FMWK 16 | CFBundleShortVersionString 17 | 1.0 18 | CFBundleSignature 19 | ???? 20 | CFBundleVersion 21 | $(CURRENT_PROJECT_VERSION) 22 | NSPrincipalClass 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Ch11-Backend/vapor-example/VaporApp.xcodeproj/Routing_Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CFBundleDevelopmentRegion 5 | en 6 | CFBundleExecutable 7 | $(EXECUTABLE_NAME) 8 | CFBundleIdentifier 9 | $(PRODUCT_BUNDLE_IDENTIFIER) 10 | CFBundleInfoDictionaryVersion 11 | 6.0 12 | CFBundleName 13 | $(PRODUCT_NAME) 14 | CFBundlePackageType 15 | FMWK 16 | CFBundleShortVersionString 17 | 1.0 18 | CFBundleSignature 19 | ???? 20 | CFBundleVersion 21 | $(CURRENT_PROJECT_VERSION) 22 | NSPrincipalClass 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Ch11-Backend/vapor-example/VaporApp.xcodeproj/SMTP_Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CFBundleDevelopmentRegion 5 | en 6 | CFBundleExecutable 7 | $(EXECUTABLE_NAME) 8 | CFBundleIdentifier 9 | $(PRODUCT_BUNDLE_IDENTIFIER) 10 | CFBundleInfoDictionaryVersion 11 | 6.0 12 | CFBundleName 13 | $(PRODUCT_NAME) 14 | CFBundlePackageType 15 | FMWK 16 | CFBundleShortVersionString 17 | 1.0 18 | CFBundleSignature 19 | ???? 20 | CFBundleVersion 21 | $(CURRENT_PROJECT_VERSION) 22 | NSPrincipalClass 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Ch11-Backend/vapor-example/VaporApp.xcodeproj/Socks_Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CFBundleDevelopmentRegion 5 | en 6 | CFBundleExecutable 7 | $(EXECUTABLE_NAME) 8 | CFBundleIdentifier 9 | $(PRODUCT_BUNDLE_IDENTIFIER) 10 | CFBundleInfoDictionaryVersion 11 | 6.0 12 | CFBundleName 13 | $(PRODUCT_NAME) 14 | CFBundlePackageType 15 | FMWK 16 | CFBundleShortVersionString 17 | 1.0 18 | CFBundleSignature 19 | ???? 20 | CFBundleVersion 21 | $(CURRENT_PROJECT_VERSION) 22 | NSPrincipalClass 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Ch11-Backend/vapor-example/VaporApp.xcodeproj/URI_Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CFBundleDevelopmentRegion 5 | en 6 | CFBundleExecutable 7 | $(EXECUTABLE_NAME) 8 | CFBundleIdentifier 9 | $(PRODUCT_BUNDLE_IDENTIFIER) 10 | CFBundleInfoDictionaryVersion 11 | 6.0 12 | CFBundleName 13 | $(PRODUCT_NAME) 14 | CFBundlePackageType 15 | FMWK 16 | CFBundleShortVersionString 17 | 1.0 18 | CFBundleSignature 19 | ???? 20 | CFBundleVersion 21 | $(CURRENT_PROJECT_VERSION) 22 | NSPrincipalClass 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Ch11-Backend/vapor-example/VaporApp.xcodeproj/Vapor_Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CFBundleDevelopmentRegion 5 | en 6 | CFBundleExecutable 7 | $(EXECUTABLE_NAME) 8 | CFBundleIdentifier 9 | $(PRODUCT_BUNDLE_IDENTIFIER) 10 | CFBundleInfoDictionaryVersion 11 | 6.0 12 | CFBundleName 13 | $(PRODUCT_NAME) 14 | CFBundlePackageType 15 | FMWK 16 | CFBundleShortVersionString 17 | 1.0 18 | CFBundleSignature 19 | ???? 20 | CFBundleVersion 21 | $(CURRENT_PROJECT_VERSION) 22 | NSPrincipalClass 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Ch11-Backend/vapor-example/VaporApp.xcodeproj/libc_Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CFBundleDevelopmentRegion 5 | en 6 | CFBundleExecutable 7 | $(EXECUTABLE_NAME) 8 | CFBundleIdentifier 9 | $(PRODUCT_BUNDLE_IDENTIFIER) 10 | CFBundleInfoDictionaryVersion 11 | 6.0 12 | CFBundleName 13 | $(PRODUCT_NAME) 14 | CFBundlePackageType 15 | FMWK 16 | CFBundleShortVersionString 17 | 1.0 18 | CFBundleSignature 19 | ???? 20 | CFBundleVersion 21 | $(CURRENT_PROJECT_VERSION) 22 | NSPrincipalClass 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Ch11-Backend/vapor-example/Sources/App/Middleware/SampleMiddleware.swift: -------------------------------------------------------------------------------- 1 | import Vapor 2 | import HTTP 3 | 4 | class SampleMiddleware: Middleware { 5 | 6 | func respond(to request: Request, chainingTo chain: Responder) throws -> Response { 7 | // You can manipulate the request before calling the handler 8 | // and abort early if necessary, a good injection point for 9 | // handling auth. 10 | 11 | // return Response(status: .Forbidden, text: "Permission denied") 12 | 13 | let response = try chain.respond(to: request) 14 | 15 | // You can also manipulate the response to add headers 16 | // cookies, etc. 17 | 18 | return response 19 | 20 | // Vapor Middleware is based on S4 Middleware. 21 | // This means you can share it with any other project 22 | // that uses S4 Middleware. 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /Ch11-Backend/vapor-example/Sources/App/Models/User.swift: -------------------------------------------------------------------------------- 1 | import Vapor 2 | import Fluent 3 | 4 | final class User: Model { 5 | var id: Node? 6 | var name: String 7 | 8 | init(name: String) { 9 | self.name = name 10 | } 11 | 12 | init(node: Node, in context: Context) throws { 13 | id = try node.extract("id") 14 | name = try node.extract("name") 15 | } 16 | 17 | func makeNode(context: Context) throws -> Node { 18 | return try Node(node: [ 19 | "name": name 20 | ]) 21 | } 22 | 23 | static func prepare(_ database: Database) throws { 24 | // 25 | } 26 | 27 | static func revert(_ database: Database) throws { 28 | // 29 | } 30 | } 31 | 32 | extension User { 33 | public convenience init?(from string: String) throws { 34 | self.init(name: string) 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Ch11-Backend/vapor-example/VaporApp.xcodeproj/HTTPRouting_Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CFBundleDevelopmentRegion 5 | en 6 | CFBundleExecutable 7 | $(EXECUTABLE_NAME) 8 | CFBundleIdentifier 9 | $(PRODUCT_BUNDLE_IDENTIFIER) 10 | CFBundleInfoDictionaryVersion 11 | 6.0 12 | CFBundleName 13 | $(PRODUCT_NAME) 14 | CFBundlePackageType 15 | FMWK 16 | CFBundleShortVersionString 17 | 1.0 18 | CFBundleSignature 19 | ???? 20 | CFBundleVersion 21 | $(CURRENT_PROJECT_VERSION) 22 | NSPrincipalClass 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Ch11-Backend/vapor-example/VaporApp.xcodeproj/Polymorphic_Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CFBundleDevelopmentRegion 5 | en 6 | CFBundleExecutable 7 | $(EXECUTABLE_NAME) 8 | CFBundleIdentifier 9 | $(PRODUCT_BUNDLE_IDENTIFIER) 10 | CFBundleInfoDictionaryVersion 11 | 6.0 12 | CFBundleName 13 | $(PRODUCT_NAME) 14 | CFBundlePackageType 15 | FMWK 16 | CFBundleShortVersionString 17 | 1.0 18 | CFBundleSignature 19 | ???? 20 | CFBundleVersion 21 | $(CURRENT_PROJECT_VERSION) 22 | NSPrincipalClass 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Ch11-Backend/vapor-example/VaporApp.xcodeproj/SocksCore_Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CFBundleDevelopmentRegion 5 | en 6 | CFBundleExecutable 7 | $(EXECUTABLE_NAME) 8 | CFBundleIdentifier 9 | $(PRODUCT_BUNDLE_IDENTIFIER) 10 | CFBundleInfoDictionaryVersion 11 | 6.0 12 | CFBundleName 13 | $(PRODUCT_NAME) 14 | CFBundlePackageType 15 | FMWK 16 | CFBundleShortVersionString 17 | 1.0 18 | CFBundleSignature 19 | ???? 20 | CFBundleVersion 21 | $(CURRENT_PROJECT_VERSION) 22 | NSPrincipalClass 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Ch11-Backend/vapor-example/VaporApp.xcodeproj/Transport_Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CFBundleDevelopmentRegion 5 | en 6 | CFBundleExecutable 7 | $(EXECUTABLE_NAME) 8 | CFBundleIdentifier 9 | $(PRODUCT_BUNDLE_IDENTIFIER) 10 | CFBundleInfoDictionaryVersion 11 | 6.0 12 | CFBundleName 13 | $(PRODUCT_NAME) 14 | CFBundlePackageType 15 | FMWK 16 | CFBundleShortVersionString 17 | 1.0 18 | CFBundleSignature 19 | ???? 20 | CFBundleVersion 21 | $(CURRENT_PROJECT_VERSION) 22 | NSPrincipalClass 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Ch11-Backend/vapor-example/VaporApp.xcodeproj/WebSockets_Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CFBundleDevelopmentRegion 5 | en 6 | CFBundleExecutable 7 | $(EXECUTABLE_NAME) 8 | CFBundleIdentifier 9 | $(PRODUCT_BUNDLE_IDENTIFIER) 10 | CFBundleInfoDictionaryVersion 11 | 6.0 12 | CFBundleName 13 | $(PRODUCT_NAME) 14 | CFBundlePackageType 15 | FMWK 16 | CFBundleShortVersionString 17 | 1.0 18 | CFBundleSignature 19 | ???? 20 | CFBundleVersion 21 | $(CURRENT_PROJECT_VERSION) 22 | NSPrincipalClass 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Initialization.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Initialization 6 | 7 | class ShoppingItem { 8 | var name: String? 9 | var quantity = 1 10 | var purchased = false 11 | } 12 | 13 | var item = ShoppingItem() 14 | 15 | //: [Next](@next) 16 | -------------------------------------------------------------------------------- /Ch11-Backend/vapor-example/VaporApp.xcodeproj/PathIndexable_Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CFBundleDevelopmentRegion 5 | en 6 | CFBundleExecutable 7 | $(EXECUTABLE_NAME) 8 | CFBundleIdentifier 9 | $(PRODUCT_BUNDLE_IDENTIFIER) 10 | CFBundleInfoDictionaryVersion 11 | 6.0 12 | CFBundleName 13 | $(PRODUCT_NAME) 14 | CFBundlePackageType 15 | FMWK 16 | CFBundleShortVersionString 17 | 1.0 18 | CFBundleSignature 19 | ???? 20 | CFBundleVersion 21 | $(CURRENT_PROJECT_VERSION) 22 | NSPrincipalClass 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Ch11-Backend/vapor-example/VaporApp.xcodeproj/TypeSafeRouting_Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CFBundleDevelopmentRegion 5 | en 6 | CFBundleExecutable 7 | $(EXECUTABLE_NAME) 8 | CFBundleIdentifier 9 | $(PRODUCT_BUNDLE_IDENTIFIER) 10 | CFBundleInfoDictionaryVersion 11 | 6.0 12 | CFBundleName 13 | $(PRODUCT_NAME) 14 | CFBundlePackageType 15 | FMWK 16 | CFBundleShortVersionString 17 | 1.0 18 | CFBundleSignature 19 | ???? 20 | CFBundleVersion 21 | $(CURRENT_PROJECT_VERSION) 22 | NSPrincipalClass 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Ch11-Frontend/TodoApp/Pods/ReactiveCocoa/ReactiveCocoa/UIKit/iOS/UIStepper.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | import ReactiveSwift 3 | import enum Result.NoError 4 | 5 | extension Reactive where Base: UIStepper { 6 | 7 | /// Sets the stepper's value. 8 | public var value: BindingTarget { 9 | return makeBindingTarget { $0.value = $1 } 10 | } 11 | 12 | /// Sets stepper's minimum value. 13 | public var minimumValue: BindingTarget { 14 | return makeBindingTarget { $0.minimumValue = $1 } 15 | } 16 | 17 | /// Sets stepper's maximum value. 18 | public var maximumValue: BindingTarget { 19 | return makeBindingTarget { $0.maximumValue = $1 } 20 | } 21 | 22 | /// A signal of double values emitted by the stepper upon each user's 23 | /// interaction. 24 | public var values: Signal { 25 | return controlEvents(.valueChanged).map { $0.value } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Protocols.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | protocol HttpProtocol{ 6 | func didRecieveResults(results: Any) 7 | } 8 | 9 | struct WebServiceManager { 10 | var delegate:HttpProtocol? 11 | let data: Data 12 | func test() { 13 | do { 14 | let jsonResult = try JSONSerialization.jsonObject(with: self.data, options: JSONSerialization.ReadingOptions.mutableContainers) 15 | self.delegate?.didRecieveResults(results: jsonResult) 16 | } catch let error as NSError { 17 | print("json error" + error.localizedDescription) 18 | } 19 | } 20 | } 21 | 22 | //: [Next](@next) 23 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Generics.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Generics 6 | 7 | func swapTwoIntegers( a: inout Int, b: inout Int) { 8 | let tempA = a 9 | a = b 10 | b = tempA 11 | } 12 | 13 | func swapTwoValues( a: inout T, b: inout T) { 14 | let tempA = a 15 | a = b 16 | b = tempA 17 | } 18 | 19 | //: [Next](@next) 20 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Immutability.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Immutability vs. Mutability 6 | 7 | var aMutableString = "This is a variable String" 8 | let aConstString = "This is a constant String" 9 | 10 | //: [Next](@next) 11 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Pages/Strings.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // String literal 6 | 7 | let aVegetable = "Arugula" 8 | 9 | // Initializing an Empty String 10 | var anEmptyString = "" 11 | var anotherEmptyString = String() 12 | 13 | if anEmptyString.isEmpty { 14 | print("String is empty") 15 | } 16 | 17 | // Concatenating Strings and Characters 18 | 19 | let string1 = "Hello" 20 | let string2 = " Mr" 21 | var welcome = string1 + string2 22 | 23 | var instruction = "Follow us please" 24 | instruction += string2 25 | 26 | let exclamationMark: Character = "!" 27 | welcome.append(exclamationMark) 28 | 29 | 30 | // String Interpolation 31 | 32 | let multiplier = 3 33 | let message = "\(multiplier) times 7.5 is \(Double (multiplier) * 7.5)" 34 | // message is "3 times 2.5 is 22.5” 35 | 36 | //: [Next](@next) 37 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Pages/AnyAnyObject.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Any and AnyObject - not recommended 6 | 7 | class Movie { 8 | var director: String 9 | var name: String 10 | init(name: String, director: String) { 11 | self.director = director 12 | self.name = name 13 | } 14 | } 15 | 16 | let objects: [AnyObject] = [ 17 | Movie(name: "The Shawshank Redemption", director: "Frank Darabont"), 18 | Movie(name: "The Godfather", director: "Francis Ford Coppola") 19 | ] 20 | 21 | for object in objects { 22 | let movie = object as! Movie 23 | print("Movie: '\(movie.name)', dir. \(movie.director)") 24 | } 25 | 26 | // Shorter syntax 27 | for movie in objects as! [Movie] { 28 | print("Movie: '\(movie.name)', dir. \(movie.director)") 29 | } 30 | 31 | //: [Next](@next) 32 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Types.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | //: ### Types 3 | import Foundation 4 | 5 | // Type inference 6 | 7 | let constString = "This is a string constant" 8 | let pi = 3.14159 9 | var primeNumber = 691 10 | let name = "my name" 11 | 12 | // Type annotation 13 | 14 | let pi2: Double = 3.14159 15 | let piAndPhi: (Double, Double) = (3.14159, 1.618) 16 | func ourFunction(a: Int) { /* ... */ } 17 | 18 | // Type aliases 19 | 20 | typealias UnsignedInteger = UInt32 21 | 22 | //: [Next](@next) 23 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/DeclarativeImperative.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | //: ### Declarative vs. Imperative 3 | 4 | let numbers = [9, 29, 19, 79] 5 | 6 | // Imperative example 7 | var tripledNumbers:[Int] = [] 8 | for number in numbers { 9 | tripledNumbers.append(number * 3) 10 | } 11 | print(tripledNumbers) 12 | 13 | // Declarative example 14 | let tripledIntNumbers = numbers.map({ 15 | number in 16 | number * 3 17 | }) 18 | print(tripledIntNumbers) 19 | 20 | let newTripledIntNumbers = numbers.map { $0 * 3 } 21 | 22 | //: [Next](@next) 23 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/ErrorHandling.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Error Protocol 6 | 7 | enum HttpError: Error { 8 | case badRequest 9 | case unauthorized 10 | case forbidden 11 | case requestTimeOut 12 | case unsupportedMediaType 13 | case internalServerError 14 | case notImplemented 15 | case badGateway 16 | case serviceUnavailable 17 | } 18 | 19 | //: [Next](@next) 20 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Subscripts.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Subscripts 6 | 7 | struct TimesTable { 8 | let multiplier: Int 9 | subscript(index: Int) -> Int { 10 | return multiplier * index 11 | } 12 | } 13 | 14 | let fiveTimesTable = TimesTable(multiplier: 5) 15 | print("six times five is \(fiveTimesTable[6])") 16 | // prints "six times five is 30” 17 | 18 | //: [Next](@next) 19 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Tuples.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Tuples 6 | 7 | let http400Error = (400, "Bad Request") 8 | // http400Error is of type (Int, String), and equals (400, "Bad Request") 9 | 10 | // Decompose a Tuple's content 11 | let (requestStatusCode, requestStatusMessage) = http400Error 12 | 13 | //: [Next](@next) 14 | -------------------------------------------------------------------------------- /Playgrounds/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Resources/Ch01-Introduction.playground/Pages/Methods.xcplaygroundpage/Contents.swift: -------------------------------------------------------------------------------- 1 | //: [Previous](@previous) 2 | 3 | import Foundation 4 | 5 | // Methods 6 | 7 | class AClass { 8 | class func someTypeMethod() { 9 | // type method body 10 | } 11 | } 12 | 13 | // We can call this method as follows: 14 | AClass.someTypeMethod() 15 | 16 | //: [Next](@next) 17 | --------------------------------------------------------------------------------