Advanced iOS Application Architecture and Patterns · Advanced iOS Application Architecture and Patterns Session 229 Andy Matuschak iOS Apps and Frameworks Frameworks! Colin Barrett
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
class UsernameValidator: Validator { var input: NSString? func validateWithError(error: NSErrorPointer) -> Bool { let regex = NSRegularExpression(pattern: ...) ... }}
ValidationPasswords
ValidationPasswords
class PasswordValidator: Validator { var input: NSString? ...}
ValidationPasswords
class PasswordValidator: Validator { var input: NSString? ...}
Represents the validity of a single password field
ValidationPasswords
class PasswordValidator: Validator { var input: NSString? ...}
Represents the validity of a single password fieldclass SetPasswordValidator: Validator { let firstPasswordValidator = PasswordValidator() let secondPasswordValidator = PasswordValidator() ...}
ValidationPasswords
class PasswordValidator: Validator { var input: NSString? ...}
Represents the validity of a single password fieldclass SetPasswordValidator: Validator { let firstPasswordValidator = PasswordValidator() let secondPasswordValidator = PasswordValidator() ...}
Represents two password fields that must match in value
ValidationOverall form
ValidationOverall form
class SignUpValidator: Validator { let usernameValidator = UsernameValidator() let setPasswordValidator = SetPasswordValidator() let emailAddressValidator = EmailAddressValidator() ...}
ValidationOverall form
class SignUpValidator: Validator { let usernameValidator = UsernameValidator() let setPasswordValidator = SetPasswordValidator() let emailAddressValidator = EmailAddressValidator() ...}
Represents the validity of the entire form
ValidationOverall form
class SignUpValidator: Validator { let usernameValidator = UsernameValidator() let setPasswordValidator = SetPasswordValidator() let emailAddressValidator = EmailAddressValidator() ...}
Represents the validity of the entire form
Behavior of nil
ValidationOverall form
class SignUpValidator: Validator { let usernameValidator = UsernameValidator() let setPasswordValidator = SetPasswordValidator() let emailAddressValidator = EmailAddressValidator() ...}
Represents the validity of the entire form
Behavior of nil• Most validators allow nil
ValidationOverall form
class SignUpValidator: Validator { let usernameValidator = UsernameValidator() let setPasswordValidator = SetPasswordValidator() let emailAddressValidator = EmailAddressValidator() ...}
Represents the validity of the entire form
Behavior of nil• Most validators allow nil
• SignUpValidator verifies contained inputs are non-nil
Validation
Validation
Set input on corresponding validator
Enable sign-up button
Decorate invalid text fields
For each text field
If sign-up validator OK
Otherwise
Define Clear Responsibilities2
Simplify with immutability3
Design information flow1
Define clear responsibilities2
“Mutability is bad and you should feel bad for using it”
The Internet, probably…
Insight, not dogmaWhy, not how
5
A
B
C
5
A
B
C
5
5
A
B
C
99
99
A
B
C
99
99
A
B
C
99
A
B
C
99 99
99
A
B
C
99 99
99
A
B
C
99 99
99
A
B
C
5
A
B
C
5
A
B
C
5
5
A
B
C
995
5
A
B
C
99
5
5
A
B
C
Swift StructsBest of both worlds
Swift StructsBest of both worlds
Opt-in mutability • mutating keyword
Swift StructsBest of both worlds
Opt-in mutability • mutating keyword
Call-by-value • New copy automatically created when passing struct to another function
55
A
B
C
55
A
B
C
5
5
A
B
C
5
9999
A
B
C
5
9999
A
B
C
5 99
99
A
B
C
UIMotionEffect
UIMotionEffect
Adjust views based on gyroscope data
UIMotionEffect
Adjust views based on gyroscope data
Used to achieve parallax effects
UIMotionEffect
Adjust views based on gyroscope data
Used to achieve parallax effects
Reusable across views
UIMotionEffect
Adjust views based on gyroscope data
Used to achieve parallax effects
Reusable across views
Low-latency requirements
UIMotionEffect
UIMotionEffect
Inputs Outputs
UIMotionEffect
Inputs Outputs
Device pose
UIMotionEffect
Inputs Outputs
Device pose Relative offset for each key path
Inputs Outputs
UIMotionEffectInput deltas
Inputs Outputs
UIMotionEffectInput deltas
Device pose deltas
Inputs Outputs
UIMotionEffectInput deltas
Device pose deltas Relative offset for each key path
Inputs Outputs
UIMotionEffectInput deltas
Previous poses
Device pose deltas Relative offset for each key path