├── .github └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── LICENSE ├── README.md ├── TIMELINE.md ├── codes ├── AdapterPattern.swift ├── AddSubviewExtension.swift ├── AddingPrefixToString.swift ├── AllSatisfyFunction.swift ├── ArrayPrependExtensionFunction.swift ├── AutoLayoutExtension.swift ├── BackgroundQoS.swift ├── BitwiseShiftOperators.swift ├── BuilderPattern.swift ├── BundleExtension.swift ├── CStyleForLoopUsingStride.swift ├── CaseIterable.swift ├── CharacterPropertiesSwift5.swift ├── ClassNameExtension.swift ├── ClosedRangeOperator.swift ├── CodeSeparation.swift ├── CompactMapFunction.swift ├── CompactMapValuesSwift5.swift ├── ComputedProperties.swift ├── ConformNeverToEquatableAndHashableSwift5.swift ├── CountWhereSwift5.swift ├── CustomOperator.swift ├── DecodingJSONFromBundle.swift ├── DefaultParameter.swift ├── DefaultQoS.swift ├── DiscardableResult.swift ├── DismissKeyboardInteractively.swift ├── DispatchGroup.swift ├── DistanceOfTwoCGPoint.swift ├── DistinctBy.swift ├── DynamicMemberLookup.swift ├── ElementOfOperator.swift ├── ExtensionForNestedTypes.swift ├── FacadePattern.swift ├── FactoryPattern.swift ├── Fallthrough.swift ├── FilterFunction.swift ├── FirstWhere.swift ├── FlattenNestedOptionalsSwift5.swift ├── FunctionArgumentLabels.swift ├── GenericFunctions.swift ├── GetAnElementInSafety.swift ├── GuardOptionalBinding.swift ├── HalfOpenRangeOperator.swift ├── HandlingFutureEnumCasesSwift5.swift ├── ImportanceOfWeakReference.swift ├── InoutParameter.swift ├── IntAndStringDescriptionOfBool.swift ├── IntToUIntDoubleFloat.swift ├── IsMultipleSwift5.swift ├── Join&SplitFunction.swift ├── LabeledStatements.swift ├── LazyProperty.swift ├── LessThanOperatorSwift5.swift ├── MapFunction.swift ├── MemberShortHand.swift ├── MultilineStringLiterals.swift ├── MutatingFunction.swift ├── NilCoalescingOperator.swift ├── ObserverPattern.swift ├── OmittingArgumentLabels.swift ├── OneSidedRange.swift ├── OneTimeCode.swift ├── OperatorOverloading.swift ├── PassingOperator.swift ├── PreservingInitializers.swift ├── PropertyObservers.swift ├── ProtocolConformance.swift ├── PublicPrivateSet.swift ├── QualityOfServiceClasses.swift ├── RegisterDequeueXIBCollectionView.swift ├── RegisterDequeueXIBTableView.swift ├── RemoveElementInArray.swift ├── RemoveTheSameValueFromTheArray.swift ├── RepeatWhile.swift ├── RequiredHeightForLabel.swift ├── ReturnMultipleValues.swift ├── SearchBarTextField.swift ├── ShowAlertFunction.swift ├── ShuffledAndShuffleFunctions.swift ├── SimpleDefer.swift ├── SingletonPattern.swift ├── SketchShadow.swift ├── SnapKitUsage.swift ├── StaticFactoryMethodsForUILabel.swift ├── StaticTypeProperties.swift ├── StrategyPattern.swift ├── SumFunction.swift ├── SwapValues.swift ├── SwitchRootVCExtension.swift ├── TernaryOperator.swift ├── TypeMethods.swift ├── UIColorConvenienceInit.swift ├── UnaryMinusOperator.swift ├── UrlQueryParameters.swift ├── UserInitiatedQoS.swift ├── UserInteractiveQoS.swift ├── UtilityQoS.swift ├── VariadicParameters.swift └── WordCountFunction.swift ├── icons ├── CarbonSettings.png ├── instagram.png ├── sdt-logo.png ├── telegram.png └── twitter.png ├── screenshots ├── AdapterPattern.png ├── AddSubviewExtension.png ├── AddingPrefixToString.png ├── AllSatisfyFunction.png ├── ArrayPrependExtensionFunction.png ├── AutoLayoutExtension.png ├── BackgroundQoS.png ├── BitwiseShiftOperators.png ├── BuilderPattern.png ├── BundleExtension.png ├── CStyleForLoopUsingStride.png ├── CaseIterable.png ├── CharacterPropertiesSwift5.png ├── ClassNameExtension.png ├── ClosedRangeOperator.png ├── CodeSeparation.png ├── CompactMapFunction.png ├── CompactMapValuesSwift5.png ├── ComputedProperties.png ├── ConformNeverToEquatableAndHashableSwift5.png ├── CountWhereSwift5.png ├── CustomOperator.png ├── DecodingJSONFromBundle.png ├── DefaultParameter.png ├── DefaultQoS.png ├── DiscardableResult.png ├── DismissKeyboardInteractively.png ├── DispatchGroup.png ├── DistanceOfTwoCGPoint.png ├── DistinctBy.png ├── DynamicMemberLookup.png ├── ElementOfOperator.png ├── ExtensionForNestedTypes.png ├── FacadePattern.png ├── FactoryPattern.png ├── Fallthrough.png ├── FilterFunction.png ├── FirstWhere.png ├── FlattenNestedOptionalsSwift5.png ├── FunctionArgumentLabels.png ├── GenericFunctions.png ├── GetAnElementInSafety.png ├── GuardOptionalBinding.png ├── HalfOpenRangeOperator.png ├── HandlingFutureEnumCasesSwift5.png ├── ImportanceOfWeakReference.png ├── InoutParameter.png ├── IntAndStringDescriptionOfBool.png ├── IntToUIntDoubleFloat.png ├── IsMultipleSwift5.png ├── Join&SplitFunction.png ├── LabeledStatements.png ├── LazyProperty.png ├── LessThanOperatorSwift5.png ├── MapFunction.png ├── MemberShortHand.png ├── MultilineStringLiterals.png ├── MutatingFunction.png ├── NilCoalescingOperator.png ├── ObserverPattern.png ├── OmittingArgumentLabels.png ├── OneSidedRange.png ├── OneTimeCode.png ├── OperatorOverloading.png ├── PassingOperator.png ├── PreservingInitializers.png ├── PropertyObservers.png ├── ProtocolConformance.png ├── PublicPrivateSet.png ├── QualityOfServiceClasses.png ├── RegisterDequeueXIBCollectionView.png ├── RegisterDequeueXIBTableView.png ├── RemoveElementInArray.png ├── RemoveTheSameValueFromTheArray.png ├── RepeatWhile.png ├── RequiredHeightForLabel.png ├── ReturnMultipleValues.png ├── SearchBarTextField.png ├── ShowAlertFunction.png ├── ShuffledAndShuffleFunctions.png ├── SimpleDefer.png ├── SingletonPattern.png ├── SketchShadow.png ├── SnapKitUsage.png ├── StaticFactoryMethodsForUILabel.png ├── StaticTypeProperties.png ├── StrategyPattern.png ├── SumFunction.png ├── SwapValues.png ├── SwitchRootVCExtension.png ├── TernaryOperator.png ├── TypeMethods.png ├── UIColorConvenienceInit.png ├── UnaryMinusOperator.png ├── UrlQueryParameters.png ├── UserInitiatedQoS.png ├── UserInteractiveQoS.png ├── UtilityQoS.png ├── VariadicParameters.png └── WordCountFunction.png └── tips.json /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## PR Checklist 2 | 3 | Please check if your PR fulfills the following requirements: 4 | 5 | - [Carbon](https://carbon.now.sh) Requirements 6 | | [Detail Carbon Settings](https://github.com/MobileTipsters/Swift-Daily-Tips/blob/master/icons/CarbonSettings.png) 7 | - [ ] Select `Dracula` Theme 8 | - [ ] Select right `programming language` 9 | - [ ] Set `largest` font size 10 | 11 | 12 | - Commit requirements 13 | - [ ] Image should be added to `screenshots` folder 14 | - [ ] Code snippet should be added to `codes` folder 15 | - [ ] Image and code snippet have the `same name` for their files 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | \.DS_Store 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Swift Daily Tips 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![Swift Daily Tips](/icons/sdt-logo.png) 2 | 3 | [![Patreon](https://img.shields.io/badge/patreon-donate-green.svg)](https://patreon.com/SwiftDailyTips) [![Buy me a Coffee](https://img.shields.io/badge/buy%20me%20a%20coffee-donate-green.svg)](https://buymeacoffee.com/SwiftDailyTips) [![GitHub stars](https://img.shields.io/github/stars/MobileTipsters/Swift-Daily-Tips.svg)](https://github.com/MobileTipsters/Swift-Daily-Tips/stargazers) [![GitHub forks](https://img.shields.io/github/forks/MobileTipsters/Swift-Daily-Tips.svg)](https://github.com/MobileTipsters/Swift-Daily-Tips/stargazers) [![GitHub issues](https://img.shields.io/github/issues/MobileTipsters/Swift-Daily-Tips.svg)](https://github.com/MobileTipsters/Swift-Daily-Tips/issues) [![GitHub license](https://img.shields.io/github/license/MobileTipsters/Swift-Daily-Tips.svg)](https://github.com/MobileTipsters/Swift-Daily-Tips) 4 | 5 | [![alt text][TwitterIcon]][Twitter] 6 | [![alt text][InstagramIcon]][Instagram] 7 | [![alt text][TelegramIcon]][Telegram] 8 | 9 | [TwitterIcon]: /icons/twitter.png (twitter) 10 | [InstagramIcon]: /icons/instagram.png (instagram) 11 | [TelegramIcon]: /icons/telegram.png (telegram) 12 | 13 | [Twitter]: https://www.twitter.com/SwiftDailyTips 14 | [Instagram]: https://www.instagram.com/SwiftDailyTips 15 | [Telegram]: https://t.me/SwiftDailyTips 16 | 17 | ## [Timeline](/TIMELINE.md) of Tips 18 | 19 | #### [#56 Factory Pattern](/codes/FactoryPattern.swift) 20 | 21 | #### [#55 Adapter Pattern](/codes/AdapterPattern.swift) 22 | 23 | #### [#54 Singleton Pattern](/codes/SingletonPattern.swift) 24 | 25 | #### [#53 Dispatch Group](/codes/DispatchGroup.swift) 26 | 27 | #### [#52 Background QoS](/codes/BackgroundQoS.swift) 28 | 29 | #### [#51 Utility QoS](/codes/UtilityQoS.swift) 30 | 31 | #### [#50 Default QoS](/codes/DefaultQoS.swift) 32 | 33 | #### [#49 User Initiated QoS](/codes/UserInitiatedQoS.swift) 34 | 35 | #### [#48 User Interactive QoS](/codes/UserInteractiveQoS.swift) 36 | 37 | #### [#47 Quality of Service Classes](/codes/QualityOfServiceClasses.swift) 38 | 39 | #### [#46 MutatingFunction](/codes/MutatingFunction.swift) 40 | 41 | #### [#45 Dynamic Member Lookup](/codes/DynamicMemberLookup.swift) 42 | 43 | #### [#44 Bitwise Shift Operators](/codes/BitwiseShiftOperators.swift) 44 | 45 | #### [#43 Unary Minus Operator](/codes/UnaryMinusOperator.swift) 46 | 47 | #### [#42 One-Sided Range](/codes/OneSidedRange.swift) 48 | 49 | #### [#41 Half-Open Range Operator](/codes/HalfOpenRangeOperator.swift) 50 | 51 | #### [#40 Closed Range Operator](/codes/ClosedRangeOperator.swift) 52 | 53 | #### [#39 Variadic Parameters](/codes/VariadicParameters.swift) 54 | 55 | #### [#38 Omitting Argument Labels](/codes/OmittingArgumentLabels.swift) 56 | 57 | #### [#37 Function Argument Labels](/codes/FunctionArgumentLabels.swift) 58 | 59 | #### [#36 Repeat While](/codes/RepeatWhile.swift) 60 | 61 | #### [#35 Multiline String Literals](/codes/MultilineStringLiterals.swift) 62 | 63 | #### [#34 Builder Pattern](/codes/BuilderPattern.swift) 64 | 65 | #### [#33 Swap Values](/codes/SwapValues.swift) 66 | 67 | #### [#32 Generic Functions](/codes/GenericFunctions.swift) 68 | 69 | #### [#31 Fallthrough](/codes/Fallthrough.swift) 70 | 71 | #### [#30 Join & Split Function](/codes/Join&SplitFunction.swift) 72 | 73 | #### [#29 Nil-Coalescing Operator](/codes/NilCoalescingOperator.swift) 74 | 75 | #### [#28 Ternary Operator](/codes/TernaryOperator.swift) 76 | 77 | #### [#27 Public Private(set)](/codes/PublicPrivateSet.swift) 78 | 79 | #### [#26 Property Observers](/codes/PropertyObservers.swift) 80 | 81 | #### [#25 Return Multiple Values](/codes/ReturnMultipleValues.swift) 82 | 83 | #### [#24 Discardable Result](/codes/DiscardableResult.swift) 84 | 85 | #### [#23 Lazy Property](/codes/LazyProperty.swift) 86 | 87 | #### [#22 Default Parameter](/codes/DefaultParameter.swift) 88 | 89 | #### [#21 Type Methods](/codes/TypeMethods.swift) 90 | 91 | #### [#20 Static Type Properties](/codes/StaticTypeProperties.swift) 92 | 93 | #### [#19 Computed Properties](/codes/ComputedProperties.swift) 94 | 95 | #### [#18 Shuffled and Shuffle functions](/codes/ShuffledAndShuffleFunctions.swift) 96 | 97 | #### [#17 CaseIterable Protocol](/codes/CaseIterable.swift) 98 | 99 | #### [#16 Element of Operator ∈](/codes/ElementOfOperator.swift) 100 | 101 | #### [#15 Passing Operator](/codes/PassingOperator.swift) 102 | 103 | #### [#14 CompactMap Function](/codes/CompactMapFunction.swift) 104 | 105 | #### [#13 Map Function](/codes/MapFunction.swift) 106 | 107 | #### [#12 In-out Parameter](/codes/InoutParameter.swift) 108 | 109 | #### [#11 Simple Defer Function](/codes/SimpleDefer.swift) 110 | 111 | #### [#10 AllSatisfy Function](/codes/AllSatisfyFunction.swift) 112 | 113 | #### [#9 First Where Function](/codes/FirstWhere.swift) 114 | 115 | #### [#8 Guard Optional Binding](/codes/GuardOptionalBinding.swift) 116 | 117 | #### [#7 Filter Function](/codes/FilterFunction.swift) 118 | 119 | #### [#6 One Time Code #iOS12](/codes/OneTimeCode.swift) 120 | 121 | #### [#5 Dismiss Keyboard Interactively](/codes/DismissKeyboardInteractively.swift) 122 | 123 | #### [#4 Member Short Hand](/codes/MemberShortHand.swift) 124 | 125 | #### [#3 UIColor Convenience Init](/codes/UIColorConvenienceInit.swift) 126 | 127 | #### [#2 Static Factory Methods for UILabel](/codes/StaticFactoryMethodsForUILabel.swift) 128 | 129 | #### [#1 Add Subview Extension](/codes/AddSubviewExtension.swift) 130 | -------------------------------------------------------------------------------- /TIMELINE.md: -------------------------------------------------------------------------------- 1 | ## [README](/README.md) 2 | 3 | ### [#42 One-Sided Range](/codes/OneSidedRange.swift) 4 | ![alt text][OneSidedRange] 5 | 6 | ### [#41 Half-Open Range Operator](/codes/HalfOpenRangeOperator.swift) 7 | ![alt text][HalfOpenRangeOperator] 8 | 9 | ### [#40 Closed Range Operator](/codes/ClosedRangeOperator.swift) 10 | ![alt text][ClosedRangeOperator] 11 | 12 | ### [#39 Variadic Parameters](/codes/VariadicParameters.swift) 13 | ![alt text][VariadicParameters] 14 | 15 | ### [#38 Omitting Argument Labels](/codes/OmittingArgumentLabels.swift) 16 | ![alt text][OmittingArgumentLabels] 17 | 18 | ### [#37 Function Argument Labels](/codes/FunctionArgumentLabels.swift) 19 | ![alt text][FunctionArgumentLabels] 20 | 21 | ### [#36 Repeat While](/codes/RepeatWhile.swift) 22 | ![alt text][RepeatWhile] 23 | 24 | ### [#35 Multiline String Literals](/codes/MultilineStringLiterals.swift) 25 | ![alt text][MultilineStringLiterals] 26 | 27 | ### [#34 Builder Pattern](/codes/BuilderPattern.swift) 28 | ![alt text][BuilderPattern] 29 | 30 | ### [#33 Swap Values](/codes/SwapValues.swift) 31 | ![alt text][SwapValues] 32 | 33 | ### [#32 Generic Functions](/codes/GenericFunctions.swift) 34 | ![alt text][GenericFunctions] 35 | 36 | ### [#31 Fallthrough](/codes/Fallthrough.swift) 37 | ![alt text][Fallthrough] 38 | 39 | ### [#30 Join & Split Function](/codes/Join&SplitFunction.swift) 40 | ![alt text][Join&SplitFunction] 41 | 42 | ### [#29 Nil-Coalescing Operator](/codes/NilCoalescingOperator.swift) 43 | ![alt text][NilCoalescingOperator] 44 | 45 | ### [#28 Ternary Operator](/codes/TernaryOperator.swift) 46 | ![alt text][TernaryOperator] 47 | 48 | ### [#27 Public Private(set)](/codes/PublicPrivateSet.swift) 49 | ![alt text][PublicPrivateSet] 50 | 51 | ### [#26 Property Observers](/codes/PropertyObservers.swift) 52 | ![alt text][PropertyObservers] 53 | 54 | ### [#25 Return Multiple Values](/codes/ReturnMultipleValues.swift) 55 | ![alt text][ReturnMultipleValues] 56 | 57 | ### [#24 Discardable Result](/codes/DiscardableResult.swift) 58 | ![alt text][DiscardableResult] 59 | 60 | ### [#23 Lazy Property](/codes/LazyProperty.swift) 61 | ![alt text][LazyProperty] 62 | 63 | ### [#22 Default Parameter](/codes/DefaultParameter.swift) 64 | ![alt text][DefaultParameter] 65 | 66 | ### [#21 Type Methods](/codes/TypeMethods.swift) 67 | ![alt text][TypeMethods] 68 | 69 | ### [#20 Static Type Properties](/codes/StaticTypeProperties.swift) 70 | ![alt text][StaticTypeProperties] 71 | 72 | ### [#19 Computed Properties](/codes/ComputedProperties.swift) 73 | ![alt text][ComputedProperties] 74 | 75 | ### [#18 Shuffled and Shuffle functions](/codes/ShuffledAndShuffleFunctions.swift) 76 | ![alt text][ShuffledAndShuffleFunctions] 77 | 78 | ### [#17 CaseIterable Protocol](/codes/CaseIterable.swift) 79 | ![alt text][CaseIterable] 80 | 81 | ### [#16 Element of Operator ∈](/codes/ElementOfOperator.swift) 82 | ![alt text][ElementOfOperator] 83 | 84 | ### [#15 Passing Operator](/codes/PassingOperator.swift) 85 | ![alt text][PassingOperator] 86 | 87 | ### [#14 CompactMap Function](/codes/CompactMapFunction.swift) 88 | ![alt text][CompactMapFunction] 89 | 90 | ### [#13 Map Function](/codes/MapFunction.swift) 91 | ![alt text][MapFunction] 92 | 93 | ### [#12 In-out Parameter](/codes/InoutParameter.swift) 94 | ![alt text][InoutParameter] 95 | 96 | ### [#11 Simple Defer Function](/codes/SimpleDefer.swift) 97 | ![alt text][SimpleDefer] 98 | 99 | ### [#10 AllSatisfy Function](/codes/AllSatisfyFunction.swift) 100 | ![alt text][AllSatisfyFunction] 101 | 102 | ### [#9 First Where Function](/codes/FirstWhere.swift) 103 | ![alt text][FirstWhere] 104 | 105 | ### [#8 Guard Optional Binding](/codes/GuardOptionalBinding.swift) 106 | ![alt text][GuardOptionalBinding] 107 | 108 | ### [#7 Filter Function](/codes/FilterFunction.swift) 109 | ![alt text][FilterFunction] 110 | 111 | ### [#6 One Time Code #iOS12](/codes/OneTimeCode.swift) 112 | ![alt text][OneTimeCode] 113 | 114 | ### [#5 Dismiss Keyboard Interactively](/codes/DismissKeyboardInteractively.swift) 115 | ![alt text][DismissKeyboardInteractively] 116 | 117 | ### [#4 Member Short Hand](/codes/MemberShortHand.swift) 118 | ![alt text][MemberShortHand] 119 | 120 | ### [#3 UIColor Convenience Init](/codes/UIColorConvenienceInit.swift) 121 | ![alt text][UIColorConvenienceInit] 122 | 123 | ### [#2 Static Factory Methods for UILabel](/codes/StaticFactoryMethodsForUILabel.swift) 124 | ![alt text][StaticFactoryMethodsForUILabel] 125 | 126 | ### [#1 Add Subview Extension](/codes/AddSubviewExtension.swift) 127 | ![alt text][AddSubviewExtension] 128 | 129 | [AddSubviewExtension]: /screenshots/AddSubviewExtension.png 130 | [StaticFactoryMethodsForUILabel]: /screenshots/StaticFactoryMethodsForUILabel.png 131 | [UIColorConvenienceInit]: /screenshots/UIColorConvenienceInit.png 132 | [MemberShortHand]: /screenshots/MemberShortHand.png 133 | [DismissKeyboardInteractively]: /screenshots/DismissKeyboardInteractively.png 134 | [OneTimeCode]: /screenshots/OneTimeCode.png 135 | [FilterFunction]: /screenshots/FilterFunction.png 136 | [GuardOptionalBinding]: /screenshots/GuardOptionalBinding.png 137 | [FirstWhere]: /screenshots/FirstWhere.png 138 | [AllSatisfyFunction]: /screenshots/AllSatisfyFunction.png 139 | [SimpleDefer]: /screenshots/SimpleDefer.png 140 | [InoutParameter]: /screenshots/InoutParameter.png 141 | [MapFunction]: /screenshots/MapFunction.png 142 | [CompactMapFunction]: /screenshots/CompactMapFunction.png 143 | [PassingOperator]: /screenshots/PassingOperator.png 144 | [ElementOfOperator]: /screenshots/ElementOfOperator.png 145 | [CaseIterable]: /screenshots/CaseIterable.png 146 | [ShuffledAndShuffleFunctions]: /screenshots/ShuffledAndShuffleFunctions.png 147 | [ComputedProperties]: /screenshots/ComputedProperties.png 148 | [StaticTypeProperties]: /screenshots/StaticTypeProperties.png 149 | [TypeMethods]: /screenshots/TypeMethods.png 150 | [DefaultParameter]: /screenshots/DefaultParameter.png 151 | [LazyProperty]: /screenshots/LazyProperty.png 152 | [DiscardableResult]: /screenshots/DiscardableResult.png 153 | [ReturnMultipleValues]: /screenshots/ReturnMultipleValues.png 154 | [PropertyObservers]: /screenshots/PropertyObservers.png 155 | [PublicPrivateSet]: /screenshots/PublicPrivateSet.png 156 | [TernaryOperator]: /screenshots/TernaryOperator.png 157 | [NilCoalescingOperator]: /screenshots/NilCoalescingOperator.png 158 | [Join&SplitFunction]: /screenshots/Join&SplitFunction.png 159 | [Fallthrough]: /screenshots/Fallthrough.png 160 | [GenericFunctions]: /screenshots/GenericFunctions.png 161 | [SwapValues]: /screenshots/SwapValues.png 162 | [BuilderPattern]: /screenshots/BuilderPattern.png 163 | [MultilineStringLiterals]: /screenshots/MultilineStringLiterals.png 164 | [RepeatWhile]: /screenshots/RepeatWhile.png 165 | [FunctionArgumentLabels]: /screenshots/FunctionArgumentLabels.png 166 | [OmittingArgumentLabels]: /screenshots/OmittingArgumentLabels.png 167 | [VariadicParameters]: /screenshots/VariadicParameters.png 168 | [ClosedRangeOperator]: /screenshots/ClosedRangeOperator.png 169 | [HalfOpenRangeOperator]: /screenshots/HalfOpenRangeOperator.png 170 | [OneSidedRange]: /screenshots/OneSidedRange.png 171 | -------------------------------------------------------------------------------- /codes/AdapterPattern.swift: -------------------------------------------------------------------------------- 1 | // Adapter Pattern 2 | 3 | // Adapter is a structural design pattern that allows objects with incompatible 4 | // interfaces to work together. In other words, it transforms the interface of 5 | // an object to adapt it to a different object. 6 | 7 | protocol Jumping { 8 | func jump() 9 | } 10 | 11 | class Cat: Jumping { 12 | func jump() { print("Pounces") } 13 | } 14 | 15 | // MARK: - ADAPTEE 16 | class Frog { 17 | func leap() { print("Leaps") } 18 | } 19 | 20 | // MARK: - ADAPTER 21 | class FrogAdapter: Jumping { 22 | private let frog = Frog() 23 | func jump() { frog.leap() } 24 | } 25 | 26 | let cat = Cat() 27 | let frog = FrogAdapter() 28 | var animals: [Jumping] = [cat, frog] 29 | 30 | func jumpAll(animals: [Jumping]) { 31 | for animal in animals { 32 | animal.jump() 33 | } 34 | } -------------------------------------------------------------------------------- /codes/AddSubviewExtension.swift: -------------------------------------------------------------------------------- 1 | extension UIView { 2 | func addSubviews(_ subviews: UIView...) { 3 | subviews.forEach(addSubview) 4 | } 5 | } 6 | 7 | // Add multiple subviews in a single line 8 | view.addSubviews(imageView, slider, view, label) 9 | -------------------------------------------------------------------------------- /codes/AddingPrefixToString.swift: -------------------------------------------------------------------------------- 1 | // Adding a prefix to a string 2 | 3 | extension String { 4 | func withPrefix(_ prefix: String) -> String { 5 | if self.hasPrefix(prefix) { return self } 6 | return "\(prefix)\(self)" 7 | } 8 | } 9 | 10 | let url = "www.hackingwithswift.com" 11 | let fullURL = url.withPrefix("https://") -------------------------------------------------------------------------------- /codes/AllSatisfyFunction.swift: -------------------------------------------------------------------------------- 1 | // The following code uses this method to test whether all 2 | // the names in an array have at least five characters: 3 | 4 | let names = ["Sofia", "Camilla", "Martina", "Mateo", "Nicolás"] 5 | let allHaveAtLeastFive = names.allSatisfy({ $0.count >= 5 }) 6 | // allHaveAtLeastFive == true -------------------------------------------------------------------------------- /codes/ArrayPrependExtensionFunction.swift: -------------------------------------------------------------------------------- 1 | // Array Prepend Extension Function 2 | 3 | extension Array { 4 | mutating func prepend(_ newElement: Element) { 5 | insert(newElement, at: 0) 6 | } 7 | } 8 | 9 | [2, 3, 4, 5].prepend(1) // [1, 2, 3, 4, 5] 10 | ["e", "l", "l", "o"].prepend("h") // ["h", "e", "l", "l", "o"] -------------------------------------------------------------------------------- /codes/AutoLayoutExtension.swift: -------------------------------------------------------------------------------- 1 | // Auto Layout Extension 2 | 3 | extension UIView { 4 | func fillSuperview() { 5 | anchor(top: superview?.topAnchor, leading: superview?.leadingAnchor, bottom: superview?.bottomAnchor, trailing: superview?.trailingAnchor) 6 | } 7 | 8 | func anchor(top: NSLayoutYAxisAnchor?, leading: NSLayoutXAxisAnchor?, bottom: NSLayoutYAxisAnchor?, trailing: NSLayoutXAxisAnchor?, padding: UIEdgeInsets = .zero, size: CGSize = .zero) { 9 | translatesAutoresizingMaskIntoConstraints = false 10 | 11 | if let top = top { 12 | topAnchor.constraint(equalTo: top, constant: padding.top).isActive = true 13 | } 14 | 15 | if let leading = leading { 16 | leadingAnchor.constraint(equalTo: leading, constant: padding.left).isActive = true 17 | } 18 | 19 | if let bottom = bottom { 20 | bottomAnchor.constraint(equalTo: bottom, constant: -padding.bottom).isActive = true 21 | } 22 | 23 | if let trailing = trailing { 24 | trailingAnchor.constraint(equalTo: trailing, constant: -padding.right).isActive = true 25 | } 26 | 27 | if size.width != 0 { 28 | widthAnchor.constraint(equalToConstant: size.width).isActive = true 29 | } 30 | 31 | if size.height != 0 { 32 | heightAnchor.constraint(equalToConstant: size.height).isActive = true 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /codes/BackgroundQoS.swift: -------------------------------------------------------------------------------- 1 | // Background QoS 2 | 3 | // Work that operates in the background and 4 | // isn’t visible to the user, such as 5 | // indexing, synchronizing, and backups. 6 | // Focuses on energy efficiency. 7 | 8 | DispatchQueue.global(qos: .background).async { 9 | EventHelper.fireEvents(title: eventTitle) 10 | } -------------------------------------------------------------------------------- /codes/BitwiseShiftOperators.swift: -------------------------------------------------------------------------------- 1 | // Bitwise Left and Right Shift Operators 2 | // The bitwise left shift operator (<<) and bitwise right shift operator (>>) 3 | // move all bits in a number to the left or the right by a certain number of 4 | // places, according to the rules defined below. 5 | 6 | // Bitwise left and right shifts have the effect of multiplying or dividing 7 | // an integer by a factor of two. Shifting an integer’s bits to the left by 8 | // one position doubles its value, whereas shifting it to the right by one 9 | // position halves its value. 10 | 11 | let number = 1024 12 | let divisionByTwo = number >> 1 13 | // 512 14 | let multiplyByTwo = number << 1 15 | // 2048 16 | 17 | let pink: UInt32 = 0xCC6699 18 | let redComponent = (pink & 0xFF0000) >> 16 19 | // redComponent is 0xCC, or 204 20 | let greenComponent = (pink & 0x00FF00) >> 8 21 | // greenComponent is 0x66, or 102 22 | let blueComponent = pink & 0x0000FF 23 | // blueComponent is 0x99, or 153 -------------------------------------------------------------------------------- /codes/BuilderPattern.swift: -------------------------------------------------------------------------------- 1 | // Builder allows you to create an instance and setting it up in a simple way: 2 | 3 | protocol Builder {} 4 | 5 | extension Builder { 6 | public func with(configure: (inout Self) -> Void) -> Self { 7 | var this = self 8 | configure(&this) 9 | return this 10 | } 11 | } 12 | 13 | // We need NSObject to conform to Builder to enable it for all subclasses of it 😊 14 | extension NSObject: Builder {} 15 | 16 | private let tableView = UITableView(frame: .zero, style: .plain).with { tableView in 17 | tableView.backgroundColor = .white 18 | tableView.separatorColor = .darkGray 19 | tableView.separatorInset = UIEdgeInsets(top: 0, left: 0, bottom: 10.0, right: 0) 20 | tableView.allowsMultipleSelection = true 21 | } 22 | -------------------------------------------------------------------------------- /codes/BundleExtension.swift: -------------------------------------------------------------------------------- 1 | extension Bundle { 2 | var appName: String { 3 | return infoDictionary?["CFBundleName"] as! String 4 | } 5 | 6 | var bundleId: String { 7 | return bundleIdentifier! 8 | } 9 | 10 | var versionNumber: String { 11 | return infoDictionary?["CFBundleShortVersionString"] as! String 12 | } 13 | 14 | var buildNumber: String { 15 | return infoDictionary?["CFBundleVersion"] as! String 16 | } 17 | } -------------------------------------------------------------------------------- /codes/CStyleForLoopUsingStride.swift: -------------------------------------------------------------------------------- 1 | // C style For Loop Using Stride 2 | 3 | /// Returns a sequence from a starting value to, but not including, an end 4 | /// value, stepping by the specified amount. 5 | /// 6 | /// You can use this function to stride over values of any type that conforms 7 | /// to the `Strideable` protocol, such as integers or floating-point types. 8 | /// Starting with `start`, each successive value of the sequence adds `stride` 9 | /// until the next value would be equal to or beyond `end`. 10 | 11 | for radians in stride(from: 0.0, to: .pi * 2, by: .pi / 2) { 12 | let degrees = Int(radians * 180 / .pi) 13 | print("Degrees: \(degrees), radians: \(radians)") 14 | } 15 | // Degrees: 0, radians: 0.0 16 | // Degrees: 90, radians: 1.5707963267949 17 | // Degrees: 180, radians: 3.14159265358979 18 | // Degrees: 270, radians: 4.71238898038469 19 | -------------------------------------------------------------------------------- /codes/CaseIterable.swift: -------------------------------------------------------------------------------- 1 | // Types that conform to the `CaseIterable` protocol are typically 2 | // enumerations without associated values. When using a `CaseIterable` 3 | // type, you can access a collection of all of the type's cases 4 | // by using the type's`allCases` property. 5 | 6 | enum CompassDirection: CaseIterable { 7 | case north, south, east, west 8 | } 9 | 10 | print("There are \(CompassDirection.allCases.count) directions.") 11 | 12 | for direction in CompassDirection.allCases { 13 | print("I want to go \(direction).") 14 | } 15 | -------------------------------------------------------------------------------- /codes/CharacterPropertiesSwift5.swift: -------------------------------------------------------------------------------- 1 | // Character Properties Swift 5.0 2 | 3 | // Proposal: SE-0221 4 | // String is a collection whose element is Character, which represents an 5 | // extended grapheme cluster (commonly just called “grapheme”). This makes 6 | // Character one of the first types encountered both by newcomers to Swift 7 | // as well as by experienced Swift developers playing around in new 8 | // domains (e.g. scripting). Yet Character exposes little functionality 9 | // other than the ability to order it with respect to other characters, 10 | // and a way to access the raw Unicode scalar values that comprise it. 11 | 12 | extension Character { 13 | @inlinable public var isASCII: Bool { ... } 14 | @inlinable public var asciiValue: UInt8? { ... } 15 | public var isWhitespace: Bool { ... } 16 | public var isNewline: Bool { ... } 17 | public var isNumber: Bool { ... } 18 | @inlinable public var isWholeNumber: Bool { ... } 19 | public var wholeNumberValue: Int? { ... } 20 | @inlinable public var isHexadecimalDigit: Bool { ... } 21 | public var hexadecimalDigitValue: Int? { ... } 22 | public var isLetter: Bool { ... } 23 | public func uppercased() -> String { ... } 24 | public func lowercased() -> String { ... } 25 | @inlinable public var isUppercase: Bool { ... } 26 | @inlinable public var isLowercase: Bool { ... } 27 | @inlinable public var isCased: Bool { ... } 28 | public var isSymbol: Bool { ... } 29 | public var isMathSymbol: Bool { ... } 30 | public var isCurrencySymbol: Bool { ... } 31 | public var isPunctuation: Bool { ... } 32 | } -------------------------------------------------------------------------------- /codes/ClassNameExtension.swift: -------------------------------------------------------------------------------- 1 | // Class Name Extension 2 | 3 | protocol ClassNameProtocol { 4 | static var className: String { get } 5 | var className: String { get } 6 | } 7 | 8 | extension ClassNameProtocol { 9 | static var className: String { 10 | return String(describing: self) 11 | } 12 | 13 | var className: String { 14 | return type(of: self).className 15 | } 16 | } 17 | 18 | extension NSObject: ClassNameProtocol {} 19 | 20 | UIView.className // "UIView" 21 | UILabel().className // "UILabel" -------------------------------------------------------------------------------- /codes/ClosedRangeOperator.swift: -------------------------------------------------------------------------------- 1 | // Closed Range Operator 2 | // The closed range operator (a...b) defines a range 3 | // that runs from a to b, and includes the values 4 | // a and b. The value of a must not be greater than b. 5 | 6 | // The closed range operator is useful when iterating 7 | // over a range in which you want all of the values 8 | // to be used, such as with a for-in loop: 9 | 10 | for index in 1...5 { 11 | print("\(index) times 5 is \(index * 5)") 12 | } 13 | // 1 times 5 is 5 14 | // 2 times 5 is 10 15 | // 3 times 5 is 15 16 | // 4 times 5 is 20 17 | // 5 times 5 is 25 -------------------------------------------------------------------------------- /codes/CodeSeparation.swift: -------------------------------------------------------------------------------- 1 | // Code Separation 2 | 3 | // We can take this one step further by creating 4 | // a private extension for private behavior. 5 | 6 | struct Person { 7 | // MARK: - Properties 8 | 9 | let first: String 10 | let last: String 11 | } 12 | 13 | // MARK: - Public Functions 14 | extension Person { 15 | // ... 16 | } 17 | 18 | // MARK: - Private Functions 19 | private extension Person { 20 | // ... 21 | } -------------------------------------------------------------------------------- /codes/CompactMapFunction.swift: -------------------------------------------------------------------------------- 1 | // Use compactMap function to receive an array of nonoptional values 2 | // when your transformation produces an optional value. 3 | let possibleNumbers = ["1", "2", "three", "///4///", "5", "Fish"] 4 | let mapped: [Int?] = possibleNumbers.map { Int($0) } 5 | // [1, 2, nil, nil, 5, nil] 6 | let compactMapped: [Int] = possibleNumbers.compactMap { Int($0) } 7 | // [1, 2, 5] 8 | -------------------------------------------------------------------------------- /codes/CompactMapValuesSwift5.swift: -------------------------------------------------------------------------------- 1 | // compactMapValues to Dictionary Swift 5.0 2 | 3 | // SE-0218 adds a new compactMapValues() method to dictionaries, 4 | // bringing together the compactMap() functionality from arrays 5 | // (“transform my values, unwrap the results, then discard 6 | // anything that’s nil”) with the mapValues() method from 7 | // dictionaries (“leave my keys intact but transform my values”). 8 | 9 | let d: [String: String?] = ["a": "1", "b": nil, "c": "3"] 10 | let r4 = d.compactMapValues({$0}) 11 | // r4 == ["a": "1", "c": "3"] 12 | 13 | let d: [String: String] = ["a": "1", "b": "2", "c": "three"] 14 | let r5 = d.compactMapValues(Int.init) 15 | // r5 == ["a": 1, "b": 2] -------------------------------------------------------------------------------- /codes/ComputedProperties.swift: -------------------------------------------------------------------------------- 1 | // In addition to stored properties, classes, structures, and enumerations 2 | // can define computed properties, which do not actually store a value. 3 | 4 | class Person { 5 | var name: String? 6 | var surname: String? 7 | // Computed Property 8 | var fullname: String? { 9 | guard let name = name, let surname = surname else { return nil } 10 | return "\(name) \(surname)" 11 | } 12 | } -------------------------------------------------------------------------------- /codes/ConformNeverToEquatableAndHashableSwift5.swift: -------------------------------------------------------------------------------- 1 | // Conform Never to Equatable and Hashable Swift 5.0 2 | 3 | // Proposal: SE-0215 4 | // Never is very useful for representing impossible code. 5 | // Most people are familiar with it as the return type of 6 | // functions like fatalError, but Never is also useful 7 | // when working with generic classes. 8 | // The standard library should add Equatable and Hashable 9 | // implementations for Never: 10 | 11 | extension Never: Equatable { 12 | public static func == (lhs: Never, rhs: Never) -> Bool { 13 | switch (lhs, rhs) { 14 | } 15 | } 16 | } 17 | 18 | extension Never: Hashable { 19 | public func hash(into hasher: inout Hasher) { 20 | } 21 | } -------------------------------------------------------------------------------- /codes/CountWhereSwift5.swift: -------------------------------------------------------------------------------- 1 | // count(where:) Swift 5.0 2 | 3 | // SE-0220 introduces a new count(where:) method 4 | // that performs the equivalent of a filter() and 5 | // count in a single pass. This saves the creation 6 | // of a new array that gets immediately discarded, 7 | // and provides a clear and concise solution to 8 | // a common problem. 9 | 10 | let scores = [100, 80, 85] 11 | let passCount = scores.count { $0 < 90 } -------------------------------------------------------------------------------- /codes/CustomOperator.swift: -------------------------------------------------------------------------------- 1 | // Custom Operator 2 | 3 | extension Vector2D { 4 | static prefix func +++ (vector: inout Vector2D) -> Vector2D { 5 | vector += vector 6 | return vector 7 | } 8 | } 9 | 10 | var toBeDoubled = Vector2D(x: 1.0, y: 4.0) 11 | let afterDoubling = +++toBeDoubled 12 | // toBeDoubled now has values of (2.0, 8.0) 13 | // afterDoubling also has values of (2.0, 8.0) -------------------------------------------------------------------------------- /codes/DecodingJSONFromBundle.swift: -------------------------------------------------------------------------------- 1 | // Decoding JSON from bundle 2 | 3 | extension Bundle { 4 | func decode(_ type: T.Type, from filename: String) -> T { 5 | guard let json = url(forResource: filename, withExtension: nil) else { 6 | fatalError("Failed to locate \(filename) in app bundle.") 7 | } 8 | 9 | guard let jsonData = try? Data(contentsOf: json) else { 10 | fatalError("Failed to load \(filename) from app bundle.") 11 | } 12 | 13 | let decoder = JSONDecoder() 14 | 15 | guard let result = try? decoder.decode(T.self, from: jsonData) else { 16 | fatalError("Failed to decode \(filename) from app bundle.") 17 | } 18 | 19 | return result 20 | } 21 | } 22 | 23 | let items = Bundle.main.decode([ResponseItem].self, from: "Response.json") -------------------------------------------------------------------------------- /codes/DefaultParameter.swift: -------------------------------------------------------------------------------- 1 | /* 2 | You can define a default value for any parameter 3 | in a function by assigning a value to the parameter 4 | after that parameter’s type. If a default value is 5 | defined, you can omit that parameter when calling the function. 6 | */ 7 | func saveToDisk(forced: Bool = false) { 8 | // save to disk logic 9 | } 10 | 11 | let card = Card(with: "Ali") 12 | card.saveToDisk() // saveToDisk func will consider forced is false 13 | card.saveToDisk(forced: true) // func will force 14 | -------------------------------------------------------------------------------- /codes/DefaultQoS.swift: -------------------------------------------------------------------------------- 1 | // Default QoS 2 | 3 | // The priority level of this QoS falls between 4 | // user-initiated and utility. This QoS is not 5 | // intended to be used by developers to classify 6 | // work. Work that has no QoS information assigned 7 | // is treated as default, and the GCD global queue 8 | // runs at this level. 9 | 10 | DispatchQueue.global(qos: .default).async { 11 | self.loadMore() 12 | } -------------------------------------------------------------------------------- /codes/DiscardableResult.swift: -------------------------------------------------------------------------------- 1 | /* 2 | Apply this attribute to a function or method declaration to suppress the 3 | compiler warning when the function or method that returns a value is called 4 | without using its result. 5 | */ 6 | @discardableResult 7 | func bumpUp() -> Int { 8 | // In this example, consider We have a model which is responsible to manage 9 | // pagination at our requests. This func bumps up the pageSize value 10 | // of the model. If you need that value, you can take it like; 11 | // let pageSize = pageItem.bumpUp() 12 | // If you not, you can just call pageItem.bumpUp() to increase value. 13 | pageSize += 1 14 | return pageSize 15 | } 16 | -------------------------------------------------------------------------------- /codes/DismissKeyboardInteractively.swift: -------------------------------------------------------------------------------- 1 | // Dismiss your keyboard when you are 2 | // scrolling your tableView down interactively. 3 | tableView.keyboardDismissMode = .interactive 4 | -------------------------------------------------------------------------------- /codes/DispatchGroup.swift: -------------------------------------------------------------------------------- 1 | // Dispatch Group 2 | 3 | // Let’s say you’ve got several long running tasks to perform. After all of 4 | // them have finished, you’d like to run some further logic. You could run 5 | // each task in a sequential fashion, but that isn’t so efficient - you’d 6 | // really like the former tasks to run concurrently. DispatchGroup enables 7 | // you to do exactly this. 8 | 9 | let dispatchGroup = DispatchGroup() 10 | 11 | dispatchGroup.enter() 12 | loadUserActivities { dispatchGroup.leave() } 13 | 14 | dispatchGroup.enter() 15 | loadUserPosts { dispatchGroup.leave() } 16 | 17 | dispatchGroup.notify(queue: .main) { 18 | collectionView.reloadData() 19 | } -------------------------------------------------------------------------------- /codes/DistanceOfTwoCGPoint.swift: -------------------------------------------------------------------------------- 1 | // Distance of two CGPoint 2 | 3 | extension CGPoint { 4 | func distance(from point: CGPoint) -> CGFloat { 5 | return CGPoint.distance(from: self, to: point) 6 | } 7 | 8 | static func distance(from point1: CGPoint, to point2: CGPoint) -> CGFloat { 9 | return sqrt(pow(point2.x - point1.x, 2) + pow(point2.y - point1.y, 2)) 10 | } 11 | } 12 | 13 | let pointA = CGPoint(x: 4, y: 5) 14 | let pointB = CGPoint(x: 8, y: 6) 15 | 16 | pointA.distance(from: pointB) // 4.1231056 17 | CGPoint.distance(from: pointA, to: pointB) // 4.1231056 -------------------------------------------------------------------------------- /codes/DistinctBy.swift: -------------------------------------------------------------------------------- 1 | // - distinct(by:) function 2 | 3 | struct Student { 4 | let id: Int 5 | } 6 | 7 | let students: [Student] = [1, 2, 2, 3, 3, 3].map({ Student(id: $0) }) 8 | // contents = student1, student2, student2, student3, student3, student3 9 | 10 | let uniqueStudents = students.distinct(by: { $0.id }) // Distinct by id. 11 | // contents = student1, student2, student3 12 | 13 | // - Definition 14 | 15 | public extension Sequence { 16 | 17 | /// Returns a sequence that contains no duplicate entries according to the 18 | /// generic hash and equality comparisons on the keys returned by the given 19 | /// key-generating block. If an element occurs multiple times in the sequence 20 | /// then the later occurrences are discarded. 21 | /// 22 | /// - Parameter keyBlock: Key generating block. 23 | public func distinct(by keyBlock: (Iterator.Element) -> Key) -> [Iterator.Element] { 24 | var seen: [Key: Bool] = [:] 25 | return self.filter { 26 | seen.updateValue(true, forKey: keyBlock($0)) == nil 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /codes/DynamicMemberLookup.swift: -------------------------------------------------------------------------------- 1 | // Dynamic Member Lookup 2 | // Apply this attribute to a class, structure, enumeration, or protocol 3 | // to enable members to be looked up by name at runtime. The type must 4 | // implement a subscript(dynamicMemberLookup:) subscript. 5 | 6 | @dynamicMemberLookup 7 | struct DynamicStruct { 8 | let dictionary = ["someDynamicMember": 325, 9 | "someOtherMember": 787] 10 | subscript(dynamicMember member: String) -> Int { 11 | return dictionary[member] ?? 1054 12 | } 13 | } 14 | let s = DynamicStruct() 15 | 16 | // Using dynamic member lookup 17 | let dynamic = s.someDynamicMember 18 | print(dynamic) 19 | // Prints "325" 20 | 21 | // Calling the underlying subscript directly 22 | let equivalent = s[dynamicMember: "someDynamicMember"] 23 | print(dynamic == equivalent) 24 | // Prints "true" -------------------------------------------------------------------------------- /codes/ElementOfOperator.swift: -------------------------------------------------------------------------------- 1 | infix operator ∈ 2 | func ∈ (lhs: T, rhs: [T]) -> Bool { 3 | return rhs.contains(lhs) 4 | } 5 | 6 | let month = "September" 7 | if month ∈ ["April", "June", "September", "November"] { 8 | print("\(month) has 30 days.") 9 | } 10 | // 👇🏻 You can take this sembol. -------------------------------------------------------------------------------- /codes/ExtensionForNestedTypes.swift: -------------------------------------------------------------------------------- 1 | // Extension for Nested Types 2 | 3 | // The result is quite nice. Not only can we group constants, 4 | // avoiding literals that are scattered throughout the 5 | // codebase, we also namespace the constants. In other words, 6 | // the constants are easy to remember and make sense. 7 | 8 | extension Service { 9 | enum Keys { 10 | static let apiKey = "asnjh12312uqw212sdg" 11 | } 12 | } 13 | 14 | extension UserDefaults { 15 | enum Keys { 16 | static let schedule = "schedule" 17 | } 18 | } 19 | 20 | extension ViewController { 21 | enum EventKeys { 22 | static let succesCheckout = "succesCheckout" 23 | static let failCheckout = "failCheckout" 24 | } 25 | } -------------------------------------------------------------------------------- /codes/FacadePattern.swift: -------------------------------------------------------------------------------- 1 | // Facade Pattern 2 | 3 | // The Facade design pattern provides a single interface 4 | // to a complex subsystem. Instead of exposing the user 5 | // to a set of classes and their APIs, you only expose 6 | // one simple unified API. 7 | 8 | class LibraryAPI { 9 | private let persistencyManager = PersistencyManager() 10 | private let httpClient = HTTPClient() 11 | var isOnline = false 12 | 13 | func getAlbums() -> [Album] { 14 | return persistencyManager.getAlbums() 15 | } 16 | 17 | func addAlbum(_ album: Album, at index: Int) { 18 | persistencyManager.addAlbum(album, at: index) 19 | if isOnline { 20 | httpClient.postRequest("/api/addAlbum", body: album.description) 21 | } 22 | } 23 | 24 | func deleteAlbum(at index: Int) { 25 | persistencyManager.deleteAlbum(at: index) 26 | if isOnline { 27 | httpClient.postRequest("/api/deleteAlbum", body: "\(index)") 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /codes/FactoryPattern.swift: -------------------------------------------------------------------------------- 1 | // Factory Pattern 2 | 3 | // Factory pattern can come in handy when you want to reduce the dependency of a class 4 | // on other classes. On the other hand, it encapsulates the object creation process 5 | // and users can simply pass in parameters to a generic factory class without knowing 6 | // how the objects are actually being created. Also it gives you a clean code. 7 | 8 | protocol Human { 9 | var name : String {get set} 10 | func run() 11 | func eat() 12 | func sleep() 13 | } 14 | 15 | class Soldier: Human { 16 | //... 17 | } 18 | class Civilian: Human { 19 | //... 20 | } 21 | 22 | enum HumanType { 23 | case soldier 24 | case civilian 25 | } 26 | 27 | class HumanFactory { 28 | static let shared = HumanFactory() 29 | 30 | func getHuman(type: HumanType, name: String) -> Human { 31 | switch type { 32 | case .soldier: 33 | return Soldier(soldierName: name) 34 | case .civilian: 35 | return Civilian(civilianName: name) 36 | } 37 | } 38 | } 39 | 40 | let soldier = HumanFactory.shared.getHuman(type: .soldier, name: "Jay") 41 | soldier.sleep() 42 | //soldider Jay is sleeping 43 | let civilian = HumanFactory.shared.getHuman(type: .civilian, name: "Saman") 44 | civilian.run() 45 | //Saman is running 46 | -------------------------------------------------------------------------------- /codes/Fallthrough.swift: -------------------------------------------------------------------------------- 1 | // Fallthrough 2 | // In Swift, switch statements don’t fall through the bottom of each case 3 | // and into the next one. That is, the entire switch statement completes 4 | // its execution as soon as the first matching case is completed. 5 | // If you need C-style fallthrough behavior, you can opt in to this 6 | // behavior on a case-by-case basis with the fallthrough keyword. 7 | 8 | let integerToDescribe = 5 9 | var description = "The number \(integerToDescribe) is" 10 | switch integerToDescribe { 11 | case 2, 3, 5, 7, 11, 13, 17, 19: 12 | description += " a prime number, and also" 13 | fallthrough 14 | default: 15 | description += " an integer." 16 | } 17 | print(description) 18 | // Prints "The number 5 is a prime number, and also an integer." 19 | -------------------------------------------------------------------------------- /codes/FilterFunction.swift: -------------------------------------------------------------------------------- 1 | let digits = [1, 4, 10, 15] 2 | let even = digits.filter { $0 % 2 == 0 } 3 | // [4, 10] 4 | 5 | let cast = ["Vivien", "Marlon", "Kim", "Karl"] 6 | let shortNames = cast.filter { $0.count < 5 } 7 | // ["Kim", "Karl"] -------------------------------------------------------------------------------- /codes/FirstWhere.swift: -------------------------------------------------------------------------------- 1 | // Use .first(where: (Int) throws -> Bool) 2 | // to retrieve first elemen in an array which contains 3 | // the same conditional objects. 4 | let numbers = [3, 7, 4, -2, 9, -6, 10, 1] 5 | if let firstNegative = numbers.first(where: { $0 < 0 }) { 6 | print("The first negative number is \(firstNegative).") 7 | } 8 | // Prints "The first negative number is -2." -------------------------------------------------------------------------------- /codes/FlattenNestedOptionalsSwift5.swift: -------------------------------------------------------------------------------- 1 | // Flatten nested optionals resulting from 'try?' Swift 5.0 2 | 3 | // SE-0230 modifies the way try? works so that nested optionals are flattened 4 | // to become regular optionals. This makes it work the same way as optional 5 | // chaining and conditional typecasts, both of which flatten optionals in 6 | // earlier Swift versions. 7 | 8 | // In Swift 5, try? someExpr() will mirror the behavior of foo?.someExpr(): 9 | 10 | // If someExpr() produces a non-optional value, it will be wrapped in an Optional. 11 | // If someExpr() produces an Optional, then no additional optional-ness is added. 12 | // This results in the following changes to the type of a try? expression: 13 | 14 | // Swift 4: 'Int??' 15 | // Swift 5: 'Int?' 16 | let result = try? database?.countOfRows(matching: predicate) 17 | 18 | 19 | // Swift 4: 'String??' 20 | // Swift 5: 'String?' 21 | let myString = try? String(data: someData, encoding: .utf8) 22 | 23 | // Swift 4: '[String: Any]??' 24 | // Swift 5: '[String: Any]?' 25 | let dict = try? JSONSerialization.jsonObject(with: data) as? [String: Any] -------------------------------------------------------------------------------- /codes/FunctionArgumentLabels.swift: -------------------------------------------------------------------------------- 1 | // Function Argument Labels 2 | 3 | // Normal usage 4 | func awesomeFunc(firstParameterName: Int, secondParameterName: Int) { 5 | // In the function body, firstParameterName and secondParameterName 6 | // refer to the argument values for the first and second parameters. 7 | } 8 | awesomeFunc(firstParameterName: 1, secondParameterName: 2) 9 | 10 | // Argument Label Usage 11 | func awesomeFunc(argumentLabel parameterName: Int) { 12 | // In the function body, parameterName refers to the argument value 13 | // for that parameter. 14 | } 15 | awesomeFunc(argumentLabel: 1) 16 | 17 | // Reallife Example 18 | // Consider this func is in subclassed UITableViewCell 19 | func populate(with user: User) { 20 | nameLabel.text = user.name 21 | ageLabel.text = user.age 22 | } 23 | 24 | cell.populate(with: users[indexPath.row]) 25 | -------------------------------------------------------------------------------- /codes/GenericFunctions.swift: -------------------------------------------------------------------------------- 1 | // Generic Functions can work with any type. 2 | // The generic function uses a placeholder type name 3 | // called T, in this case) instead of an actual type name 4 | // (such as Int, String, or Double). The placeholder type name 5 | // doesn’t say anything about what T must be, but it does 6 | // say that both a and b must be of the same type T, whatever T 7 | // represents. The actual type to use in place of T is determined 8 | // each time the swapTwoValues(_:_:) function is called. 9 | 10 | func swapTwoValues(_ a: inout T, _ b: inout T) { 11 | let temporaryA = a 12 | a = b 13 | b = temporaryA 14 | } 15 | var someInt = 3 16 | var anotherInt = 107 17 | swapTwoValues(&someInt, &anotherInt) 18 | // someInt is now 107, and anotherInt is now 3 19 | 20 | var someString = "hello" 21 | var anotherString = "world" 22 | swapTwoValues(&someString, &anotherString) 23 | // someString is now "world", and anotherString is now "hello" -------------------------------------------------------------------------------- /codes/GetAnElementInSafety.swift: -------------------------------------------------------------------------------- 1 | // Get an element in safety. 2 | 3 | public extension Collection { 4 | public subscript(safe index: Index) -> Element? { 5 | return startIndex <= index && index < endIndex ? self[index] : nil 6 | } 7 | } 8 | 9 | let array = [0, 1, 2] 10 | if let item = array[safe: 2] { 11 | print(item) 12 | } -------------------------------------------------------------------------------- /codes/GuardOptionalBinding.swift: -------------------------------------------------------------------------------- 1 | /* 2 | What makes the “guard” statement truly stand out, 3 | however, is that unwrapped optional values remain 4 | available in the rest of the code block. 5 | */ 6 | 7 | private func fetchContents() { 8 | webService.fetchCategories { [weak self] (response) in 9 | // Optional Binding for self 10 | guard let self = self else { return } 11 | self.createloadMoreRequest(content: response) 12 | } 13 | } 14 | 15 | private func createloadMoreRequest(content: Content?) { 16 | // Optional Binding for content 17 | guard let content = content else { return } 18 | let categoryId = content.categoryId 19 | self.loadMore(id: categoryId) 20 | } -------------------------------------------------------------------------------- /codes/HalfOpenRangeOperator.swift: -------------------------------------------------------------------------------- 1 | // Half-Open Range Operator 2 | 3 | // The half-open range operator (a..=4.2) 9 | // This will only be executed if the Swift version is less than 4.2. 10 | #endif 11 | 12 | #if !compiler(>=4.2) 13 | // This will only be executed if the Swift compiler version is less than 4.2. 14 | #endif 15 | 16 | #if swift(<4.2) 17 | // This will only be executed if the Swift version is less than 4.2. 18 | #endif 19 | 20 | #if compiler(<4.2) 21 | // This will only be executed if the Swift compiler version is less than 4.2. 22 | #endif -------------------------------------------------------------------------------- /codes/MapFunction.swift: -------------------------------------------------------------------------------- 1 | // Returns an array containing the results of mapping 2 | // the given closure over the sequence's elements. 3 | let cast = ["Vivien", "Marlon", "Kim", "Karl"] 4 | let lowercaseNames = cast.map { $0.lowercased() } 5 | // ["vivien", "marlon", "kim", "karl"] 6 | let letterCounts = cast.map { $0.count } 7 | // [6, 6, 3, 4] -------------------------------------------------------------------------------- /codes/MemberShortHand.swift: -------------------------------------------------------------------------------- 1 | // UIColor.white 2 | view.backgroundColor = .white 3 | // CGRect.zero 4 | view.frame = .zero 5 | // You can address initializers this way too 6 | tableView = .init(frame: .zero, style: .plain) -------------------------------------------------------------------------------- /codes/MultilineStringLiterals.swift: -------------------------------------------------------------------------------- 1 | // Multiline String Literals 2 | // If you need a string that spans several lines, use 3 | // a multiline string literal—a sequence of characters 4 | // surrounded by three double quotation marks: 5 | 6 | let quotation = """ 7 | The White Rabbit put on his spectacles. "Where shall I begin, 8 | please your Majesty?" he asked. 9 | 10 | "Begin at the beginning," the King said gravely, "and go on 11 | till you come to the end; then stop." 12 | """ -------------------------------------------------------------------------------- /codes/MutatingFunction.swift: -------------------------------------------------------------------------------- 1 | // Mutating Function 2 | // If you need to modify the properties of your structure or enumeration within 3 | // a particular method, you can opt in to mutating behavior for that method. 4 | 5 | struct Point { 6 | var x = 0.0, y = 0.0 7 | mutating func moveBy(x deltaX: Double, y deltaY: Double) { 8 | x += deltaX 9 | y += deltaY 10 | } 11 | } 12 | 13 | // Cannot use mutating member on immutable value: 'point' is a 'let' constant 14 | // let point = Point(x: 1.0, y: 1.0) 15 | // point.moveBy(x: 2.0, y: 3.0) 16 | 17 | var somePoint = Point(x: 1.0, y: 1.0) 18 | somePoint.moveBy(x: 2.0, y: 3.0) 19 | print("The point is now at (\(somePoint.x), \(somePoint.y))") 20 | // Prints "The point is now at (3.0, 4.0)" -------------------------------------------------------------------------------- /codes/NilCoalescingOperator.swift: -------------------------------------------------------------------------------- 1 | // Nil-Coalescing Operator 2 | 3 | // The nil-coalescing operator (a ?? b) unwraps an optional a if it contains a 4 | // value, or returns a default value b if a is nil. The expression a is always of 5 | // an optional type. The expression b must match the type that is stored inside a. 6 | 7 | let defaultColorName = "red" 8 | var userDefinedColorName: String? // defaults to nil 9 | 10 | var colorNameToUse = userDefinedColorName ?? defaultColorName 11 | // userDefinedColorName is nil, so colorNameToUse is set to the default of "red" 12 | 13 | userDefinedColorName = "green" 14 | colorNameToUse = userDefinedColorName ?? defaultColorName 15 | // userDefinedColorName is not nil, so colorNameToUse is set to "green" -------------------------------------------------------------------------------- /codes/ObserverPattern.swift: -------------------------------------------------------------------------------- 1 | // Observer Pattern 2 | 3 | // The Observer design pattern defines a one-to-many dependency between objects so 4 | // that when one object changes state, all its dependents are notified and updated 5 | // automatically. The Observer pattern is essentially a publish-and-subscribe model 6 | // in which the subject and its observers are loosely coupled. Communication can 7 | // take place between the observing and observed objects without either needing 8 | // to know much about the other. Cocoa implements the observer pattern in two ways: 9 | // Notifications and Key-Value Observing (KVO). 10 | 11 | protocol Observer { 12 | var id : Int { get } // property to get an id 13 | func update(with newValue: ObservableValue) 14 | } 15 | 16 | protocol Observable { 17 | associatedtype ObservableValue 18 | var value : ObservableValue { get set } 19 | var observers : [Observer] { get set } 20 | 21 | func addObserver(observer: Observer) 22 | func removeObserver(observer: Observer) 23 | func notifyAllObservers(with newValue: ObservableValue) 24 | } -------------------------------------------------------------------------------- /codes/OmittingArgumentLabels.swift: -------------------------------------------------------------------------------- 1 | // Omitting Argument Labels 2 | // If you don’t want an argument label for a parameter, write an underscore 3 | // (_) instead of an explicit argument label for that parameter. 4 | 5 | func awesomeFunc(_ firstParameterName: Int, secondParameterName: Int) { 6 | // In the function body, firstParameterName and secondParameterName 7 | // refer to the argument values for the first and second parameters. 8 | } 9 | awesomeFunc(1, secondParameterName: 2) 10 | 11 | // Example 12 | func multiply(_ firstNumber: Int, _ secondNumber: Int) -> Int { 13 | return firstNumber * secondNumber 14 | } 15 | 16 | let result = multiply(4, 7) -------------------------------------------------------------------------------- /codes/OneSidedRange.swift: -------------------------------------------------------------------------------- 1 | // One-Sided Ranges 2 | // The closed range operator has an alternative form for ranges 3 | // that continue as far as possible in one direction—for example, 4 | // a range that includes all the elements of an array from index 5 | // 2 to the end of the array. In these cases, you can omit the 6 | // value from one side of the range operator. This kind of range 7 | // is called a one-sided range because the operator has a value 8 | // on only one side. For example: 9 | 10 | let names = ["Anna", "Alex", "Brian", "Jack"] 11 | for name in names[2...] { 12 | print(name) 13 | } 14 | // Brian 15 | // Jack 16 | 17 | for name in names[...2] { 18 | print(name) 19 | } 20 | // Anna 21 | // Alex 22 | // Brian -------------------------------------------------------------------------------- /codes/OneTimeCode.swift: -------------------------------------------------------------------------------- 1 | // To enable security code autofill on a UITextField we need to set the textContentType property to .oneTimeCode. 2 | otpTextField.textContentType = .oneTimeCode 3 | -------------------------------------------------------------------------------- /codes/OperatorOverloading.swift: -------------------------------------------------------------------------------- 1 | // Operator Overloading 2 | 3 | struct Vector2D { 4 | var x = 0.0, y = 0.0 5 | } 6 | 7 | extension Vector2D { 8 | static func + (left: Vector2D, right: Vector2D) -> Vector2D { 9 | return Vector2D(x: left.x + right.x, y: left.y + right.y) 10 | } 11 | } 12 | 13 | let vector = Vector2D(x: 3.0, y: 1.0) 14 | let anotherVector = Vector2D(x: 2.0, y: 4.0) 15 | let combinedVector = vector + anotherVector 16 | // combinedVector is a Vector2D instance with values of (5.0, 5.0) -------------------------------------------------------------------------------- /codes/PassingOperator.swift: -------------------------------------------------------------------------------- 1 | // Passing operator as closures 2 | let array = [3, 9, 1, 4, 6, 2] 3 | let sorted = array.sorted(by: >) 4 | // [9, 6, 4, 3, 2, 1] -------------------------------------------------------------------------------- /codes/PreservingInitializers.swift: -------------------------------------------------------------------------------- 1 | // Preserving Initializers 2 | 3 | struct Person { 4 | // MARK: - Properties 5 | 6 | let first: String 7 | let last: String 8 | } 9 | 10 | extension Person { 11 | // MARK: - Initialization 12 | 13 | init(dictionary: [String: String]) { 14 | self.first = dictionary["first"] ?? "Emre" 15 | self.last = dictionary["last"] ?? "Ozdil" 16 | } 17 | } -------------------------------------------------------------------------------- /codes/PropertyObservers.swift: -------------------------------------------------------------------------------- 1 | // Property Observers 2 | /* 3 | Property observers observe and respond to changes in a property’s 4 | value. Property observers are called every time a property’s value is 5 | set, even if the new value is the same as the property’s current value. 6 | */ 7 | struct MyAwesomeClass { 8 | var awesomeProperty: String { 9 | willSet { 10 | // This will be called just before the property is set. 11 | print("value is \(self.awesomeProperty)") 12 | print("value will be \(newValue)") 13 | } 14 | 15 | didSet { 16 | // This will be called just after the property is set. 17 | print("value is \(self.awesomeProperty)") 18 | print("value was \(oldValue)") 19 | } 20 | } 21 | } 22 | 23 | let example = MyAwesomeClass(awesomeProperty: "iPhone7") 24 | example.awesomeProperty = "iPhoneX" 25 | // value is iPhone7 26 | // value will be iPhoneX 27 | // value is iPhoneX 28 | // value was iPhone7 29 | -------------------------------------------------------------------------------- /codes/ProtocolConformance.swift: -------------------------------------------------------------------------------- 1 | // Protocol Conformance 2 | 3 | // The Swift Programming Language mentions that extensions 4 | // can be used to conform an existing type to a protocol. 5 | // While this isn't new or revolutionary, it can also help 6 | // you keep your code organized. 7 | // Take the UITableViewDataSource and UITableViewDelegate 8 | // protocols as an example. This example may look familiar. 9 | // This is fine, but it results in a lengthy class 10 | // implementation that can become difficult to navigate over time. 11 | 12 | class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { 13 | // ... 14 | } 15 | 16 | // You can keep your code organized by creating an extension for 17 | // each protocol the type conforms to. 18 | 19 | class ViewController: UIViewController { 20 | // ... 21 | } 22 | 23 | extension ViewController: UITableViewDataSource { 24 | // ... 25 | } 26 | 27 | extension ViewController: UITableViewDelegate { 28 | // ... 29 | } -------------------------------------------------------------------------------- /codes/PublicPrivateSet.swift: -------------------------------------------------------------------------------- 1 | // Swift has a great middle ground: public private(set). 2 | // This lets us mark a property as being open for reading but closed for writing 3 | 4 | struct Bank { 5 | public private(set) var address: String 6 | } 7 | 8 | let bank = Bank(address: "My Address") 9 | 10 | // Bank address getter is public 11 | print(bank.address) // OUTPUT: My Address 12 | 13 | // Bank address setter is private 14 | // bank.address = "Karim" // Compile Error -------------------------------------------------------------------------------- /codes/QualityOfServiceClasses.swift: -------------------------------------------------------------------------------- 1 | // Quality of Service Classes 2 | 3 | // Apps and operations compete to use finite resources: memory, network interfaces, 4 | // CPU, and so on. In order to remain responsive and efficient, the system needs to 5 | // prioritize tasks and make intelligent decisions about when to execute them. 6 | 7 | // A quality of service (QoS) class allows you to categorize work to be performed by 8 | // NSOperation, NSOperationQueue, NSThread objects, dispatch queues, and pthreads 9 | // (POSIX threads). By assigning a QoS to work, you indicate its importance, and 10 | // the system prioritizes it and schedules it accordingly. 11 | 12 | import Foundation 13 | //@available(OSX 10.10, iOS 8.0, *) 14 | 15 | // Work is virtually instantaneous. 16 | DispatchQoS.userInteractive 17 | // Work is nearly instantaneous, such as a few seconds or less. 18 | DispatchQoS.userInitiated 19 | // Work takes a few seconds. 20 | DispatchQoS.default 21 | // Work takes a few seconds to a few minutes. 22 | DispatchQoS.utility 23 | // Work takes significant time, such as minutes or hours. 24 | DispatchQoS.background 25 | 26 | // Stay tuned for more information about Quality of Service. -------------------------------------------------------------------------------- /codes/RegisterDequeueXIBCollectionView.swift: -------------------------------------------------------------------------------- 1 | // Register - Dequeue XIB UICollectionView 2 | 3 | public extension UICollectionView { 4 | public func register(cellType: T.Type, bundle: Bundle? = nil) { 5 | let className = cellType.className 6 | let nib = UINib(nibName: className, bundle: bundle) 7 | register(nib, forCellWithReuseIdentifier: className) 8 | } 9 | 10 | public func register(cellTypes: [T.Type], bundle: Bundle? = nil) { 11 | cellTypes.forEach { register(cellType: $0, bundle: bundle) } 12 | } 13 | 14 | public func register(reusableViewType: T.Type, 15 | ofKind kind: String = UICollectionElementKindSectionHeader, 16 | bundle: Bundle? = nil) { 17 | let className = reusableViewType.className 18 | let nib = UINib(nibName: className, bundle: bundle) 19 | register(nib, forSupplementaryViewOfKind: kind, withReuseIdentifier: className) 20 | } 21 | 22 | public func register(reusableViewTypes: [T.Type], 23 | ofKind kind: String = UICollectionElementKindSectionHeader, 24 | bundle: Bundle? = nil) { 25 | reusableViewTypes.forEach { register(reusableViewType: $0, ofKind: kind, bundle: bundle) } 26 | } 27 | 28 | public func dequeueReusableCell(with type: T.Type, 29 | for indexPath: IndexPath) -> T { 30 | return dequeueReusableCell(withReuseIdentifier: type.className, for: indexPath) as! T 31 | } 32 | 33 | public func dequeueReusableView(with type: T.Type, 34 | for indexPath: IndexPath, 35 | ofKind kind: String = UICollectionElementKindSectionHeader) -> T { 36 | return dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: type.className, for: indexPath) as! T 37 | } 38 | } -------------------------------------------------------------------------------- /codes/RegisterDequeueXIBTableView.swift: -------------------------------------------------------------------------------- 1 | // Register / Dequeue XIB UITableViewCell 2 | 3 | public extension UITableView { 4 | public func register(cellType: T.Type, bundle: Bundle? = nil) { 5 | let className = cellType.className 6 | let nib = UINib(nibName: className, bundle: bundle) 7 | register(nib, forCellReuseIdentifier: className) 8 | } 9 | 10 | public func register(cellTypes: [T.Type], bundle: Bundle? = nil) { 11 | cellTypes.forEach { register(cellType: $0, bundle: bundle) } 12 | } 13 | 14 | public func dequeueReusableCell(with type: T.Type, for indexPath: IndexPath) -> T { 15 | return self.dequeueReusableCell(withIdentifier: type.className, for: indexPath) as! T 16 | } 17 | } 18 | 19 | tableView.register(cellType: MyCell.self) 20 | tableView.register(cellTypes: [MyCell1.self, MyCell2.self]) 21 | 22 | let cell = tableView.dequeueReusableCell(with: MyCell.self, for: indexPath) -------------------------------------------------------------------------------- /codes/RemoveElementInArray.swift: -------------------------------------------------------------------------------- 1 | // Remove element by the instances in an array 2 | 3 | public extension Array where Element: Equatable { 4 | @discardableResult 5 | public mutating func remove(element: Element) -> Index? { 6 | guard let index = index(of: element) else { return nil } 7 | remove(at: index) 8 | return index 9 | } 10 | 11 | @discardableResult 12 | public mutating func remove(elements: [Element]) -> [Index] { 13 | return elements.flatMap { remove(element: $0) } 14 | } 15 | } 16 | 17 | let array = ["foo", "bar"] 18 | array.remove(element: "foo") 19 | array // ["bar"] -------------------------------------------------------------------------------- /codes/RemoveTheSameValueFromTheArray.swift: -------------------------------------------------------------------------------- 1 | // Remove the same value from the array 2 | 3 | public extension Array where Element: Hashable { 4 | public mutating func unify() { 5 | self = unified() 6 | } 7 | } 8 | 9 | public extension Collection where Element: Hashable { 10 | public func unified() -> [Element] { 11 | return reduce(into: []) { 12 | if !$0.contains($1) { 13 | $0.append($1) 14 | } 15 | } 16 | } 17 | } 18 | 19 | var array = [1, 2, 3, 3, 2, 1, 4] 20 | array.unify() // [1, 2, 3, 4] -------------------------------------------------------------------------------- /codes/RepeatWhile.swift: -------------------------------------------------------------------------------- 1 | // Repeat-While 2 | // The other variation of the while loop, known as the repeat-while loop, 3 | // performs a single pass through the loop block first, before considering 4 | // the loop’s condition. It then continues to repeat the loop until the 5 | // condition is false. 6 | 7 | // The repeat-while loop in Swift is analogous to a do-while loop in 8 | // other languages. 9 | 10 | repeat { 11 | // move up or down for a snake or ladder 12 | square += board[square] 13 | // roll the dice 14 | diceRoll += 1 15 | if diceRoll == 7 { diceRoll = 1 } 16 | // move by the rolled amount 17 | square += diceRoll 18 | } while square < finalSquare 19 | print("Game over!") -------------------------------------------------------------------------------- /codes/RequiredHeightForLabel.swift: -------------------------------------------------------------------------------- 1 | // Required height for label 2 | 3 | extension UILabel { 4 | var requiredHeight: CGFloat { 5 | let label = UILabel(frame: CGRect(x: 0, y: 0, width: frame.width, height: CGFloat.greatestFiniteMagnitude)) 6 | label.numberOfLines = 0 7 | label.lineBreakMode = NSLineBreakMode.byWordWrapping 8 | label.font = font 9 | label.text = text 10 | label.attributedText = attributedText 11 | label.sizeToFit() 12 | return label.frame.height 13 | } 14 | } -------------------------------------------------------------------------------- /codes/ReturnMultipleValues.swift: -------------------------------------------------------------------------------- 1 | // Use a tuple to make a compound value—for example, to return 2 | // multiple values from a function. The elements of a tuple 3 | // can be referred to either by name or by number. 4 | 5 | func calculateStatistics(scores: [Int]) -> (min: Int, max: Int, sum: Int) { 6 | guard let min = scores.min(), let max = scores.max() else { 7 | fatalError("Scores is nil") 8 | } 9 | 10 | let sum = scores.reduce(0) { $0 + $1 } 11 | 12 | return (min, max, sum) 13 | } 14 | let statistics = calculateStatistics(scores: [5, 3, 100, 3, 9]) 15 | print(statistics.max) 16 | // Prints "100" 17 | print(statistics.2) 18 | // Prints "120" -------------------------------------------------------------------------------- /codes/SearchBarTextField.swift: -------------------------------------------------------------------------------- 1 | // Search Bar Text Field 2 | 3 | extension UISearchBar { 4 | func searchBarTextField() -> UITextField? { 5 | for view in subviews { 6 | for subview in view.subviews { 7 | if let textField = subview as? UITextField { 8 | return textField 9 | } 10 | } 11 | } 12 | return nil 13 | } 14 | } -------------------------------------------------------------------------------- /codes/ShowAlertFunction.swift: -------------------------------------------------------------------------------- 1 | 2 | // You can implement a method as an extension to base UIViewController class 3 | // to show information alert to users with a simple Okay button. 4 | extension UIViewController { 5 | func showAlert(title: String, message: String) { 6 | let alert = UIAlertController(title: title, message: message, preferredStyle: .alert) 7 | alert.addAction(UIAlertAction(title: NSLocalizedString("Okay", comment: ""), style: .default, handler: nil)) 8 | self.present(alert, animated: true, completion: nil) 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /codes/ShuffledAndShuffleFunctions.swift: -------------------------------------------------------------------------------- 1 | // Shuffled and shuffle functions 2 | 3 | var numbers = [1, 2, 3, 4, 5, 6] 4 | let shuffledNumbers = numbers.shuffled() 5 | // shuffledNumbers == [6, 1, 3, 2, 5, 4] 6 | // numbers == [1, 2, 3, 4, 5, 6] 7 | 8 | numbers.shuffle() 9 | // numbers == [4, 2, 6, 5, 1, 3] -------------------------------------------------------------------------------- /codes/SimpleDefer.swift: -------------------------------------------------------------------------------- 1 | // A defer statement is used for executing code just before 2 | // transferring program control outside of the scope that 3 | // the defer statement appears in. 4 | 5 | func simpleDefer() { 6 | defer { print("End of the function") } 7 | 8 | print("Main body of the simleDefer function") 9 | } 10 | // Prints: Main body of the simleDefer function 11 | // Prints: End of the function -------------------------------------------------------------------------------- /codes/SingletonPattern.swift: -------------------------------------------------------------------------------- 1 | // Singleton Pattern 2 | 3 | // Singletons are easy to understand. The singleton pattern guarantees 4 | // that only one instance of a class is instantiated. 5 | 6 | // Shared URL Session 7 | let sharedURLSession = URLSession.shared 8 | 9 | // Standard User Defaults 10 | let standardUserDefaults = UserDefaults.standard 11 | 12 | class NetworkManager { 13 | static let shared = NetworkManager(baseURL: API.baseURL) 14 | 15 | let baseURL: URL 16 | 17 | // A private initializer can only be called by this class itself. 18 | private init(baseURL: URL) { 19 | self.baseURL = baseURL 20 | } 21 | } 22 | 23 | NetworkManager.shared -------------------------------------------------------------------------------- /codes/SketchShadow.swift: -------------------------------------------------------------------------------- 1 | // Sketch Shadow 2 | 3 | extension CALayer { 4 | func applySketchShadow( 5 | color: UIColor = .black, 6 | alpha: Float = 0.5, 7 | x: CGFloat = 0, 8 | y: CGFloat = 2, 9 | blur: CGFloat = 4, 10 | spread: CGFloat = 0) 11 | { 12 | shadowColor = color.cgColor 13 | shadowOpacity = alpha 14 | shadowOffset = CGSize(width: x, height: y) 15 | shadowRadius = blur / 2.0 16 | if spread == 0 { 17 | shadowPath = nil 18 | } else { 19 | let dx = -spread 20 | let rect = bounds.insetBy(dx: dx, dy: dx) 21 | shadowPath = UIBezierPath(rect: rect).cgPath 22 | } 23 | } 24 | } 25 | 26 | layer.applySketchShadow() 27 | layer.applySketchShadow(color: .red, alpha: 0.6, x: 0, y: 4, blur: 8, spread: -4) 28 | -------------------------------------------------------------------------------- /codes/SnapKitUsage.swift: -------------------------------------------------------------------------------- 1 | // SnapKit Usage 2 | 3 | titleLabel.translatesAutoresizingMaskIntoConstraints = false 4 | titleLabel.topAnchor.constraint(equalTo: self.topAnchor, constant: 8).isActive = true 5 | titleLabel.leadingAnchor.constraint(equalTo: self.leadingAnchor, constant: 8).isActive = true 6 | titleLabel.trailingAnchor.constraint(equalTo: self.trailingAnchor, constant: -8).isActive = true 7 | titleLabel.bottomAnchor.constraint(equalTo: self.descriptionLabel.topAnchor, constant: -8).isActive = true 8 | 9 | descriptionLabel.translatesAutoresizingMaskIntoConstraints = false 10 | descriptionLabel.topAnchor.constraint(equalTo: self.titleLabel.bottomAnchor, constant: 8).isActive = true 11 | descriptionLabel.leadingAnchor.constraint(equalTo: self.titleLabel.leadingAnchor).isActive = true 12 | descriptionLabel.trailingAnchor.constraint(equalTo: self.titleLabel.trailingAnchor).isActive = true 13 | descriptionLabel.bottomAnchor.constraint(equalTo: self.bottomAnchor, constant: -8).isActive = true 14 | 15 | import SnapKit 16 | 17 | titleLabel.snp.makeConstraints { (make) in 18 | make.top.equalToSuperview().offset(8) 19 | make.leading.equalToSuperview().offset(8) 20 | make.trailing.equalToSuperview().offset(-8) 21 | make.bottom.equalTo(descriptionLabel.snp.top).offset(-8) 22 | } 23 | 24 | descriptionLabel.snp.makeConstraints { (make) in 25 | make.top.equalTo(titleLabel.snp.bottom).offset(8) 26 | make.leading.equalTo(titleLabel.snp.leading) 27 | make.trailing.equalTo(titleLabel.snp.trailing) 28 | make.bottom.equalToSuperview().offset(-8) 29 | } 30 | -------------------------------------------------------------------------------- /codes/StaticFactoryMethodsForUILabel.swift: -------------------------------------------------------------------------------- 1 | extension UILabel { 2 | // MARK: - Static Factory Method for Title 3 | static func initForTitle() -> UILabel { 4 | let label = UILabel() 5 | label.font = .boldSystemFont(ofSize: 18) 6 | label.textColor = .darkGray 7 | label.numberOfLines = 1 8 | label.adjustsFontSizeToFitWidth = true 9 | label.minimumScaleFactor = 0.75 10 | return label 11 | } 12 | 13 | // MARK: - Static Factory Method for Description 14 | static func initForDescription() -> UILabel { 15 | let label = UILabel() 16 | label.font = .systemFont(ofSize: 14) 17 | label.textColor = .black 18 | label.numberOfLines = 0 19 | return label 20 | } 21 | } 22 | 23 | class ContentViewController: UIViewController { 24 | lazy var titleLabel = UILabel.initForTitle() 25 | lazy var textLabel = UILabel.initForDescription() 26 | } -------------------------------------------------------------------------------- /codes/StaticTypeProperties.swift: -------------------------------------------------------------------------------- 1 | // Static - Type Properties 2 | 3 | // No longer have to initialize an object to access properties. 4 | // Constant struct contains static type properties 5 | 6 | struct Constant { 7 | static let baseUrl = "https://github.com/MobileTipsters/Swift-Daily-Tips/" 8 | static let backgroundColor = UIColor.lightGray 9 | } 10 | 11 | let githubRepo = URL(string: Constant.baseUrl) 12 | view.backgroundColor = Constant.backgroundColor -------------------------------------------------------------------------------- /codes/StrategyPattern.swift: -------------------------------------------------------------------------------- 1 | // Strategy Pattern 2 | 3 | // In Strategy pattern, a class behavior or its algorithm can be changed 4 | // at run time. This type of design pattern comes under behavior pattern. 5 | // In Strategy pattern, we create objects which represent various strategies 6 | // and a context object whose behavior varies as per its strategy object. 7 | // The strategy object changes the executing algorithm of the context object. 8 | 9 | protocol Fly { 10 | func fly() 11 | } 12 | 13 | class Bird: Fly { 14 | func fly() { 15 | print("Spread Wings") 16 | } 17 | } 18 | 19 | class Plane: Fly { 20 | func fly() { 21 | print("We are Turkish Airlines, We are Globally Yours") 22 | } 23 | } 24 | 25 | let flyableObject: Fly = Plane() 26 | flyableObject.fly() -------------------------------------------------------------------------------- /codes/SumFunction.swift: -------------------------------------------------------------------------------- 1 | // Sum Function for Numeric Collection 2 | 3 | extension Collection where Element: Numeric { 4 | func sum() -> Element { 5 | return self.reduce(0, +) 6 | } 7 | } 8 | 9 | [3, 4, 6].sum() // 13 10 | [3.4, 6.2, 7.3].sum() // 16.9 -------------------------------------------------------------------------------- /codes/SwapValues.swift: -------------------------------------------------------------------------------- 1 | // Swaping two variables 2 | 3 | var firstVariable = 5 4 | var secondVariable = 10 5 | 6 | print(firstVariable) // OUTPUT: 5 7 | print(secondVariable) // OUTPUT: 10 8 | 9 | // Swap firstVariable value with secondVariable value. 10 | (firstVariable, secondVariable) = (secondVariable, firstVariable) 11 | 12 | print(firstVariable) // OUTPUT: 10 13 | print(secondVariable) // OUTPUT: 5 -------------------------------------------------------------------------------- /codes/SwitchRootVCExtension.swift: -------------------------------------------------------------------------------- 1 | // Switch Root VC Extension 2 | // This function can use to change between normal mode and dark mode. 3 | // Because the navigation bar and the tab bar appearance can be changed. 4 | 5 | extension UIWindow { 6 | func switchRootViewController(_ viewController: UIViewController, 7 | animated: Bool = true, 8 | duration: TimeInterval = 0, 9 | options: UIView.AnimationOptions = .curveEaseInOut, 10 | completion: (() -> Void)? = nil) { 11 | guard animated else { 12 | rootViewController = viewController 13 | return 14 | } 15 | 16 | UIView.transition(with: self, duration: duration, options: options, animations: { 17 | let oldState = UIView.areAnimationsEnabled 18 | UIView.setAnimationsEnabled(false) 19 | self.rootViewController = viewController 20 | UIView.setAnimationsEnabled(oldState) 21 | }) { _ in 22 | completion?() 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /codes/TernaryOperator.swift: -------------------------------------------------------------------------------- 1 | /* 2 | The ternary conditional operator is a special operator with three parts, 3 | which takes the form question ? answer1 : answer2. It’s a shortcut for 4 | evaluating one of two expressions based on whether question is true or 5 | false. If question is true, it evaluates answer1 and returns its value; 6 | otherwise, it evaluates answer2 and returns its value. 7 | */ 8 | 9 | // General usage for if/else 10 | if condition { 11 | logic1() 12 | } else { 13 | logic2() 14 | } 15 | 16 | // Ternary Usage 17 | condition ? logic1() : logic2() 18 | // Real life example 19 | let height = shouldShowInformationView ? 100 : 50 20 | -------------------------------------------------------------------------------- /codes/TypeMethods.swift: -------------------------------------------------------------------------------- 1 | // You indicate type methods by writing the static keyword 2 | // before the method’s func keyword. Classes may also use 3 | // the class keyword to allow subclasses to override 4 | // the superclass’s implementation of that method. 5 | 6 | class Service { 7 | class func fetchData() { } 8 | static func sendData() { } 9 | } 10 | 11 | class MovieService: Service { 12 | override class func fetchData() { } 13 | // Cannot override static function 14 | // override static func sendData() { } 15 | } 16 | 17 | // No longer have to initialize an object to access functions. 18 | Service.sendData() 19 | MovieService.fetchData() -------------------------------------------------------------------------------- /codes/UIColorConvenienceInit.swift: -------------------------------------------------------------------------------- 1 | extension UIColor { 2 | // UIColor(r: 95, g: 199, b: 220) 3 | convenience init(r: Int, g: Int, b: Int) { 4 | self.init(red: CGFloat(r) / 255.0, green: CGFloat(g) / 255.0, blue: CGFloat(b) / 255.0, alpha: 1.0) 5 | } 6 | // UIColor(hex: 0x5fc7dc) 7 | convenience init(hex:Int) { 8 | self.init(r:(hex >> 16) & 0xff, g:(hex >> 8) & 0xff, b:hex & 0xff) 9 | } 10 | } -------------------------------------------------------------------------------- /codes/UnaryMinusOperator.swift: -------------------------------------------------------------------------------- 1 | // Unary Minus Operator 2 | 3 | // The sign of a numeric value can be toggled using a prefixed -, 4 | // known as the unary minus operator: 5 | 6 | let three = 3 7 | let minusThree = -three // minusThree equals -3 8 | let plusThree = -minusThree // plusThree equals 3, or "minus minus three" 9 | 10 | // The unary minus operator (-) is prepended directly before the value 11 | // it operates on, without any white space. -------------------------------------------------------------------------------- /codes/UrlQueryParameters.swift: -------------------------------------------------------------------------------- 1 | // Dictionary of the URL's query parameters 2 | 3 | extension URL { 4 | var queryParameters: [String: String]? { 5 | guard let components = URLComponents(url: self, resolvingAgainstBaseURL: false) else { return nil } 6 | guard let queryItems = components.queryItems else { return nil } 7 | 8 | var items: [String: String] = [:] 9 | 10 | for queryItem in queryItems { 11 | items[queryItem.name] = queryItem.value 12 | } 13 | 14 | return items 15 | } 16 | } -------------------------------------------------------------------------------- /codes/UserInitiatedQoS.swift: -------------------------------------------------------------------------------- 1 | // User Initiated 2 | 3 | // Work that the user has initiated and requires immediate results, 4 | // such as opening a saved document or performing an action when the 5 | // user clicks something in the user interface. The work is required 6 | // in order to continue user interaction. Focuses on responsiveness 7 | // and performance. 8 | 9 | DispatchQueue.global(qos: .userInitiated).async { 10 | if let url = URL(string: urlString) { 11 | if let data = try? Data(contentsOf: url) { 12 | self.parse(json: data) 13 | return 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /codes/UserInteractiveQoS.swift: -------------------------------------------------------------------------------- 1 | // User Interactive 2 | 3 | // Work that is interacting with the user, such as operating 4 | // on the main thread, refreshing the user interface, or 5 | // performing animations. If the work doesn’t happen quickly, 6 | // the user interface may appear frozen. 7 | // Focuses on responsiveness and performance. 8 | 9 | DispatchQueue.global(qos: .userInteractive).async { 10 | self.fadeInNewImage(overlayImage) 11 | self.tableView.reloadData() 12 | } 13 | -------------------------------------------------------------------------------- /codes/UtilityQoS.swift: -------------------------------------------------------------------------------- 1 | // Utility QoS 2 | 3 | // Work that may take some time to complete and doesn’t require 4 | // an immediate result, such as downloading or importing data. 5 | // Utility tasks typically have a progress bar that is visible 6 | // to the user. Focuses on providing a balance between 7 | // responsiveness, performance, and energy efficiency. 8 | 9 | 10 | DispatchQueue.global(qos: .utility).async { 11 | API.readNotification(notificationId) 12 | } -------------------------------------------------------------------------------- /codes/VariadicParameters.swift: -------------------------------------------------------------------------------- 1 | // Variadic Parameters 2 | // A variadic parameter accepts zero or more values of a specified type. 3 | // You use a variadic parameter to specify that the parameter can be 4 | // passed a varying number of input values when the function is called. 5 | // Write variadic parameters by inserting three period characters (...) 6 | // after the parameter’s type name. 7 | 8 | func arithmeticMean(_ numbers: Double...) -> Double { 9 | var total: Double = 0 10 | for number in numbers { 11 | total += number 12 | } 13 | return total / Double(numbers.count) 14 | } 15 | arithmeticMean(1, 2, 3, 4, 5) 16 | // returns 3.0, which is the arithmetic mean of these five numbers 17 | arithmeticMean(3, 8.25, 18.75) 18 | // returns 10.0, which is the arithmetic mean of these three numbers -------------------------------------------------------------------------------- /codes/WordCountFunction.swift: -------------------------------------------------------------------------------- 1 | // Word Count Function 2 | 3 | import Foundation 4 | 5 | extension String { 6 | var wordCount: Int { 7 | let regex = try? NSRegularExpression(pattern: "\\w+") 8 | return regex?.numberOfMatches(in: self, range: NSRange(location: 0, length: self.utf16.count)) ?? 0 9 | } 10 | } 11 | 12 | let phrase = "The rain in Spain" 13 | print(phrase.wordCount) // 4 14 | -------------------------------------------------------------------------------- /icons/CarbonSettings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/icons/CarbonSettings.png -------------------------------------------------------------------------------- /icons/instagram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/icons/instagram.png -------------------------------------------------------------------------------- /icons/sdt-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/icons/sdt-logo.png -------------------------------------------------------------------------------- /icons/telegram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/icons/telegram.png -------------------------------------------------------------------------------- /icons/twitter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/icons/twitter.png -------------------------------------------------------------------------------- /screenshots/AdapterPattern.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/AdapterPattern.png -------------------------------------------------------------------------------- /screenshots/AddSubviewExtension.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/AddSubviewExtension.png -------------------------------------------------------------------------------- /screenshots/AddingPrefixToString.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/AddingPrefixToString.png -------------------------------------------------------------------------------- /screenshots/AllSatisfyFunction.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/AllSatisfyFunction.png -------------------------------------------------------------------------------- /screenshots/ArrayPrependExtensionFunction.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/ArrayPrependExtensionFunction.png -------------------------------------------------------------------------------- /screenshots/AutoLayoutExtension.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/AutoLayoutExtension.png -------------------------------------------------------------------------------- /screenshots/BackgroundQoS.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/BackgroundQoS.png -------------------------------------------------------------------------------- /screenshots/BitwiseShiftOperators.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/BitwiseShiftOperators.png -------------------------------------------------------------------------------- /screenshots/BuilderPattern.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/BuilderPattern.png -------------------------------------------------------------------------------- /screenshots/BundleExtension.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/BundleExtension.png -------------------------------------------------------------------------------- /screenshots/CStyleForLoopUsingStride.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/CStyleForLoopUsingStride.png -------------------------------------------------------------------------------- /screenshots/CaseIterable.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/CaseIterable.png -------------------------------------------------------------------------------- /screenshots/CharacterPropertiesSwift5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/CharacterPropertiesSwift5.png -------------------------------------------------------------------------------- /screenshots/ClassNameExtension.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/ClassNameExtension.png -------------------------------------------------------------------------------- /screenshots/ClosedRangeOperator.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/ClosedRangeOperator.png -------------------------------------------------------------------------------- /screenshots/CodeSeparation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/CodeSeparation.png -------------------------------------------------------------------------------- /screenshots/CompactMapFunction.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/CompactMapFunction.png -------------------------------------------------------------------------------- /screenshots/CompactMapValuesSwift5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/CompactMapValuesSwift5.png -------------------------------------------------------------------------------- /screenshots/ComputedProperties.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/ComputedProperties.png -------------------------------------------------------------------------------- /screenshots/ConformNeverToEquatableAndHashableSwift5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/ConformNeverToEquatableAndHashableSwift5.png -------------------------------------------------------------------------------- /screenshots/CountWhereSwift5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/CountWhereSwift5.png -------------------------------------------------------------------------------- /screenshots/CustomOperator.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/CustomOperator.png -------------------------------------------------------------------------------- /screenshots/DecodingJSONFromBundle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/DecodingJSONFromBundle.png -------------------------------------------------------------------------------- /screenshots/DefaultParameter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/DefaultParameter.png -------------------------------------------------------------------------------- /screenshots/DefaultQoS.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/DefaultQoS.png -------------------------------------------------------------------------------- /screenshots/DiscardableResult.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/DiscardableResult.png -------------------------------------------------------------------------------- /screenshots/DismissKeyboardInteractively.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/DismissKeyboardInteractively.png -------------------------------------------------------------------------------- /screenshots/DispatchGroup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/DispatchGroup.png -------------------------------------------------------------------------------- /screenshots/DistanceOfTwoCGPoint.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/DistanceOfTwoCGPoint.png -------------------------------------------------------------------------------- /screenshots/DistinctBy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/DistinctBy.png -------------------------------------------------------------------------------- /screenshots/DynamicMemberLookup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/DynamicMemberLookup.png -------------------------------------------------------------------------------- /screenshots/ElementOfOperator.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/ElementOfOperator.png -------------------------------------------------------------------------------- /screenshots/ExtensionForNestedTypes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/ExtensionForNestedTypes.png -------------------------------------------------------------------------------- /screenshots/FacadePattern.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/FacadePattern.png -------------------------------------------------------------------------------- /screenshots/FactoryPattern.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/FactoryPattern.png -------------------------------------------------------------------------------- /screenshots/Fallthrough.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/Fallthrough.png -------------------------------------------------------------------------------- /screenshots/FilterFunction.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/FilterFunction.png -------------------------------------------------------------------------------- /screenshots/FirstWhere.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/FirstWhere.png -------------------------------------------------------------------------------- /screenshots/FlattenNestedOptionalsSwift5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/FlattenNestedOptionalsSwift5.png -------------------------------------------------------------------------------- /screenshots/FunctionArgumentLabels.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/FunctionArgumentLabels.png -------------------------------------------------------------------------------- /screenshots/GenericFunctions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/GenericFunctions.png -------------------------------------------------------------------------------- /screenshots/GetAnElementInSafety.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/GetAnElementInSafety.png -------------------------------------------------------------------------------- /screenshots/GuardOptionalBinding.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/GuardOptionalBinding.png -------------------------------------------------------------------------------- /screenshots/HalfOpenRangeOperator.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/HalfOpenRangeOperator.png -------------------------------------------------------------------------------- /screenshots/HandlingFutureEnumCasesSwift5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/HandlingFutureEnumCasesSwift5.png -------------------------------------------------------------------------------- /screenshots/ImportanceOfWeakReference.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/ImportanceOfWeakReference.png -------------------------------------------------------------------------------- /screenshots/InoutParameter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/InoutParameter.png -------------------------------------------------------------------------------- /screenshots/IntAndStringDescriptionOfBool.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/IntAndStringDescriptionOfBool.png -------------------------------------------------------------------------------- /screenshots/IntToUIntDoubleFloat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/IntToUIntDoubleFloat.png -------------------------------------------------------------------------------- /screenshots/IsMultipleSwift5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/IsMultipleSwift5.png -------------------------------------------------------------------------------- /screenshots/Join&SplitFunction.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/Join&SplitFunction.png -------------------------------------------------------------------------------- /screenshots/LabeledStatements.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/LabeledStatements.png -------------------------------------------------------------------------------- /screenshots/LazyProperty.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/LazyProperty.png -------------------------------------------------------------------------------- /screenshots/LessThanOperatorSwift5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/LessThanOperatorSwift5.png -------------------------------------------------------------------------------- /screenshots/MapFunction.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/MapFunction.png -------------------------------------------------------------------------------- /screenshots/MemberShortHand.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/MemberShortHand.png -------------------------------------------------------------------------------- /screenshots/MultilineStringLiterals.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/MultilineStringLiterals.png -------------------------------------------------------------------------------- /screenshots/MutatingFunction.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/MutatingFunction.png -------------------------------------------------------------------------------- /screenshots/NilCoalescingOperator.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/NilCoalescingOperator.png -------------------------------------------------------------------------------- /screenshots/ObserverPattern.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/ObserverPattern.png -------------------------------------------------------------------------------- /screenshots/OmittingArgumentLabels.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/OmittingArgumentLabels.png -------------------------------------------------------------------------------- /screenshots/OneSidedRange.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/OneSidedRange.png -------------------------------------------------------------------------------- /screenshots/OneTimeCode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/OneTimeCode.png -------------------------------------------------------------------------------- /screenshots/OperatorOverloading.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/OperatorOverloading.png -------------------------------------------------------------------------------- /screenshots/PassingOperator.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/PassingOperator.png -------------------------------------------------------------------------------- /screenshots/PreservingInitializers.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/PreservingInitializers.png -------------------------------------------------------------------------------- /screenshots/PropertyObservers.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/PropertyObservers.png -------------------------------------------------------------------------------- /screenshots/ProtocolConformance.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/ProtocolConformance.png -------------------------------------------------------------------------------- /screenshots/PublicPrivateSet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/PublicPrivateSet.png -------------------------------------------------------------------------------- /screenshots/QualityOfServiceClasses.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/QualityOfServiceClasses.png -------------------------------------------------------------------------------- /screenshots/RegisterDequeueXIBCollectionView.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/RegisterDequeueXIBCollectionView.png -------------------------------------------------------------------------------- /screenshots/RegisterDequeueXIBTableView.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/RegisterDequeueXIBTableView.png -------------------------------------------------------------------------------- /screenshots/RemoveElementInArray.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/RemoveElementInArray.png -------------------------------------------------------------------------------- /screenshots/RemoveTheSameValueFromTheArray.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/RemoveTheSameValueFromTheArray.png -------------------------------------------------------------------------------- /screenshots/RepeatWhile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/RepeatWhile.png -------------------------------------------------------------------------------- /screenshots/RequiredHeightForLabel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/RequiredHeightForLabel.png -------------------------------------------------------------------------------- /screenshots/ReturnMultipleValues.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/ReturnMultipleValues.png -------------------------------------------------------------------------------- /screenshots/SearchBarTextField.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/SearchBarTextField.png -------------------------------------------------------------------------------- /screenshots/ShowAlertFunction.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/ShowAlertFunction.png -------------------------------------------------------------------------------- /screenshots/ShuffledAndShuffleFunctions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/ShuffledAndShuffleFunctions.png -------------------------------------------------------------------------------- /screenshots/SimpleDefer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/SimpleDefer.png -------------------------------------------------------------------------------- /screenshots/SingletonPattern.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/SingletonPattern.png -------------------------------------------------------------------------------- /screenshots/SketchShadow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/SketchShadow.png -------------------------------------------------------------------------------- /screenshots/SnapKitUsage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/SnapKitUsage.png -------------------------------------------------------------------------------- /screenshots/StaticFactoryMethodsForUILabel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/StaticFactoryMethodsForUILabel.png -------------------------------------------------------------------------------- /screenshots/StaticTypeProperties.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/StaticTypeProperties.png -------------------------------------------------------------------------------- /screenshots/StrategyPattern.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/StrategyPattern.png -------------------------------------------------------------------------------- /screenshots/SumFunction.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/SumFunction.png -------------------------------------------------------------------------------- /screenshots/SwapValues.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/SwapValues.png -------------------------------------------------------------------------------- /screenshots/SwitchRootVCExtension.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/SwitchRootVCExtension.png -------------------------------------------------------------------------------- /screenshots/TernaryOperator.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/TernaryOperator.png -------------------------------------------------------------------------------- /screenshots/TypeMethods.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/TypeMethods.png -------------------------------------------------------------------------------- /screenshots/UIColorConvenienceInit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/UIColorConvenienceInit.png -------------------------------------------------------------------------------- /screenshots/UnaryMinusOperator.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/UnaryMinusOperator.png -------------------------------------------------------------------------------- /screenshots/UrlQueryParameters.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/UrlQueryParameters.png -------------------------------------------------------------------------------- /screenshots/UserInitiatedQoS.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/UserInitiatedQoS.png -------------------------------------------------------------------------------- /screenshots/UserInteractiveQoS.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/UserInteractiveQoS.png -------------------------------------------------------------------------------- /screenshots/UtilityQoS.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/UtilityQoS.png -------------------------------------------------------------------------------- /screenshots/VariadicParameters.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/VariadicParameters.png -------------------------------------------------------------------------------- /screenshots/WordCountFunction.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MobileTipsters/Swift-Daily-Tips/8b8686779dad0a7d8671ec2de53663cb3b16af78/screenshots/WordCountFunction.png -------------------------------------------------------------------------------- /tips.json: -------------------------------------------------------------------------------- 1 | { 2 | "baseUrl": "https://github.com/MobileTipsters/Swift-Daily-Tips/blob/master", 3 | "tips": [ 4 | { 5 | "id": 1, 6 | "date": "1.11.2018", 7 | "title": "Add Subview Extension", 8 | "codeUrl": "/codes/AddSubviewExtension.swift", 9 | "imageUrl": "/screenshots/AddSubviewExtension.png" 10 | }, 11 | { 12 | "id": 2, 13 | "date": "2.11.2018", 14 | "title": "Static Factory Methods for UILabel", 15 | "codeUrl": "/codes/StaticFactoryMethodsForUILabel.swift", 16 | "imageUrl": "/screenshots/StaticFactoryMethodsForUILabel.png" 17 | }, 18 | { 19 | "id": 3, 20 | "date": "3.11.2018", 21 | "title": "UIColor Convenience Init", 22 | "codeUrl": "/codes/UIColorConvenienceInit.swift", 23 | "imageUrl": "/screenshots/UIColorConvenienceInit.png" 24 | }, 25 | { 26 | "id": 4, 27 | "date": "4.11.2018", 28 | "title": "Member Short Hand", 29 | "codeUrl": "/codes/MemberShortHand.swift", 30 | "imageUrl": "/screenshots/MemberShortHand.png" 31 | }, 32 | { 33 | "id": 5, 34 | "date": "5.11.2018", 35 | "title": "Dismiss Keyboard Interactively", 36 | "codeUrl": "/codes/DismissKeyboardInteractively.swift", 37 | "imageUrl": "/screenshots/DismissKeyboardInteractively.png" 38 | }, 39 | { 40 | "id": 6, 41 | "date": "6.11.2018", 42 | "title": "One Time Code #iOS12", 43 | "codeUrl": "/codes/OneTimeCode.swift", 44 | "imageUrl": "/screenshots/OneTimeCode.png" 45 | }, 46 | { 47 | "id": 7, 48 | "date": "7.11.2018", 49 | "title": "Filter Function", 50 | "codeUrl": "/codes/FilterFunction.swift", 51 | "imageUrl": "/screenshots/FilterFunction.png" 52 | }, 53 | { 54 | "id": 8, 55 | "date": "8.11.2018", 56 | "title": "Guard Optional Binding", 57 | "codeUrl": "/codes/GuardOptionalBinding.swift", 58 | "imageUrl": "/screenshots/GuardOptionalBinding.png" 59 | }, 60 | { 61 | "id": 9, 62 | "date": "9.11.2018", 63 | "title": "First Where Function", 64 | "codeUrl": "/codes/FirstWhere.swift", 65 | "imageUrl": "/screenshots/FirstWhere.png" 66 | }, 67 | { 68 | "id": 10, 69 | "date": "10.11.2018", 70 | "title": "AllSatisfy Function", 71 | "codeUrl": "/codes/AllSatisfyFunction.swift", 72 | "imageUrl": "/screenshots/AllSatisfyFunction.png" 73 | }, 74 | { 75 | "id": 11, 76 | "date": "11.11.2018", 77 | "title": "Simple Defer Function", 78 | "codeUrl": "/codes/SimpleDefer.swift", 79 | "imageUrl": "/screenshots/SimpleDefer.png" 80 | }, 81 | { 82 | "id": 12, 83 | "date": "12.11.2018", 84 | "title": "In-out Parameter", 85 | "codeUrl": "/codes/InoutParameter.swift", 86 | "imageUrl": "/screenshots/InoutParameter.png" 87 | }, 88 | { 89 | "id": 13, 90 | "date": "13.11.2018", 91 | "title": "Map Function", 92 | "codeUrl": "/codes/MapFunction.swift", 93 | "imageUrl": "/screenshots/MapFunction.png" 94 | }, 95 | { 96 | "id": 14, 97 | "date": "14.11.2018", 98 | "title": "CompactMap Function", 99 | "codeUrl": "/codes/CompactMapFunction.swift", 100 | "imageUrl": "/screenshots/CompactMapFunction.png" 101 | }, 102 | { 103 | "id": 15, 104 | "date": "15.11.2018", 105 | "title": "Passing Operator", 106 | "codeUrl": "/codes/PassingOperator.swift", 107 | "imageUrl": "/screenshots/PassingOperator.png" 108 | }, 109 | { 110 | "id": 16, 111 | "date": "16.11.2018", 112 | "title": "Element of Operator ∈", 113 | "codeUrl": "/codes/ElementOfOperator.swift", 114 | "imageUrl": "/screenshots/ElementOfOperator.png" 115 | }, 116 | { 117 | "id": 17, 118 | "date": "17.11.2018", 119 | "title": "CaseIterable Protocol", 120 | "codeUrl": "/codes/CaseIterable.swift", 121 | "imageUrl": "/screenshots/CaseIterable.png" 122 | }, 123 | { 124 | "id": 18, 125 | "date": "18.11.2018", 126 | "title": "Shuffled and Shuffle Functions", 127 | "codeUrl": "/codes/ShuffledAndShuffleFunctions.swift", 128 | "imageUrl": "/screenshots/ShuffledAndShuffleFunctions.png" 129 | }, 130 | { 131 | "id": 19, 132 | "date": "19.11.2018", 133 | "title": "Computed Properties", 134 | "codeUrl": "/codes/ComputedProperties.swift", 135 | "imageUrl": "/screenshots/ComputedProperties.png" 136 | }, 137 | { 138 | "id": 20, 139 | "date": "20.11.2018", 140 | "title": "Static Type Properties", 141 | "codeUrl": "/codes/StaticTypeProperties.swift", 142 | "imageUrl": "/screenshots/StaticTypeProperties.png" 143 | }, 144 | { 145 | "id": 21, 146 | "date": "21.11.2018", 147 | "title": "Type Methods", 148 | "codeUrl": "/codes/TypeMethods.swift", 149 | "imageUrl": "/screenshots/TypeMethods.png" 150 | }, 151 | { 152 | "id": 22, 153 | "date": "22.11.2018", 154 | "title": "Default Parameter", 155 | "codeUrl": "/codes/DefaultParameter.swift", 156 | "imageUrl": "/screenshots/DefaultParameter.png" 157 | }, 158 | { 159 | "id": 23, 160 | "date": "23.11.2018", 161 | "title": "Lazy Property", 162 | "codeUrl": "/codes/LazyProperty.swift", 163 | "imageUrl": "/screenshots/LazyProperty.png" 164 | }, 165 | { 166 | "id": 24, 167 | "date": "24.11.2018", 168 | "title": "Discardable Result", 169 | "codeUrl": "/codes/DiscardableResult.swift", 170 | "imageUrl": "/screenshots/DiscardableResult.png" 171 | }, 172 | { 173 | "id": 25, 174 | "date": "25.11.2018", 175 | "title": "Return Multiple Values", 176 | "codeUrl": "/codes/ReturnMultipleValues.swift", 177 | "imageUrl": "/screenshots/ReturnMultipleValues.png" 178 | }, 179 | { 180 | "id": 26, 181 | "date": "26.11.2018", 182 | "title": "Property Observers", 183 | "codeUrl": "/codes/PropertyObservers.swift", 184 | "imageUrl": "/screenshots/PropertyObservers.png" 185 | }, 186 | { 187 | "id": 27, 188 | "date": "27.11.2018", 189 | "title": "Public Private(set)", 190 | "codeUrl": "/codes/PublicPrivateSet.swift", 191 | "imageUrl": "/screenshots/PublicPrivateSet.png" 192 | }, 193 | { 194 | "id": 28, 195 | "date": "28.11.2018", 196 | "title": "Ternary Operator", 197 | "codeUrl": "/codes/TernaryOperator.swift", 198 | "imageUrl": "/screenshots/TernaryOperator.png" 199 | }, 200 | { 201 | "id": 29, 202 | "date": "29.11.2018", 203 | "title": "Nil-Coalescing Operator", 204 | "codeUrl": "/codes/NilCoalescingOperator.swift", 205 | "imageUrl": "/screenshots/NilCoalescingOperator.png" 206 | }, 207 | { 208 | "id": 30, 209 | "date": "30.11.2018", 210 | "title": "Join & Split Function", 211 | "codeUrl": "/codes/Join&SplitFunction.swift", 212 | "imageUrl": "/screenshots/Join&SplitFunction.png" 213 | }, 214 | { 215 | "id": 31, 216 | "date": "1.12.2018", 217 | "title": "Generic Functions", 218 | "codeUrl": "/codes/GenericFunctions.swift", 219 | "imageUrl": "/screenshots/GenericFunctions.png" 220 | }, 221 | { 222 | "id": 32, 223 | "date": "2.12.2018", 224 | "title": "Return Multiple Values", 225 | "codeUrl": "/codes/ReturnMultipleValues.swift", 226 | "imageUrl": "/screenshots/ReturnMultipleValues.png" 227 | }, 228 | { 229 | "id": 33, 230 | "date": "3.12.2018", 231 | "title": "Swap Values", 232 | "codeUrl": "/codes/SwapValues.swift", 233 | "imageUrl": "/screenshots/SwapValues.png" 234 | }, 235 | { 236 | "id": 34, 237 | "date": "4.12.2018", 238 | "title": "Builder Pattern", 239 | "codeUrl": "/codes/BuilderPattern.swift", 240 | "imageUrl": "/screenshots/BuilderPattern.png" 241 | }, 242 | { 243 | "id": 35, 244 | "date": "5.12.2018", 245 | "title": "Multiline String Literals", 246 | "codeUrl": "/codes/MultilineStringLiterals.swift", 247 | "imageUrl": "/screenshots/MultilineStringLiterals.png" 248 | }, 249 | { 250 | "id": 36, 251 | "date": "6.12.2018", 252 | "title": "Repeat While", 253 | "codeUrl": "/codes/RepeatWhile.swift", 254 | "imageUrl": "/screenshots/RepeatWhile.png" 255 | }, 256 | { 257 | "id": 37, 258 | "date": "7.12.2018", 259 | "title": "Function Argument Labels", 260 | "codeUrl": "/codes/FunctionArgumentLabels.swift", 261 | "imageUrl": "/screenshots/FunctionArgumentLabels.png" 262 | }, 263 | { 264 | "id": 38, 265 | "date": "8.12.2018", 266 | "title": "Omitting Argument Labels", 267 | "codeUrl": "/codes/OmittingArgumentLabels.swift", 268 | "imageUrl": "/screenshots/OmittingArgumentLabels.png" 269 | }, 270 | { 271 | "id": 39, 272 | "date": "9.12.2018", 273 | "title": "Variadic Parameters", 274 | "codeUrl": "/codes/VariadicParameters.swift", 275 | "imageUrl": "/screenshots/VariadicParameters.png" 276 | }, 277 | { 278 | "id": 40, 279 | "date": "10.12.2018", 280 | "title": "Closed Range Operator", 281 | "codeUrl": "/codes/ClosedRangeOperator.swift", 282 | "imageUrl": "/screenshots/ClosedRangeOperator.png" 283 | }, 284 | { 285 | "id": 41, 286 | "date": "11.12.2018", 287 | "title": "Half-Open Range Operator", 288 | "codeUrl": "/codes/HalfOpenRangeOperator.swift", 289 | "imageUrl": "/screenshots/HalfOpenRangeOperator.png" 290 | }, 291 | { 292 | "id": 42, 293 | "date": "12.12.2018", 294 | "title": "One-Sided Range", 295 | "codeUrl": "/codes/OneSidedRange.swift", 296 | "imageUrl": "/screenshots/OneSidedRange.png" 297 | } 298 | ] 299 | } 300 | --------------------------------------------------------------------------------