售 价:¥
温馨提示:数字商品不支持退换货,不提供源文件,不支持导出打印
为你推荐
Title Page
Copyright
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Dedication
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Downloading the color images of this book
Errata
Piracy
Questions
Hello macOS
It's going to be Swift
And more than Swift
It's going to be Xcode and more
Prerequisites
The book's overall structure
How Unix, macOS, Cocoa, and AppKit fit together
Darwin
macOS
Cocoa
Harnessing that power
The serious developer's toolkit
What you'll get from this book
Summary
Basic Swift
Variables and types
Number types
Integers
Booleans
Strings
Printing to the console
Comments
Arrays, dictionaries, and sets
Arrays
Dictionaries
Sets
Naming of types and variables
Type aliases
Value and reference types
Operators
Mathematical operators
Augmented assignment
Comparison operators
Logical operators
Other standard operators
Ternary operator
Nil-coalescing operator
Structs, classes, and other data structures
Structs
Classes
Optional instances
Tuples
Enumerations
Optionals
Why use optionals?
Unwrapping an optional
Control flow
if else
switch
Loops
Saying goodbye to i++
Iterating with for loops
while
Functions
Summary
Checking Out the Power of Xcode
A quick and simple sketch app
Speeding it up with code snippets
Checking out the supplied snippets
Usage
Rolling your own snippets
Logging with special literals
Getting the most out of breakpoints
Editing breakpoint options
Other actions
Adding a debugger command
Triggering an AppleScript or shell script
Don't stop me now
Behaviors
Understanding schemes
What schemes actually do
Creating a new scheme
Using scheme environment variables
Why build configs are so cool
Creating a new build configuration
Creating user-defined build settings
Adapting the Info.plist file
Using Swift compiler custom flags
Creating the custom flag
Using custom flags in code
Finding the build settings on disk
Summary
MVC and Other Design Patterns
Programming paradigms
So, what is meant by paradigm?
Imperative
Object-oriented programming
Class-based programming
Protocol-oriented programming
The drawbacks of OOP
Declarative programming
Understanding functional programming
Using functional concepts within OOP
Learning functional programming the fast way
Encapsulation
Separation of concerns
Simplification
A path through the forest
Functions
Data flow
Objects
Design patterns
Summary
Advanced Swift
Control flow
Using switch
Compound cases
Tuple matching
Value binding
Using the where keyword
Control transfer statements
The break statement
The fallthrough statement
The guard statement
Functions
Arguments
Default arguments
Anonymous arguments
Variadic arguments
Function overloading
Function naming in Swift 3.0
First class functions
Functions are typed
Closures
Closures that take arguments
Closures with multiple arguments
Alternative closure syntax
Closures are functions; functions are closures
Using map, reduce, and filter
Map with arrays
Map with dictionaries
reduce
filter
Nesting and chaining map, reduce, and filter
Nesting
Chaining
Enumerations as data structures
Adding methods to enums
Associated values
Grouping together different data types
Creating multiple distinct types from a single type
Mixed type arrays, anybody?
Recursive definitions
Making constants with an enum
Replacing classes
Protocols
Declaring method requirements
Conforming to a protocol
Protocol advantages over classes
Extending existing types with a protocol
Creating collections of mixed types
Protocols can conform to protocols
Declaring required properties
Implementing required properties
Class-only protocols
Class considerations
Protocol composition
Customizing operators
Adding operator implementations to types
Equivalence
Custom operators
Defining a custom operator
Prefix operators
Postfix operators
Infix operators
Implementing a custom operator
Collection types
Arrays
Comparing arrays
Mutating an array
Using arrays to create new arrays
Testing array elements
Removing elements from an array
Methods that mutate and return a value
Mutating non-returning methods
Sorting arrays
Dictionaries
Accessing all keys or values
Mutating dictionaries
Removing dictionary elements
Optionals
Conditional downcasting
Unwrapping optionals with guard
Implicitly unwrapped optionals
Summary
Cocoa Frameworks - The Backbone of Your Apps
Understanding Foundation Kit
Understanding NSObject
Import statements
Leveraging key-value observing
Coding for KVO
KVO - compliant classes
Adding the observer
Reacting to value changes
Removing the observer
Trying it out
Modifying ViewController
Cocoa bindings
Adding the data model
Adding an NSArrayController
Binding the table view
Binding the table selection
Adding the binding
Adding and binding a text field
Changing array values
Pretty Boolean
Summary
Creating Views Programmatically
Why code instead of IB?
Setting our goals
The steps involved
Beyond the visuals
Coding a table view
Preparing the View Controller
The table and label
Adding the table
Configuring the table's columns
Adding the info label
Providing the app with data
Importing the Person class
The data model
Creating a property list with XML
Getting data from the property list
Adopting datasource and delegate protocols
Datasource extension
Delegate extension
Returning table view columns
Reacting to selection events
Observing without bindings
Adding KVO to the View Controller
Adding an observer
Handling changes in the data
Removing an observer
Triggering changes to the data
Advantages of KVO in code
The final line of code
Adding further control elements in code
Adding the sort button
Implementing a button's action
Running the app
Summary
Strings and Text
Strings and characters
What is a String in Swift?
What is a Character?
Unicode compliance
Combining strings and characters
String indices and subranges
Obtaining a String.Index
Obtaining a subrange
Modifying strings
Removing characters
Inserting characters
String interpolation
Writing long strings
Escape characters
Other representations
C strings
NSString
Some NSString gotchas
Indexing
Mutability
Value and reference
String comparison
Formatting strings
Formatting using fonts
Formatting using NSMutableAttributedString
Adding an attribute
Multiple attributes
Links in text
Styles and effects
NSTextView
The MVC pattern of text views
NSTextStorage
NSTextContainer
NSLayoutManager
Custom text view
Creating the custom storage class
Creating the custom text view
Summary
Getting More from Interface Builder
Advanced IB navigation
The little-known HUD
Showing all views under the cursor
Debug View Hierarchy
Controlling the amount of information
Other view settings
Wireframe view
Zooming
Showing constraints
Encapsulating views with NSStackView
Taming the storyboard
Refactoring large storyboards
Under the hood of a storyboard
Summary
Drawing on the Strength of Core Graphics
Why not use an image?
Why not use native views?
Core Graphics and AppKit drawing
Using AppKit
Using Core Graphics
Which to use
Creating custom views
Custom buttons
Defining the custom button's properties
Overriding the button's draw method
Filling a path
Stroking a path
Drawing the icon with code
Adding an alternative icon
Testing the button
Dial clock
Creating a custom view with AppKit
Overriding the custom view's draw method
Drawing arcs
Drawing the outline
Adding the fill color
Adding the minutes curve
Adding the hours curve
Correcting the order of drawing
Pie clock
Creating a custom view with Core Graphics
Understanding CGContext
Why do we need a graphics context?
Understanding the CG coordinates system
Creating the custom class
Overriding the class's draw method
The draw method
The drawFace method
Adding a gradient with AppKit
The drawMinutes method
Adding a gradient with Core Graphics
Adding more color locations
The drawHours method
Context translation
Context rotation
Translating the context
Rotating the text
Adding the hour displacement
Adding shadows
Context scaling
Summary
Core Animation
What is Core Animation?
Where does Core Animation fit in?
Layer backed and layer hosting
Drawing, then animating
Introducing CALayer
Creating a project
Adding a custom view
Extending CGColor
Preparing the ViewController class
Adding a button in code
Building CALayer objects
Adding CA sublayers
Exploring glows and shadows
Adding a CAShapeLayer
CAShapeLayer properties
CGPaths
Adding CA transformations
Rotating a layer in 3D
Using CATextLayer
Animating CALayer objects
CA implicit animations
CA explicit animations
CABasicAnimation
CABasicAnimation and the view model
Delaying an animation
Using CAKeyframeAnimation
Controlling animations with CAAnimationGroup
Wrapping changes in CATransaction objects
Affine transformation
Adding CATransaction completion blocks
Nesting CATransaction blocks
Two-and-a-half dimensional animations
Adding perspective
Getting even closer to 3D
Introducing CATransformLayer
Composing CALayers onto CATransformLayer
Rotating the CATransformLayer
Adding 3D animation
Animating NSViews
Summary
Handling Errors Gracefully
Errors aren't mistakes
Expecting the unexpected
Optionals
Explicit error handling
Swift error handling
The four ways of handling errors
Error types
Creating the simplest Error enum
Creating a better Error enum
Throwing an error
Handling an error
The error life cycle
Asserting that the error will not occur
Handling the error as an optional value
Handling an error with do-catch
Pattern matching
Matching associated values
Propagating an error
Propagation - case study: handling in scope
Propagation - case study: propagation
Verbose errors
Anything can be an error
NSError handling
Anatomy of an NSError
Catching NSErrors
Pattern-matched Cocoa catches
Creating NSError instances in Swift
Summary
Persistent Storage
Creating a project
Creating the project's file manager
Using UserDefaults
Storage of simple objects
Storing simple objects
Using the synchronize method
Loading simple objects
Testing the code
Storing structured data
Saving structured data
Loading structured data
Testing the code
Loading by type
Testing the code
UserDefaults convenience methods
Saving with convenience methods
Loading the data
Testing the code
Security considerations
Saving text to the Documents folder
Create an extension and helper function
Storing textual data
Testing the save function
Loading text files
Testing the load function
NSCoding/NSKeyedArchiver
Creating an NSCoding--compliant class
Handling NSCoding--compliant objects
Saving NSCoding--compliant objects
Loading NSCoding--compliant objects
Testing the code
More complex objects
Presenting open and save dialog boxes
Summary
The Benefits of Core Data
What Core Data is, and isn't
Elements of a Core Data model
Entities
Attributes
Relationships
Core Data, Cocoa Bindings, and no code
Create the project
Create a simple UI in Interface Builder
Adding the necessary UI objects to the Scene
Add an Array Controller
Setting up the data model
Preparing the View Controller
Connecting up to the storyboard
Connecting the buttons
Connecting the Array Controller
Setting up the table columns
Connecting the Table Cell Views
Connecting the text fields
Using our data model
Using NSPersistenceContainer
Adding an NSPersistentContainer instance
Delete the unneeded properties
Replacing references to the context
Creating a data manager class
Non-string entity attributes
Creating entity instances
What is a managed object context?
Fetching data
Adding relationships between entities
One-to-one relationships
One-to-many relationships
Adding relationships to the crew
Same thing, the other way around
Sorted fetches
Sorting in the table view
Predicate fetching
Using other predicates
Searching for a string
Searching for a case - insensitive string
Combining predicates
Relationship predicates
Deleting the red guy
More about Core Data
The Core Data stack
NSManagedObjectModel
NSManagedObjectContext
NSPersistentStoreCoordinator
Does app X really need Core Data?
The pros
The cons
Making that decision
Summary
Connect to the World - Networking
Patterns for downloading data
Simplicity
Control
Downloading using closures
Starting a local test server on your machine
Starting the server
Creating a JSON file
Testing the server
Implementing an HTTP request manager
The web as an asynchronous entity
The simplest request possible
The completion handler
Improving the simplest request possible
Customizing URLSessionConfiguration properties
Customizing URLRequest properties
Customizing URLSessionTask properties
Downloading using a URLSession delegate
Adding HTTP compatibility to the app
Creating a simple UI
Creating the manager
Creating a session delegate class
URLSessionDownloadDelegate methods
Handling the data
Catching errors
Getting progress information
Canceling a download
URLSessionTaskDelegate methods
Adding suspend and resume
No third-party frameworks?
The URLSession framework
URLSessionTasks
Ephemeral sessions
Cache rewards
Using different request cache policies
Summary
Concurrency and Asynchronous Programming
Concurrency and asynchronicity
Concurrency
Concurrency and parallelism
Multithreading
Multiprocessing
Threads, and why you don't need to worry
Asynchronicity
The challenges of asynchronous programming
Dependencies, and why you don't need to worry
Operation framework
Understanding operations and queues
Basic use of an OperationQueue
Adding dependencies to BlockOperations
More BlockOperation features
BlockOperation completion blocks
Defining a custom Operation object
Concurrent and non-concurrent operations
Defining non-concurrent custom operations
Defining concurrent custom operations
Summary
Understanding Xcodes Debugging Tools
Checking out Xcode's debugging tools
Debug area
Variables view
Using Quicklook
Console view
Debugging in the navigator area
Debug navigator
Hiding and showing additional information
Changing the process view
Breakpoint navigator
Report navigator
Leveraging breakpoints
Different types of breakpoint
Swift error breakpoints
Symbolic breakpoints
Other breakpoint types
Adding and removing breakpoints
Editing breakpoints
Conditions
Ignore
Adding an action to a breakpoint
Log message
Debugger Command
Shell Command
AppleScript
We can also get a little more ambitious with these actions
Sounds
Multiple actions
Breakpoint control flow
Debugger control
Close
Enable
Continue
Step over
Step into
Step out
Trying them out
Summary
LLDB and the Command Line
LLDB
Using LLDB
Debugging line-by-line
Continue
Step over
Step into
Step out
Trying it out
Enable
Printing in LLDB
Preparing classes for LLDB descriptions
Stop hooks
Printing formatted numbers
Executing code from LLDB
Type lookups
Breakpoints in LLDB
Adding a breakpoint
Breakpoint list
Attaching commands to breakpoints
Creating a Swift Error breakpoint
Naming breakpoints
Watchpoints
Adding conditions and commands
Watchpoint lists
Enabling, disabling, and deleting watchpoints
Persistent customization
Getting help in LLBD
Using shell commands in LLDB
REPL in LLDB
Switching between LLDB and Swift REPL
Leaving a REPL session
Using Python in LLDB
Accessing program variables from Python
Switching between LLDB and Python REPL
One liners from LLDB to Python
Getting help in Python
Altogether now
Standalone LLDB
Running Xcode projects in a standalone LLDB session
Differences between standalone and Xcode LLDB
Summary
Deploying Third - Party Code
Common use cases
Distribution methods
Third - party source code
Third - party libraries
Third-party frameworks
But the Internet says...
Pros and cons
The case for third - party code
The case against
The take-away
A case study
Leaving it till later
Different installation methods
Manual source code integration
Downloading the ZIP
Cloning the repo
Preparing to clone
Installing Homebrew
Installing Git
Cloning the repository
Importing the source code
Swift Package Manager
SPM products
Adding the package to an Xcode project
Over to Xcode
Package baggage
Other package managers
Cocoapods
Carthage
The price of complexity
Summary
Wrapping It Up
App distribution
The right settings on project creation
The product name
Team
The Organization Identifier
Bundle ID
Setting up the project
Setting the Application Category
Enabling sandboxing
Your developer account
Registering an app ID
Providing the required icons
Archiving the app
Validating the archive
Uploading to the App Store
Creating app records in iTunes Connect
Uploading from Xcode to the App Store
Exporting the app for distribution
Save for Mac App Store Deployment
Testing the Installer package
Export a Developer ID-signed Application
Export a Development-signed Application
Export as a macOS App
Summary
And finally
The book website
买过这本书的人还买过
读了这本书的人还在读
同类图书排行榜