awesome-ios-developer/README.md

2782 lines
85 KiB
Markdown
Raw Normal View History

2022-05-05 10:23:55 +07:00
# Awesome iOS Developer [![Join the chat at https://gitter.im/awesome-ios-developer/community](https://badges.gitter.im/awesome-ios-developer/community.svg)](https://gitter.im/awesome-ios-developer/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
2021-04-10 15:42:23 +07:00
2022-02-02 00:48:59 +07:00
<p>
2022-07-29 09:51:59 +07:00
2022-05-27 08:48:34 +07:00
2022-03-25 11:19:54 +07:00
<!--
2022-04-30 12:17:26 +07:00
2022-07-13 12:45:25 +07:00
2022-03-25 11:19:54 +07:00
%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%UPDATE LIST%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%
2022-03-20 05:45:12 +07:00
git useful
2022-03-20 05:45:12 +07:00
https://www.gitkraken.com/ -> similar with git tower
https://www.git-tower.com/mac -> observe filehistory
https://kaleidoscope.app -> diff file manager
reduce build time when TDD
line 1819
add more description
add more description about router service pattern
2022-03-25 11:19:54 +07:00
add TCA description
2022-03-27 09:56:58 +07:00
2022-06-15 10:05:32 +07:00
add domain pattern(layer) + robot testing in ios
2022-03-29 23:47:38 +07:00
add dependency inversion
2022-04-02 11:07:21 +07:00
2022-04-04 11:10:00 +07:00
+
2022-04-02 11:07:21 +07:00
2022-05-04 09:15:44 +07:00
add service locator + dependency container
2022-04-02 11:07:21 +07:00
2022-04-06 10:58:49 +07:00
add description about coordinator pattern
2022-04-11 09:11:49 +07:00
2022-04-14 12:31:00 +07:00
add modular architecture
2022-04-14 12:37:49 +07:00
add description for tuist template
2022-04-15 16:08:07 +07:00
2022-04-19 09:12:52 +07:00
add useful debugging in XCode(Youtube iOS)
+ need to add more with pic
2022-04-30 11:40:05 +07:00
2022-05-08 08:43:27 +07:00
using fastlane + periphery
2022-05-20 04:16:13 +07:00
dependency container
2022-05-23 05:23:57 +07:00
AR Kit add
2022-06-03 09:29:47 +07:00
add book for debugging( ray wenderlich)
2022-06-19 11:50:10 +07:00
2022-06-23 11:57:34 +07:00
add service locator pattern
2022-07-19 12:25:36 +07:00
composition layer
-sil option for optimization build for swift compile
2022-06-23 11:57:34 +07:00
2022-08-02 10:01:25 +07:00
SwiftGen - auto generate string & asset enum opensource
2022-08-12 10:45:03 +07:00
apple developer tutorial video link update
2022-03-20 05:45:12 +07:00
-->
2022-05-05 10:21:58 +07:00
<p align="center">
2021-06-16 11:42:34 +07:00
<img alt="awesome" src="https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg" />
2021-07-05 14:46:55 +07:00
<a href="https://hits.seeyoufarm.com">
<img src="https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2Fjphong1111%2FUseful_Swift&count_bg=%2379C83D&title_bg=%23555555&icon=&icon_color=%23E7E7E7&title=hits&edge_flat=true"/>
2022-05-05 10:14:38 +07:00
</a>
2022-05-05 10:19:33 +07:00
2021-07-05 14:42:56 +07:00
</p>
2021-05-25 17:49:54 +07:00
2021-07-05 06:12:00 +07:00
2021-05-27 10:59:42 +07:00
<p align="center">
2022-05-06 10:44:26 +07:00
🌟Feel free to contribute this Repository!!🌟
2021-05-27 10:59:42 +07:00
</p>
2021-05-24 10:35:26 +07:00
2021-05-27 10:59:42 +07:00
## 🔎 Content
2021-05-23 11:34:45 +07:00
- [Coding Convention](#Coding-convention)
2021-05-05 15:26:00 +07:00
- [Swift Lint](#Swift-lint)
2021-10-08 14:47:38 +07:00
- [App Life Cycle](#app-life-cycle)
2024-05-23 11:58:54 +07:00
- [ViewController Life Cycle](#viewcontroller-life-cycle)
2021-04-10 16:05:27 +07:00
- [Design Pattern](#Design-Pattern)
- [Adaptor](#Adaptor)
2021-11-04 22:56:35 +07:00
- [Coordinator](#Coordinator)
2021-05-24 03:31:51 +07:00
- [Delegation](#Delegation)
2021-06-23 17:37:35 +07:00
- [Dependency Injection](#Dependency-Injection)
- [Factory](#Factory)
2021-05-24 03:31:51 +07:00
- [Observer](#Observer)
2021-05-28 04:07:58 +07:00
- [KVO](#KVO)
- [KVC](#KVC)
- [Singleton](#Singleton)
2021-05-24 13:50:36 +07:00
- [Code Structuring](#code-structuringarchitecture)
2021-04-10 16:20:15 +07:00
- [MVC](#MVC)
- [MVP](#MVP)
2021-04-10 16:20:15 +07:00
- [MVVM](#MVVM)
2021-04-27 11:39:33 +07:00
- [VIPER](#VIPER)
2022-08-28 04:06:56 +07:00
- [The Composable Architecture(TCA)](#The-Composable-Architecture)
- [Reducer](#Reducer)
- [Repository Pattern](#Repository-Pattern)
2021-04-10 04:19:52 +07:00
- [UIDesign](#UIDesign)
2021-06-24 15:28:30 +07:00
- [HIG](#highuman-interface-guidelines)
2021-07-31 12:59:43 +07:00
- [SwiftUI](#SwiftUI)
2021-09-06 12:21:33 +07:00
- [Useful Cheat Sheet for SwiftUI](#Useful-Cheat-Sheet-for-SwiftUI)
2021-05-27 10:45:26 +07:00
- [UIdesign Inspiration](#UIdesign-Inspiration)
2021-05-27 10:45:53 +07:00
- [Vector Graphic Editors](#Vector-Graphic-Editors)
2021-05-27 10:45:26 +07:00
- [Design Collaboration](#Design-Collaboration)
- [Design Tools](#Design-Tools)
2021-10-02 03:25:11 +07:00
- [Useful Sites](#useful-sites)
2023-04-30 14:59:55 +07:00
- [Bundle](#Bundle)
- [Static Library](#static-library)
- [Dynamic Library](#dynamic-library)
2023-04-30 15:01:22 +07:00
- [xcframework](#xcframework)
2021-09-28 12:22:47 +07:00
- [Screen Layout Programmatically](#screen-layout-programmatically)
2021-04-22 17:06:56 +07:00
- [Helper](#Helper)
2021-05-03 14:35:24 +07:00
- [Email, Message, Call](#email-message-call)
2021-05-03 13:57:35 +07:00
- [Network Layer](#Network-Layer)
2021-05-03 16:50:11 +07:00
- [Image Picker](#Image-Picker)
2021-05-03 18:21:44 +07:00
- [File Manager](#File-Manager)
- [Video Downloader](#Video-Downloader)
2021-05-20 10:50:21 +07:00
- [Image Downloader](#Image-Downloader)
2021-05-03 19:09:09 +07:00
- [Location Manager](#Location-Manager)
2021-09-22 22:36:18 +07:00
- [Local Notification Manager](#local-notification-manager)
2021-08-04 02:24:46 +07:00
- [API](#API)
2021-04-10 15:55:09 +07:00
- [JSON](#JSON)
2021-05-27 10:45:26 +07:00
- [JSONDecoder](#JSONDecoder)
- [JSONSerialization](#JSONSerialization)
2021-09-02 13:05:16 +07:00
- [NotificationCenter](#NotificationCenter)
2021-05-23 11:39:07 +07:00
- [UserDefaults](#UserDefaults)
2021-05-22 01:00:30 +07:00
- [How to find documentDirectory](#How-to-find-documentDirectory)
2021-06-03 03:36:08 +07:00
- [Store Object](#Store-Object)
2021-05-22 00:55:41 +07:00
- [Core Data](#Core-Data)
2021-06-18 10:41:04 +07:00
- [Core Data Stack](#Core-Data-Stack)
2021-06-27 18:23:58 +07:00
- [Set Up Core Data](#Set-Up-Core-Data)
2021-05-30 14:39:10 +07:00
- [Core Data Usage](#Core-Data-Usage)
2021-06-30 09:19:28 +07:00
- [Codegen](#codegen)
- [Entities](#Entities)
- [Attributes](#Attributes)
- [Relationships](#Relationships)
- [Delete Rules](#Delete-Rules)
2021-05-25 01:01:12 +07:00
- [Store Data](#Store-Data)
2021-05-25 03:02:19 +07:00
- [Load Data](#Load-Data)
2021-05-25 04:14:07 +07:00
- [Update Data](#Update-Data)
- [Delete Data](#Delete-Data)
2021-07-23 01:03:30 +07:00
- [Core Bluetooth](#Core-Bluetooth)
2021-04-10 04:30:48 +07:00
- [Third Party Library](#Third-Party-Library)
2021-05-30 06:00:21 +07:00
- [Dependency/Package Manager](#Dependency/Package-Manager)
2021-05-29 03:15:35 +07:00
- [CocoaPods](#CocoaPods)
- [Carthage](#Carthage)
- [Swift Package Manager](#Swift-Package-Manager)
2021-05-27 10:45:53 +07:00
- [Recommend Library](#Recommend-Library)
2021-06-11 23:12:06 +07:00
- [Localization](#Localization)
- [Usage](#Localization-Usage)
2021-06-12 02:26:13 +07:00
- [Useful for Localization](#Useful-for-Localization)
2021-06-14 09:42:58 +07:00
- [Accessibility](#Accessibility)
2021-06-14 22:48:36 +07:00
- [USage](#Accessibility-Usage)
2021-04-29 11:42:01 +07:00
- [GCD](#GCD)
2021-04-30 13:40:48 +07:00
- [DispatchQueue](#DispatchQueue)
2021-07-02 15:41:22 +07:00
- [Thread Safety](#thread-safety)
2021-04-30 13:40:48 +07:00
- [DispatchGroup](#DispatchGroup)
- [DispatchWorkItem](#DispatchWorkItem)
2021-07-07 11:09:49 +07:00
- [Operation](#operation)
2021-06-21 09:56:56 +07:00
- [OperationQueue](#operationQueue)
2021-07-07 11:09:49 +07:00
- [Thread Sanitizer](#Thread-Sanitizer)
2021-05-07 15:10:24 +07:00
- [Testing](#Testing)
2022-03-15 10:23:07 +07:00
- [Five Factor Testing](#Five-Factor-Testing)
2021-08-13 09:15:25 +07:00
- [Test Double](#Test-Double)
2022-04-20 11:13:38 +07:00
- [Useful Debugging Technique](#Useful-Debugging-Technique)
2021-06-24 15:29:09 +07:00
- [TDD](#TDD)
- [Reduce Build Time](#Reduce-Build-Time)
2022-04-24 13:32:11 +07:00
- [Check build time in Xcode](#Check-build-time-in-Xcode)
2021-06-24 15:29:09 +07:00
- [BDD](#BDD)
2021-05-14 17:33:02 +07:00
- [Code Coverage](#Code-Coverage)
2021-07-19 09:48:04 +07:00
- [Integration Testing](#Integration-Testing)
- [Unit Testing](#Unit-Testing)
- [UI Testing](#UI-Testing)
- [Robot Testing](#Robot-Testing)
2021-09-23 22:50:09 +07:00
- [Snapshot Testing](#snapshot-testing)
2021-08-25 05:01:43 +07:00
- [TestFlight](#testflight)
2021-06-09 00:30:11 +07:00
- [CI/CD](#cicd)
2022-02-17 12:23:17 +07:00
- [Fastlane](#Fastlane)
2021-07-16 14:38:06 +07:00
- [Jenkins](#Jenkins)
2021-07-29 01:17:12 +07:00
- [Jira](#Jira)
2021-08-06 01:56:00 +07:00
- [CircleCI](#CircleCI)
- [Codemagic](#Codemagic)
2021-08-30 09:47:10 +07:00
- [Xcode Cloud](#xcode-cloud)
2023-04-26 01:29:57 +07:00
- [Swift DocC](#swift-DocC)
2022-02-17 12:38:58 +07:00
- [Tuist](#Tuist)
2021-05-25 03:02:19 +07:00
- [In App Purchase(IAP)](#In-App-PurchaseIAP)
2021-06-11 04:20:45 +07:00
- [Notification](#Notification)
- [Local Notification](#Local-Notification)
- [Remote Notification](#Remote-Notification)
- [APNs](#APNS)
- [Set Up APNs](#Set-Up-APNs)
- [APNs Usage](#APNs-Usage)
2021-05-21 10:55:16 +07:00
- [FRP](#FRP)
2021-05-28 12:45:01 +07:00
- [Rxswift](#Rxswift)
- [Combine](#Combine)
2021-08-06 01:56:00 +07:00
- [RxCombine](#Rxcombine)
2021-06-04 02:35:13 +07:00
- [Security](#Security)
- [Checklist For App Security](#Checklist-For-App-Security)
- [Keychain](#Keychain)
2021-06-04 02:42:38 +07:00
- [SSL Pinning](#SSL-Pinning)
2021-06-04 02:44:25 +07:00
- [Code Obfuscation](#Code-Obfuscation)
2021-06-04 02:42:38 +07:00
- [Cryptography](#Cryptography)
- [Biometric Access](#Biometric-Access)
2021-06-08 03:09:04 +07:00
- [Face ID & Touch ID](#face-id--touch-id)
2021-07-09 14:01:18 +07:00
- [Objective-C](#Objective-C)
- [Bridging Header](#Bridging-Header)
2021-05-24 03:37:34 +07:00
- [Error Search](#Error-Search)
2021-04-23 14:19:47 +07:00
- [Useful Stuff](#Useful-Stuff)
- [Useful Blogs for iOS Developers](#Useful-Blogs-for-iOS-Developers)
2021-06-01 08:54:36 +07:00
- [How to submit your app to the AppStore](#how-to-submit-your-app-to-the-appstore)
2021-10-13 00:22:06 +07:00
- [iOS Version Adoption Tracker](#iOS-version-adoption-tracker)
2021-06-12 13:05:53 +07:00
- [Online Swift Playground](#Online-Swift-Playground)
2021-04-23 23:34:04 +07:00
- [Show Preview in UIKit(Build UI with Code Base)](#show-preview-in-uikitbuild-ui-with-code-base-----)
2021-06-02 00:25:46 +07:00
- [Compare Changes in Swift Version](#Compare-Changes-in-Swift-Version)
2021-05-28 08:37:37 +07:00
- [Managing Xcode Space](#Managing-Xcode-Space)
2021-05-21 10:55:16 +07:00
- [Roadmap for iOS Developer](#Roadmap-for-iOS-Developer)
2021-06-13 03:13:08 +07:00
- [Vim in Xcode](#use-vim-in-xcode)
- [Write README.md](#write-readmemd)
2021-04-10 03:16:44 +07:00
2021-04-10 03:25:46 +07:00
2021-04-10 04:13:06 +07:00
## Coding convention
2021-04-10 15:22:54 +07:00
set of guidelines for a specific programming language that recommend programming style
### Swift Style Guide
2021-04-10 04:12:26 +07:00
2021-04-10 14:51:46 +07:00
- [Swift Style Guide](https://github.com/linkedin/swift-style-guide)
2021-04-10 04:34:45 +07:00
### Swift Lint
2021-04-10 15:20:40 +07:00
The way of force you to adapt coding convention
>otherwise project build will **FAILED**
2021-04-10 15:14:13 +07:00
- [Swift Lint](https://github.com/realm/SwiftLint) apply for all project:+1:
2021-04-15 19:36:44 +07:00
```swift
2021-04-15 19:36:01 +07:00
if which swiftlint >/dev/null; then
swiftlint
else
echo "error: SwiftLint not installed, download from https://github.com/realm/SwiftLint"
exit 1
fi
```
2021-04-10 04:34:45 +07:00
put .yml file into root folder and apply following code in Build Phases
2021-04-10 03:47:49 +07:00
2021-04-22 17:19:49 +07:00
**You can modify(delete) SwiftLint Option with opening .yml file**
2021-04-22 17:20:10 +07:00
2021-04-22 17:21:49 +07:00
> Shift + Command + . will show the hidden file
2021-04-22 17:19:49 +07:00
<img src="https://github.com/jphong1111/Useful_Swift/blob/main/Images/swiftLintChange.png">
2021-08-14 12:29:07 +07:00
📚📚 Recommend Book 📚📚
2021-08-20 22:29:35 +07:00
| Book Name | Authors Name |
2021-08-20 22:30:47 +07:00
| :----------- | :----------- |
| Clean Code: A Handbook of Agile Software Craftsmanship | Robert C. Martin |
2021-09-05 22:26:33 +07:00
| The Pragmatic Programmer Your Journey to Mastery, 20th Anniversary Edition| Andrew Hunt David Hurst Thomas |
2021-08-14 12:29:07 +07:00
2021-10-10 02:36:27 +07:00
## App Life Cycle
[iOS App Life Cycle](https://medium.com/@neroxiao/ios-app-life-cycle-ec1b31cee9dc)
2021-10-11 05:13:50 +07:00
<p align="right">
<a href="#-content">Back to Content</a>
</p>
2021-10-10 02:36:27 +07:00
2024-05-23 11:57:08 +07:00
## ViewController Life Cycle
2021-10-10 02:36:27 +07:00
2021-10-21 21:01:37 +07:00
<img src = "https://github.com/jphong1111/awesome-ios-developer/blob/main/Images/iOSViewLifeCycle.png" width="70%" height="70%"/>
2021-10-21 21:00:44 +07:00
2021-10-11 21:52:25 +07:00
- viewDidLoad
- viewWillAppear
- viewWillLayoutSubviews
- viewDidLayoutSubviews
- viewDidAppear
- viewWillDisappear
- viewDidDisappear
2021-10-11 05:13:50 +07:00
[iOS View Controller Life Cycle](https://medium.com/good-morning-swift/ios-view-controller-life-cycle-2a0f02e74ff5)
2021-10-10 02:36:27 +07:00
2021-10-11 05:13:50 +07:00
<p align="right">
<a href="#-content">Back to Content</a>
</p>
2021-10-10 02:36:27 +07:00
2021-08-14 12:29:07 +07:00
2021-04-10 16:11:11 +07:00
## Design Pattern
2021-04-14 04:01:22 +07:00
2021-04-14 04:00:57 +07:00
Check [this](https://refactoring.guru/design-patterns/swift) website for design pattern in Swift
2021-04-10 16:11:11 +07:00
## Adaptor
2021-07-20 10:07:59 +07:00
Adapter pattern is a structural design pattern that is useful for composing classes and objects into a larger system.
```swift
protocol Target {
func request()
}
class Adaptee {
func specificRequest() {}
}
class Adapter: Target {
let adaptee: Adaptee
init(adaptee: Adaptee) {
self.adaptee = adaptee
}
func request() {
adaptee.specificRequest()
}
}
```
- [Adapter Pattern in Swift](https://levelup.gitconnected.com/adapter-pattern-in-swift-b6403cfa0a78)
- [Swift adapter design pattern](https://theswiftdev.com/swift-adapter-design-pattern/)
- [Adapter in Swift](https://refactoring.guru/design-patterns/adapter/swift/example)
2021-11-04 22:56:35 +07:00
## Coordinator
2021-11-26 01:45:20 +07:00
- [Leverage the Coordinator Design Pattern in Swift 5](https://betterprogramming.pub/leverage-the-coordinator-design-pattern-in-swift-5-cd5bb9e78e12)
2021-11-04 22:56:35 +07:00
2021-05-28 04:07:58 +07:00
## Delegation
2021-04-10 16:11:11 +07:00
2021-07-21 09:31:56 +07:00
Delegation is a design pattern that enables a class to hand off (or “delegate”) some of its responsibilities to an instance of another class.
### Example
Create a protocol
```swift
2021-07-21 09:33:57 +07:00
protocol SomeProtocol: AnyObject {
2021-07-21 09:31:56 +07:00
func reload()
}
```
Create a delegate
2021-04-10 16:30:44 +07:00
```swift
2021-04-10 16:11:11 +07:00
weak var delegate: SomeProtocol?
```
2021-07-21 09:31:56 +07:00
2021-07-21 09:33:57 +07:00
You can check the code using delegation pattern [here](https://github.com/jphong1111/Unsplash_Clone/blob/main/Unsplah_Clone/Module/MainMenu/AccountScreenModule/ViewModel/AccountViewModel.swift#L35)
2021-07-21 09:31:56 +07:00
- [Delegation in Swift Swift by Sundell](https://www.swiftbysundell.com/articles/delegation-in-swift/)
- [Delegation in Swift Explained](https://learnappmaking.com/delegation-swift-how-to/)
- [Delegation Pattern in Swift 5.1](https://medium.com/@nimjea/delegation-pattern-in-swift-4-2-f6aca61f4bf5)
2021-06-23 17:37:35 +07:00
## Dependency Injection
2021-06-23 17:52:47 +07:00
Dependency injection is a pattern that can be used to eliminate the need for singletons in a project
1. Raise Transparency
2. Improve Testability
### Type of Dependency Injection
2021-06-23 17:53:45 +07:00
**1. initializer injection**
2021-06-23 17:52:47 +07:00
``` swift
class DataManager {
private let serializer: Serializer
init(serializer: Serializer) {
self.serializer = serializer
}
}
```
2021-06-23 17:53:45 +07:00
**2. property injection**
2021-06-23 17:52:47 +07:00
```swift
import UIKit
class ViewController: UIViewController {
var requestManager: RequestManager?
}
```
2021-06-23 17:53:45 +07:00
**3. method injection**
2021-06-23 17:52:47 +07:00
```swift
import Foundation
class DataManager {
func serializeRequest(request: Request, withSerializer serializer: Serializer) -> Data? {
...
}
}
```
2021-06-23 17:37:35 +07:00
[Nuts and Bolts of Dependency Injection in Swift](https://cocoacasts.com/nuts-and-bolts-of-dependency-injection-in-swift)
2021-04-10 16:11:11 +07:00
## Factory
2021-04-14 04:02:14 +07:00
2021-07-05 14:34:07 +07:00
Factory method is a creational design pattern which solves the problem of creating product objects without specifying their concrete classes.
- [Factory Method in Swift](https://refactoring.guru/design-patterns/factory-method/swift/example)
- [The Factory Pattern using Swift](https://stevenpcurtis.medium.com/the-factory-pattern-using-swift-b534ae9f983f)
2021-05-28 04:07:58 +07:00
## Observer
2021-04-14 04:02:14 +07:00
2021-05-28 11:21:11 +07:00
Observer is a behavioral design pattern that allows some objects to notify other objects about changes in their state.
- Observer - An object that wishes to be notified when the state of another object changes.
- Subject (Observable) - An object that maintains a list of observers, and inform them of state changes usually by calling one of their methods. An observable slightly differs in this in that it is just a function that sets up an observation.
- Subscribe - An observer lets a subject know that it wants to be informed of changes through a process called subscribing.
<img src = "https://github.com/jphong1111/Useful_Swift/blob/main/Images/observer.png" />
Check following sites
- [swiftbysundell](https://www.swiftbysundell.com/articles/observers-in-swift-part-1/)
2021-05-27 23:49:07 +07:00
2021-05-27 23:37:31 +07:00
TBD
2021-05-06 20:56:57 +07:00
2021-07-30 15:45:09 +07:00
### KVO
2021-05-28 04:07:58 +07:00
2021-07-30 04:44:52 +07:00
KVO stands for Key Value Observing
- [Apple Developer Site](https://developer.apple.com/documentation/swift/cocoa_design_patterns/using_key-value_observing_in_swift)
- [KVO (Key Value Observing) in Swift](https://medium.com/@abhishek1nacc/kvo-key-value-observing-in-swift-65d05ac2d240)
2021-05-28 11:21:11 +07:00
2021-07-30 15:45:09 +07:00
### KVC
2021-05-28 04:07:58 +07:00
2021-05-30 06:00:21 +07:00
[KVO vs KVC](https://medium.com/hackernoon/kvo-kvc-in-swift-12f77300c387)
2021-06-29 00:18:41 +07:00
We are using KVC in Storyboard!
2021-11-02 22:41:17 +07:00
<p align="right">
<a href="#-content">Back to Content</a>
</p>
## Singleton
2021-06-23 17:37:35 +07:00
singleton pattern is to ensure only one instance of a class is alive at any one time.
```swift
class SingletonPattern {
static let manager = SingletonPattern()
private init() {}
}
```
2021-08-17 05:34:52 +07:00
<p align="right">
<a href="#-content">Back to Content</a>
</p>
2023-04-26 01:28:31 +07:00
## Swift DocC
Swift-DocC is a documentation compiler for Swift frameworks and packages aimed at making it easy to write and publish great developer documentation.
Simple goes to Product-Build Documentation and DocC will open
2023-04-26 01:29:15 +07:00
- [Swift DocC Apple Github](https://github.com/apple/swift-docc)
- [DocC Tutorial for Swift : Getting Started](https://www.kodeco.com/34919511-docc-tutorial-for-swift-getting-started)
2021-08-17 05:34:52 +07:00
2021-05-24 13:48:45 +07:00
## Code Structuring(Architecture)
2021-04-10 16:05:27 +07:00
2021-08-20 22:39:32 +07:00
📚📚 Recommend Book 📚📚
| Book Name | Authors Name |
| :----------- | :----------- |
| Advanced iOS App Architecture : Real-world app architecture in Swift | raywenderlich Tutorial Team |
| Clean Architecture: A Craftsman's Guide to Software Structure and Design | Robert Martin |
2021-08-20 22:39:32 +07:00
2022-03-26 11:28:37 +07:00
## Clean Architecture
<img src="https://github.com/jphong1111/Useful_Swift/blob/main/Images/Clean_Architecture.png">
[Clean Architecture](https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html)
2021-08-11 23:57:50 +07:00
## MVC
2021-04-10 16:05:27 +07:00
2021-05-24 13:48:45 +07:00
MVC pattern stands for Model - View - Controller
2021-04-15 10:00:46 +07:00
<img src="https://github.com/jphong1111/Useful_Swift/blob/main/Images/MVCModel.png">
2021-04-13 13:33:49 +07:00
2021-05-24 13:48:45 +07:00
- Model - Model take care of storing data.
- View - View renders the data for users
- Controller - Controller modifies the View, accepts user input and interacts directly with the Model. And take care of view logic and business logic.
2021-08-11 23:57:50 +07:00
## MVP
2021-08-12 00:01:03 +07:00
<img src ="https://github.com/jphong1111/awesome-ios-developer/blob/main/Images/MVPdesign.png" />
2021-08-11 23:57:50 +07:00
## MVVM
2021-04-10 16:20:15 +07:00
2021-05-24 13:48:45 +07:00
MVVM patterns stand for Model - View - ViewModel
2021-08-11 23:57:50 +07:00
### MVC vs MVVM
2021-04-15 10:00:46 +07:00
2021-05-24 13:48:45 +07:00
<img src="https://github.com/jphong1111/Useful_Swift/blob/main/Images/MVVMvsMVC.png" width = "60%" height = "60%">
2021-04-15 10:00:46 +07:00
2021-05-24 13:52:46 +07:00
- Model Which holds the application data
2021-04-19 15:39:24 +07:00
2021-05-24 13:52:46 +07:00
- View It displays the data that is stored in model. These are visual elements through which a user interacts. These are subclasses of UIView
2021-04-19 15:39:24 +07:00
2021-05-24 13:52:46 +07:00
- View Model Transform model information/data and it interacts with controller or view to display those informations.
2021-04-19 15:39:24 +07:00
2021-05-24 13:52:46 +07:00
- Controller class It will be there but the responsibility of view business logic has been removed and give to view model
2021-04-19 15:39:24 +07:00
2021-05-24 13:48:45 +07:00
> You can check App example of using MVVM [here](https://github.com/jphong1111/Unsplash_Clone)
2021-04-19 15:39:24 +07:00
2021-08-11 23:57:50 +07:00
## VIPER
2021-05-24 13:50:36 +07:00
<img src="https://github.com/jphong1111/Useful_Swift/blob/main/Images/Viper.png">
2021-05-24 13:48:45 +07:00
- View - Displays what it is told to by the Presenter and relays user input back to the Presenter.
- Interactor - Contains the business logic as specified by a use case.
- Presenter - contains view logic for preparing content for display (as received from the Interactor) and for reacting to user inputs (by requesting new data from the Interactor).
- Entity - contains basic model objects used by the Interactor.
- Routing - contains navigation logic for describing which screens are shown in which order.
2021-07-26 12:55:16 +07:00
[Getting Started with the VIPER Architecture Pattern](https://www.raywenderlich.com/8440907-getting-started-with-the-viper-architecture-pattern)
2021-05-24 13:52:46 +07:00
2022-08-28 04:06:56 +07:00
# The Composable Architecture
2021-08-11 23:57:50 +07:00
2022-08-28 04:06:56 +07:00
The Composable Architecture is a library for building applications in a consistent and understandable way, with composition, testing, and ergonomics in mind
2021-08-11 23:57:50 +07:00
<img src="https://github.com/jphong1111/Useful_Swift/blob/main/Images/SCA.png">
2021-08-11 23:57:50 +07:00
- [Composable Architecture @ Point Free](https://www.pointfree.co/collections/composable-architecture)
- [The Composable Architecture GitHub](https://github.com/pointfreeco/swift-composable-architecture)
- [The Composable Architecture — One of the Best-Suited Architectures for SwiftUI](https://medium.com/swlh/the-composable-architecture-one-of-the-best-suited-architectures-for-swiftui-35bfc5102b83)
2022-08-28 04:06:56 +07:00
2021-08-11 23:57:50 +07:00
```swift
// example will update here
```
2022-08-28 04:06:56 +07:00
## Reducer
A reducer describes how to evolve the current state of an application to the next state, given an action, and describes what Effects should be executed later by the store, if any.
- [Reducer in TCA](https://pointfreeco.github.io/swift-composable-architecture/Reducer/)
2021-08-11 23:57:50 +07:00
2021-09-03 22:27:43 +07:00
<p align="right">
2021-08-17 05:34:52 +07:00
<a href="#-content">Back to Content</a>
</p>
2021-08-11 23:57:50 +07:00
## Repository Pattern
2022-03-14 06:42:48 +07:00
[The Repository and Unit of Work Patterns](https://docs.microsoft.com/en-us/aspnet/mvc/overview/older-versions/getting-started-with-ef-5-using-mvc-4/implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-application)
2021-08-11 23:57:50 +07:00
2021-04-10 04:13:06 +07:00
## UIDesign
2021-04-10 03:58:50 +07:00
2021-09-06 12:21:33 +07:00
## HIG(Human Interface Guidelines)
- [HIG](https://developer.apple.com/design/human-interface-guidelines/)
2021-04-10 14:51:46 +07:00
- [Apple UI Kit](https://developer.apple.com/documentation/uikit)
2021-05-03 10:58:56 +07:00
- [iOS Design Guide](https://ivomynttinen.com/blog/ios-design-guidelines)
2021-04-10 04:16:24 +07:00
2021-07-31 12:59:43 +07:00
## SwiftUI
SwiftUI is a user interface toolkit that lets us design apps in a **declarative way(Declarative syntax)**.
2021-09-06 12:21:33 +07:00
## Useful Cheat Sheet for SwiftUI
2021-07-31 12:59:43 +07:00
- [Fucking SwiftUI](https://fuckingswiftui.com/) Cheat Sheet for SwiftUI
- [Gosh Darn SwiftUI](https://goshdarnswiftui.com/) Cheat Sheet for SwiftUI
2021-08-02 08:39:52 +07:00
- [SimpleBoilerplates/SwiftUI-Cheat-Sheet](https://github.com/SimpleBoilerplates/SwiftUI-Cheat-Sheet)
2021-07-31 12:59:43 +07:00
TBA
2021-08-17 05:34:52 +07:00
<p align="right">
<a href="#-content">Back to Content</a>
</p>
2021-07-31 12:59:43 +07:00
2021-07-31 13:00:18 +07:00
## iOS icon
2021-05-24 14:01:26 +07:00
- [SF Symbols](https://developer.apple.com/sf-symbols/) Download SF Symbols2 for more icons!
2021-05-05 17:35:44 +07:00
- [icon8](https://icons8.com/) You can download icons imge for your **APP**
2021-05-05 17:36:18 +07:00
- [appicon](https://appicon.co/) generate the app icon size
2021-08-23 11:36:35 +07:00
- [flaticon](www.flaticon.com) Free icons download
2021-04-10 03:58:50 +07:00
2021-07-31 13:00:18 +07:00
## UIdesign Inspiration
2021-04-10 03:58:50 +07:00
2021-05-26 23:52:39 +07:00
- [Dribble](https://dribbble.com/)
- [Pinterest](https://pinterest.com/)
- [Behance](https://www.behance.net/)
2022-04-13 10:13:06 +07:00
- [Pttrns](https://pttrns.com/)👍
2021-05-26 23:52:39 +07:00
- [Awwwards](https://www.awwwards.com/)
- [Flickr](http://www.flickr.com/)
2022-04-13 10:13:06 +07:00
- [Mobbin](https://mobbin.design/dictionary)👍
2021-04-10 04:33:17 +07:00
2021-07-31 13:00:18 +07:00
## Vector Graphic Editors
2021-05-26 23:52:39 +07:00
- [Figma](https://www.figma.com/)
- [Sketch](https://www.sketch.com/)
- [Adobe XD](https://www.adobe.com/products/xd.html)
2021-07-31 13:00:18 +07:00
## Design Collaboration Tools
2021-05-27 07:28:34 +07:00
- [Sympli](https://sympli.io/)
2021-05-26 23:52:39 +07:00
- [Zepline](https://zeplin.io/)
2021-07-31 13:00:18 +07:00
## Design Tools
2021-05-27 10:45:26 +07:00
- [DetailsPro](https://detailspro.app) You can design with SwiftUI free 👍
<p align="right">
<a href="#-content">Back to Content</a>
</p>
2021-10-02 03:25:11 +07:00
## Useful Sites
- [HEX Color Picker](https://imagecolorpicker.com/) Good for picking color as Hex 👍
<p align="right">
<a href="#-content">Back to Content</a>
</p>
## Screen Layout Programmatically
TBA
2021-05-27 10:45:26 +07:00
2021-06-04 03:22:19 +07:00
<p align="right">
<a href="#-content">Back to Content</a>
</p>
2023-04-30 15:01:22 +07:00
# Bundle
2023-04-30 14:59:55 +07:00
2023-05-01 03:22:16 +07:00
You can use [Bundle+Extension.swift](https://github.com/jphong1111/awesome-ios-developer/blob/main/Bundle%2BExtension.swift) file to configure your bundle to your application.
> Source code from : [PhoneNumberKit](https://github.com/marmelroy/PhoneNumberKit)
2023-05-01 03:14:06 +07:00
2023-05-01 03:22:16 +07:00
- [Bundles and Packages](https://nshipster.com/bundles-and-packages/)
2023-04-30 14:59:55 +07:00
## Static Library
## Dynamic Library
2023-04-30 15:01:22 +07:00
## xcframework
2023-04-30 14:59:55 +07:00
XCFrameworks is a distributable binary package created by Xcode that contains variants of a framework or library so that it can be used on multiple platforms (iOS, macOS, tvOS, and watchOS), including Simulator builds
2023-05-01 03:22:16 +07:00
2023-04-30 14:59:55 +07:00
[Creating a multiplatform binary framework bundle](https://developer.apple.com/documentation/xcode/creating-a-multi-platform-binary-framework-bundle)
<p align="right">
<a href="#-content">Back to Content</a>
</p>
2021-10-02 03:25:11 +07:00
## Helper
2021-04-22 17:06:56 +07:00
2021-05-03 13:57:35 +07:00
All files are resuable files and protocol oriented. **Just Copy and Paste inside your project and use it!!** 👍
2021-05-27 23:37:31 +07:00
**These helper files are not with Error Handling! careful at use**
2021-05-03 16:51:46 +07:00
## Email, Message, Call
2021-05-03 13:57:35 +07:00
2021-04-22 17:06:56 +07:00
You can check the file in the follow link
2021-05-27 23:15:55 +07:00
- [Email, Message, Call](https://github.com/jphong1111/Useful_Swift/blob/main/Helper/ConversationHandler/ConversationManager.swift)
2021-05-03 18:21:44 +07:00
### Usage
2021-05-24 23:30:30 +07:00
import MessageUI first
2021-04-22 17:14:29 +07:00
```swift
import MessageUI
```
Then use it
2021-05-03 18:29:22 +07:00
> Don't forget to extend the mail, message delegate to your ViewController!
2021-04-22 17:14:29 +07:00
```swift
2021-05-03 18:29:22 +07:00
lazy var conversation = ConversationManager(presentingController: self, mailDelegate: self, messageDelegate: self, viewController: self)
2021-05-03 18:29:22 +07:00
@IBAction private func sendEmail(_ sender: UIButton) {
conversation.sendEmail(feedback: MailFeedback(recipients: ["abcd@google.com"], subject: "FeedBack", body: "Write feedback here"))
}
2021-05-03 18:29:22 +07:00
@IBAction private func sendMessage(_ sender: UIButton) {
conversation.sendMessage(feedback: MessageFeedBack(recipients: ["1111111111"], body: "Type here"))
}
2021-05-03 18:29:22 +07:00
@IBAction private func startCall(_ sender: UIButton) {
conversation.makeCall(number: "1111111111")
}
```
2021-04-10 03:58:50 +07:00
2021-05-03 18:41:57 +07:00
Good To GO 👏👏👏
> See Example [here](https://github.com/jphong1111/ImageMessageHandler_DemoApp)
2021-08-03 02:00:59 +07:00
<p align="right">
<a href="#-content">Back to Content</a>
</p>
2021-05-03 16:51:46 +07:00
## Network Layer
2021-05-03 13:57:35 +07:00
2021-05-03 13:58:22 +07:00
- [Network Layer](https://github.com/jphong1111/Useful_Swift/tree/main/Helper/Network%20Layer)
2021-05-03 13:57:35 +07:00
2021-05-03 16:51:46 +07:00
### Usage
2021-05-03 14:26:28 +07:00
First, set the base URL in **EndPointType file**
2021-05-03 17:05:30 +07:00
> Don't forget to put your API key in it!
2021-05-03 14:26:28 +07:00
```swift
var baseURL: URL {
guard let url = URL(string: "https://api.openweathermap.org/data/2.5/") else {
fatalError("baseURL could not be configured.")
}
return url
}
```
then make a instance of router.swift file in your code
```swift
private let router = Router<YourAPI>()
```
2021-05-03 14:27:54 +07:00
for **YourAPI part**, simply create a new **enum** with cases about specific api URL
2021-05-03 14:26:28 +07:00
> It will make your router more dynamic!
> Don't forget extension to EndPointType!
```swift
enum YourAPI {
case first(country: String)
case second(time: Int)
case third(name: String)
}
extension YourAPI: EndPointType {
var path: String {
switch self {
case .first(let country):
return "\(country).json"
case .second(let time):
return "\(time).json"
2021-05-03 14:27:54 +07:00
case .third(let name):
2021-05-03 14:26:28 +07:00
return "\(name).json"
}
}
}
```
then, use it like this
```swift
router.request(.first(country: London)) { [weak self] (results: Result<CountryWeather, AppError>) in
guard let self = self else { return }
switch results {
case .success(let data):
// insert your modifications!
case .failure(let error):
// insert your modifications!
print(error)
}
}
```
> **CountryWeather should be a model with Decodable**
2021-05-20 10:42:57 +07:00
If you want to see how can I use Network Layer in Project, check [this](https://github.com/jphong1111/Unsplash_Clone/tree/main/Unsplah_Clone/ReusableComponent/NetworkLayer)
2021-05-03 14:26:28 +07:00
2021-05-03 14:29:43 +07:00
This reusable network layer files for referenced from [here](https://medium.com/flawless-app-stories/writing-network-layer-in-swift-protocol-oriented-approach-4fa40ef1f908)
2021-05-20 10:42:57 +07:00
> Also [Alamofire](https://github.com/Alamofire/Alamofire) will be a great option for Network Layer!
2021-05-03 16:51:46 +07:00
## Image Picker
2021-05-03 16:50:11 +07:00
2021-05-06 00:51:33 +07:00
- [Image Picker](https://github.com/jphong1111/Useful_Swift/blob/main/Helper/ImagePickerHandler/ImagePicker.swift)
2021-05-03 16:50:11 +07:00
2021-05-03 16:51:46 +07:00
### Usage
2021-05-03 16:50:11 +07:00
Copy and Paste in your project and then declare Image Picker object inside your project
```swift
lazy var imagePicker = ImagePicker(presentationController: self, delegate: self)
```
Then, extend ImagePickerDelegate to your viewController
```swift
extension ViewController: ImagePickerDelegate {
func didSelect(image: UIImage?) {
self.yourImageView.image = image
self.dismiss(animated: true, completion: nil)
}
}
```
Good To GO 👏👏👏
> See Example [here](https://github.com/jphong1111/ImageMessageHandler_DemoApp)
2021-05-03 18:21:44 +07:00
## File Manager
2021-05-30 06:13:13 +07:00
- [File Manager](https://github.com/jphong1111/awesome-ios-developer/blob/main/Helper/FileManageHandler/FileManager.swift)
2021-05-03 18:46:08 +07:00
### Usage
Copy and Paste in your project
```swift
let readData = FileManageHelper.manager.readFile(filename: fileNameTextField.text ?? "", type: extensionTextField.text ?? "")
resultTextField.text = readData
```
> File Manager are wrote with singleton pattern, therefore no need to declare in side your code!
2021-05-03 18:21:44 +07:00
2021-05-03 18:51:05 +07:00
Good To GO 👏👏👏
2021-05-03 18:21:44 +07:00
## Video Downloader
2021-05-30 06:11:59 +07:00
- [Video Downloader](https://github.com/jphong1111/awesome-ios-developer/blob/main/Helper/VideoDownloadHandler/VideoDownloadManager.swift)
2021-05-03 18:51:05 +07:00
## Usage
Make an object of VideoManager inside your code
```swift
let videoManager = VideoManager()
```
use downloadVideoLinkAndCreateAsset function to start download with entering URL
```swift
self.videoManager.downloadVideoLinkAndCreateAsset(text)
```
Good To GO 👏👏👏
2021-05-03 18:21:44 +07:00
2021-05-20 10:50:21 +07:00
## Image Downloader
There is no file for Image Downloader.
To download images into device, only thing is this
```swift
if let data = try? Data(contentsOf: urls),
let image = UIImage(data: data) {
2021-08-30 13:21:58 +07:00
UIImageWriteToSavedPhotosAlbum(image, nil, nilil)
2021-05-20 10:50:21 +07:00
}
```
2021-05-20 10:52:34 +07:00
Just **change urls into your image URL**
2021-05-20 10:50:21 +07:00
> UIImageWriteToSavedPhotosAlbum will take care it to download to device.
2021-05-20 10:52:34 +07:00
2021-05-20 10:50:21 +07:00
> For more info go [here](https://www.hackingwithswift.com/example-code/media/uiimagewritetosavedphotosalbum-how-to-write-to-the-ios-photo-album)
Good To GO 👏👏👏
2021-05-03 19:09:09 +07:00
## Location Manager
2021-05-24 23:44:45 +07:00
- ~~[Location Manager](https://github.com/jphong1111/Useful_Swift/tree/main/Helper/LocationHandler/LocationManager.swift)~~
Currently Working
2021-05-03 19:09:09 +07:00
2021-06-04 03:22:19 +07:00
<p align="right">
<a href="#-content">Back to Content</a>
</p>
2021-06-22 19:33:24 +07:00
## Local Notification Manager
2021-09-07 21:19:48 +07:00
- [Local Notification Manager](https://github.com/jphong1111/awesome-ios-developer/blob/main/Helper/LocalNotificationHelper/LocalNotificationManager.swift)
2021-06-22 19:33:24 +07:00
2021-09-07 21:19:48 +07:00
<p align="right">
<a href="#-content">Back to Content</a>
</p>
2021-08-03 02:00:59 +07:00
2022-03-03 05:21:13 +07:00
# API
2021-04-10 04:12:26 +07:00
2021-05-01 09:20:43 +07:00
API(Application Programming Interface) is an interface that defines interactions between multiple software applications or mixed hardware-software intermediaries. It defines the kinds of calls or requests that can be made, how to make them, the data formats that should be used, the conventions to follow, etc.
2021-04-10 04:30:48 +07:00
2022-03-03 05:21:13 +07:00
## Various API Site
2021-05-27 10:25:28 +07:00
- [rapidAPI](https://www.rapidapi.com)
2021-05-27 11:14:52 +07:00
- [AnyAPI](https://any-api.com/)
2021-05-27 10:25:28 +07:00
- [Programmableweb](https://www.programmableweb.com/)
2021-07-22 10:16:06 +07:00
<p align="right">
<a href="#-content">Back to Content</a>
</p>
2021-08-04 12:11:53 +07:00
2021-04-10 15:55:09 +07:00
## JSON
2021-04-10 15:58:08 +07:00
JSON is a language-independent data format
2021-04-10 16:01:31 +07:00
> Which is relative with **KEY - VALUE** pair
2021-04-10 16:30:44 +07:00
```json
2021-04-10 15:58:08 +07:00
{
2021-04-10 16:00:40 +07:00
"main": [
2021-04-10 15:58:08 +07:00
{
2021-04-10 16:00:40 +07:00
"title": "example1",
2021-04-10 16:31:31 +07:00
"body": "body1"
2021-04-10 15:58:08 +07:00
},
{
2021-04-10 16:00:40 +07:00
"title": "example2",
2021-04-10 16:31:31 +07:00
"body: "body2"
2021-04-25 04:53:10 +07:00
}
2021-04-10 15:58:08 +07:00
]
}
2021-04-10 16:00:40 +07:00
```
2021-04-10 15:55:09 +07:00
### JSON parser extension for Chrome
2021-04-10 16:05:27 +07:00
This extension makes JSON more structable
2021-04-10 15:55:09 +07:00
[JSON parser pro](https://chrome.google.com/webstore/detail/json-viewer-pro/eifflpmocdbdmepbjaopkkhbfmdgijcc) **FREE** :+1:
2021-05-27 10:45:26 +07:00
## JSONDecoder
2021-04-10 16:15:30 +07:00
2021-05-27 10:45:26 +07:00
To use JSONDecoder in swift, you have to define the model to be Codable or Decodable
2021-05-01 09:20:43 +07:00
```swift
public typealias Codable = Decodable & Encodable
```
> Decodable can only decode the json data. Can't encoded json file!!
```swift
struct User: Codable {
2021-05-27 23:28:20 +07:00
var firstName: String
var lastName: String
2021-05-01 09:20:43 +07:00
var country: String
2021-05-27 23:28:20 +07:00
enum CodingKeys: String, CodingKey {
case firstName = "first_name"
case lastName = "last_name"
case country
}
2021-05-01 09:20:43 +07:00
}
2021-05-27 23:28:20 +07:00
2021-05-01 09:20:43 +07:00
```
2021-05-27 23:28:20 +07:00
> To avoid snake_case in swift, use CodingKeys or JSONDecoder.KeyDecodingStrategy
2021-05-01 09:20:43 +07:00
2021-05-20 10:34:45 +07:00
To use JSONDecoding, declare JSONDecoder and use decode() function
```swift
do {
let data = try JSONDecoder().decode(T.self, from: unwrappedData)
completionOnMain(.success(data))
} catch {
print(error)
completionOnMain(.failure(.parseError))
}
```
T.self -> Model(Struct) of the data that you want to decode
> data will decoded to form of T
unwrappedData -> Input actual data from file or server
> This should be a Data Type!!
2021-05-27 10:25:28 +07:00
## JSONSerialization
2021-04-10 16:15:30 +07:00
2021-05-27 10:25:28 +07:00
JSONSerialization is a old way of decode the JSON file.
> Apple populated Codable since Swift 4
### Example
Example of number.json data
```json
{
"number": [
{
"name": "Dennis",
"number": "111-222-3333"
},
{
"name": "Jenny",
"number": "444-555-6666"
},
{
"name": "Ben",
"number": "777-888-9999"
}
]
}
```
Here is a example of JSONSerialization with actaul JSON file in project folder
> Otherwise you can use URL!
```swift
private func populateDataFromJson() {
if let path = Bundle.main.path(forResource: "NumberData", ofType: "json") {
do {
let dataJson = try Data(contentsOf: URL(fileURLWithPath: path))
let jsonDict = try JSONSerialization.jsonObject(with: dataJson, options: .mutableContainers)
if let jsonResults = jsonDict as? [String: Any],
let results = jsonResults["number"] as? [[String: Any]] {
results.forEach { dict in
// simply appended to list(array)
self.phoneNumberList.append(PhoneNumber(name: dict["name"] as? String ?? "", number: (dict["number"] as? String ?? "")))
self.phoneNumberListClone.append(PhoneNumber(name: dict["name"] as? String ?? "", number: (dict["number"] as? String ?? "")))
}
}
} catch {
print(error.localizedDescription)
}
}
}
```
> .mutableContainers allows to working like a array and dictionary type
### JSON Parser Library
This library provide JSON parsing
- [SwifyJSON](https://github.com/SwiftyJSON/SwiftyJSON)
2021-05-24 08:22:30 +07:00
2021-07-25 16:48:30 +07:00
<p align="right">
<a href="#-content">Back to Content</a>
</p>
2021-09-02 13:05:16 +07:00
## NotificationCenter
2021-06-03 22:18:18 +07:00
2021-07-05 10:34:42 +07:00
A notification dispatch mechanism that enables the broadcast of information to registered observers.
2021-09-02 13:05:16 +07:00
- [NotificationCenter Apple Document](https://developer.apple.com/documentation/foundation/notificationcenter)
- [How To: Using Notification Center In Swift](https://learnappmaking.com/notification-center-how-to-swift/)
2021-05-22 00:55:41 +07:00
2021-07-22 10:16:06 +07:00
<p align="right">
<a href="#-content">Back to Content</a>
</p>
2021-05-23 11:39:07 +07:00
## UserDefaults
2021-05-22 00:55:41 +07:00
The UserDefaults class provides a programmatic interface for interacting with the defaults system. Check [Apple Document](https://developer.apple.com/documentation/foundation/userdefaults) for more info
2021-05-23 11:39:07 +07:00
> UserDefaults has to have **key-value** pair
2021-05-22 00:55:41 +07:00
2021-05-23 11:39:07 +07:00
### When do we use UserDafaults
- User information, like name, email address, age, occupation
- App settings, like user interface language, app color theme or “detailed vs. simple UI”
- Flags, more on this later
2021-05-24 03:20:42 +07:00
- If store data is small
2021-05-22 00:55:41 +07:00
2021-06-03 03:36:08 +07:00
## How to find documentDirectory
2021-05-22 00:55:41 +07:00
Put this line of code inside of your project
```swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
print(NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).last ?? "")
return true
}
```
2021-05-22 03:50:22 +07:00
<img src = "https://github.com/jphong1111/Useful_Swift/blob/main/Images/DocumentPath.png" />
2021-05-22 00:55:41 +07:00
simply move into that path and you can find the documentDirectory of your Application
> if Library is not shown up, just do **Shift + Command + .** to show hidden files in your folder
2021-05-22 03:50:22 +07:00
<img src = "https://github.com/jphong1111/Useful_Swift/blob/main/Images/UserDefaultPlistPath.png" />
2021-06-03 03:36:08 +07:00
## Usage
2021-05-22 03:53:03 +07:00
2021-05-22 03:27:41 +07:00
As you can see in the below, intArray will stored inside the device through UserDefaults(), so that if device is shut down, changed value wil be stored in device.
```swift
class ViewController: UIViewController {
var intArray = [1,2,3,4,5]
let defaults = UserDefaults()
override func viewDidLoad() {
super.viewDidLoad()
intArray = defaults.array(forKey: "IntArray") as! [Int]
}
@IBOutlet weak var textField: UILabel!
@IBAction private func isClicked(_ sender: UIButton) {
intArray.append(6)
defaults.set(intArray, forKey: "IntArray")
textField.text = "\(intArray)"
}
}
```
2021-05-22 03:50:22 +07:00
You can your plist file like this!
<img src = "https://github.com/jphong1111/Useful_Swift/blob/main/Images/UserDefaultPlist.png" />
2021-05-24 03:20:42 +07:00
Declare Userdefault like this!
```swift
let defaults = UserDefaults.standard
```
> **standard** allows to access from anywhere inside device
2021-05-24 03:29:08 +07:00
**With using set function, you can set userdefaults**
2021-05-24 03:20:42 +07:00
2021-05-24 03:27:53 +07:00
<img src = "https://github.com/jphong1111/Useful_Swift/blob/main/Images/UserDefaultSet.png" width = "60%" height = "60%"/>
2021-05-24 03:20:42 +07:00
2021-05-24 03:29:08 +07:00
**Also these function will allow to get a data from plist**
2021-05-24 03:20:42 +07:00
2021-05-24 03:27:53 +07:00
<img src = "https://github.com/jphong1111/Useful_Swift/blob/main/Images/UserDefaultGet.png" width = "60%" height = "60%"/>
2021-05-24 03:20:42 +07:00
2021-06-03 03:36:08 +07:00
## Store Object
2021-06-03 03:39:26 +07:00
[Store Object](https://stackoverflow.com/questions/29986957/save-custom-objects-into-nsuserdefaults)
2021-06-03 03:36:08 +07:00
2021-05-22 03:50:22 +07:00
**You are GOOD TO GO** 👏👏👏
2021-05-22 03:27:41 +07:00
2021-06-04 03:22:19 +07:00
<p align="right">
<a href="#-content">Back to Content</a>
</p>
2022-03-03 05:21:13 +07:00
# Core Data
2021-05-22 00:55:41 +07:00
2021-06-30 09:19:28 +07:00
[Everything Core Data](https://metova.com/everything-core-data/)
2021-05-24 08:26:38 +07:00
Use Core Data to save your applications permanent data for offline use, to cache temporary data, and to add undo functionality to your app on a single device.
2021-05-25 01:01:12 +07:00
**Core Data in Swift is using SQLite as DEFAULT**
2021-05-24 04:42:55 +07:00
<img src = "https://github.com/jphong1111/Useful_Swift/blob/main/Images/DataStoreInSwift.png" width = "50%" height = "50%"/>
2021-05-24 04:44:18 +07:00
> Image From London App Brewery
2021-05-22 00:55:41 +07:00
2021-08-31 23:05:01 +07:00
📚📚 Recommend Book 📚📚
| Book Name | Authors Name |
| :----------- | :----------- |
| Core Data by Tutorials: iOS 12 and Swift 4.2 Edition | raywenderlich Tutorial Team |
2021-06-27 13:53:38 +07:00
## Core Data Stack
2021-06-28 23:24:43 +07:00
- [The Core Data Stack](https://www.raywenderlich.com/books/core-data-by-tutorials/v7.0/chapters/3-the-core-data-stack)
2021-06-27 18:23:04 +07:00
<img src = "https://github.com/jphong1111/awesome-ios-developer/blob/main/Images/Core_Data_Stack.png" width = "70%" height = "70%"/>
2021-06-27 13:53:38 +07:00
2021-06-28 23:24:43 +07:00
2021-06-29 11:34:46 +07:00
- **NSManagedObject** - This is a base class of all the core data model object. This provides the schema of our database table. This is used to store model data in our application. KVO and KVC compliant. It can notify any changes that are done on its properties if any object is listening.
- **NSManagedObjectContext** - Most important class. This is the place where you do all the computations. You can think this as a scratch pad where you do all the operations realated to core data (CRUD). It's an object which you can use to manipulate and track any changes done to manage object. All the changes done on a context object will be held until and unless you are discarding or writing those changes permaneently to persistntent storage.
- **NSPersistentStoreCoordinator** - The main functionality is to provide a communication between context and persistent store.
2021-06-29 11:33:20 +07:00
- NSPersistentStore - They are the stores in which the data are being saved. These includes SQLite, In-Memory, Binary, XML(the XML store is not available on iOS).
- NSPersistentContainer - This contains the whole core data stacks.
2021-06-28 23:24:43 +07:00
2022-03-03 05:21:13 +07:00
## Set Up Core Data
2021-05-24 08:20:37 +07:00
Simply Click Core Data check box when you create a new project
2021-05-24 08:26:38 +07:00
<img src = "https://github.com/jphong1111/Useful_Swift/blob/main/Images/AddCoreData.png" width = "50%" height = "50%"/>
2021-05-24 08:20:37 +07:00
If you want to attach Core Data in exsiting project
Create **Data Model** file first
2021-05-24 08:26:38 +07:00
<img src = "https://github.com/jphong1111/Useful_Swift/blob/main/Images/AddDataModel.png" width = "50%" height = "50%"/>
2021-05-24 08:20:37 +07:00
Then import CoreData inside your **AppDelegate.swift** file
```swift
import CoreData
```
And Copy and Paste this lines of code inside your **AppDelegate.swift** file
```swift
// MARK: - Core Data stack
lazy var persistentContainer: NSPersistentContainer = {
/*
The persistent container for the application. This implementation
creates and returns a container, having loaded the store for the
application to it. This property is optional since there are legitimate
error conditions that could cause the creation of the store to fail.
*/
let container = NSPersistentContainer(name: "Your DataModel file name")
container.loadPersistentStores(completionHandler: { (storeDescription, error) in
if let error = error as NSError? {
// Replace this implementation with code to handle the error appropriately.
// fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
/*
Typical reasons for an error here include:
* The parent directory does not exist, cannot be created, or disallows writing.
* The persistent store is not accessible, due to permissions or data protection when the device is locked.
* The device is out of space.
* The store could not be migrated to the current model version.
Check the error message to determine what the actual problem was.
*/
fatalError("Unresolved error \(error), \(error.userInfo)")
}
})
return container
}()
// MARK: - Core Data Saving support
func saveContext () {
let context = persistentContainer.viewContext
if context.hasChanges {
do {
try context.save()
} catch {
// Replace this implementation with code to handle the error appropriately.
// fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
let nserror = error as NSError
fatalError("Unresolved error \(nserror), \(nserror.userInfo)")
}
}
}
```
Don't forget to change it
```swift
let container = NSPersistentContainer(name: "Your DataModel file name")
```
And goto **SceneDelegate.swift** file, copy below lines of code and replace yours
```swift
func sceneDidEnterBackground(_ scene: UIScene) {
// Called as the scene transitions from the foreground to the background.
// Use this method to save data, release shared resources, and store enough scene-specific state information
// to restore the scene back to its current state.
// Save changes in the application's managed object context when the application transitions to the background.
(UIApplication.shared.delegate as? AppDelegate)?.saveContext()
}
```
2021-05-24 08:51:20 +07:00
If your target is **below iOS13**, put this line of code in side your **applicationWillTerminate** of **AppDelegate.swift** file
2021-05-24 08:20:37 +07:00
```swift
self.saveContext()
```
2021-05-30 14:39:10 +07:00
## Core Data Usage
2021-05-24 10:02:52 +07:00
2021-06-30 09:19:28 +07:00
2021-05-24 10:02:52 +07:00
Once you create your DataModel file, you can simply create a **Entity(Class)** and **Attributes(Properties)**
And then, change the type of attributes in inspector like this
2021-05-24 12:19:06 +07:00
<img src = "https://github.com/jphong1111/Useful_Swift/blob/main/Images/DataModelAttribute_inspector.png"/>
Once you create your own Entities & Attributes, go to Inspector and change Module to **CurrentProductModule**
<img src = "https://github.com/jphong1111/Useful_Swift/blob/main/Images/DataModelAttributes.png"/>
> If you didn't set it, thats fine, but if you are working in big project, then you need to set it. Otherwise this can occurs some error.
2021-05-24 10:02:52 +07:00
2021-06-30 09:19:28 +07:00
## Codegen
2021-05-24 12:36:31 +07:00
As you can see in above, there are three options
- Manual/None - Swift didn't generate CoreDataClass, CoreDataProperties files so that you have to create yourself **(full control)**
- Class Definition - Swift will generate CoreDataClass, CoreDataProperties files. **(No control)**
- Category/Extension - Swift will generate only Extension file **(Some Control)**
2021-05-24 10:02:52 +07:00
CoreDataClass, CoreDataProperties are located in below
2021-05-24 12:37:17 +07:00
> /Users/dennis/Library/Developer/Xcode/DerivedData/CoreDataUserDefaultPractice-hisefjfyuvglrjekndpftwazftug/Build/Intermediates.noindex/CoreDataUserDefaultPractice.build/Debug-iphonesimulator/CoreDataUserDefaultPractice.build/DerivedSources/CoreDataGenerated/CoreDataUserDefaultPractice
2021-05-24 10:02:52 +07:00
2021-05-24 12:36:31 +07:00
And CoreDataClass, CoreDataProperties are looking like this,
2021-05-24 12:19:06 +07:00
<img src = "https://github.com/jphong1111/Useful_Swift/blob/main/Images/CoreDataClass_Properties.png"/>
2021-05-24 23:45:54 +07:00
2021-05-24 23:44:45 +07:00
> If your code can run it but didn't get your Entities, **Rebuild it or Restart your Xcode**
2021-05-24 10:02:52 +07:00
2021-06-29 01:31:08 +07:00
**The reason that files divided into two files is that one for writing Business Logic, one for Properties**
2021-06-30 09:19:28 +07:00
## Entities
An entity represents a table in your database. It is the blueprint for the NSManagedObject subclass instances that you will create and use throughout your application.
## Attributes
Attributes are properties of your object. They translate to a column in your database table and a property in your managed object. You can choose from a variety of primitive values that the database has to offer such as a string, integer, or date.
## Relationships
A relationship describes how one entity relates to another. Two important aspects of this are the cardinality and the deletion rule
### Cardinality
- **One-to-many** - Lets say that each Department has a group of Employees that can only work for a single Department. This would be a “one-to-many” relationship since each Department could have many Employees and each Employee can only work for one Department.
- **Many-to-many** - If a single Employee could work for multiple Departments, then our Department/Employee relationship would be “many-to-many” because each Department could have many Employees and each Employee could work for multiple Departments.
### Delete Rules
[Core Data Relationships and Delete Rules](https://cocoacasts.com/core-data-relationships-and-delete-rules)
- **No Action** - Do nothing to the object at the destination of the relationship. For example, if you delete a department, leave all the employees as they are, even if they still believe they belong to that department.
- **Nullify (Default)** - Set the inverse relationship for objects at the destination to null. For example, if you delete a department, set the department for all the current members to null. This only makes sense if the department relationship for an employee is optional, or if you ensure that you set a new department for each of the employees before the next save operation.
- **Cascade** - Delete the objects at the destination of the relationship. For example, if you delete a department, fire all the employees in that department at the same time.
- **Deny** - If there is at least one object at the relationship destination, then the source object cannot be deleted. For example, if you want to remove a department, you must ensure that all the employees in that department are first transferred elsewhere (or fired!) otherwise the department cannot be deleted.
2021-06-29 01:31:08 +07:00
2021-05-25 01:01:12 +07:00
## Store Data
Declare context as a global variable
```swift
let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
```
> Get viewContext that we defined in AppDelegate.swift file
Simply you can use this code to save your data to CoreData
```swift
func saveItem() {
do {
try context.save()
} catch {
print("Error Saving Context: \(error.localizedDescription)")
}
}
```
> Use it wherever you want
Data can be find if you print the path
```swift
print(FileManager.default.urls(for: .documentDirectory, in: .userDomainMask))
```
<img src = "https://github.com/jphong1111/Useful_Swift/blob/main/Images/CoreDataSQLite.png" />
2021-05-25 01:02:28 +07:00
2021-05-25 01:01:12 +07:00
> You can check Entities, Properties inside that file
2021-05-25 03:02:19 +07:00
## Load Data
Refer this code and apply it to your code wherever you want to reload it
```swift
func loadItem() {
let request: NSFetchRequest<Item> = Item.fetchRequest()
do {
itemArray = try context.fetch(request)
} catch {
print("Load Item Error: \(error.localizedDescription)")
}
}
```
> Item will be your Entity, itemArray will be your Entity object
> Don't forget to import **CoreData**
2021-05-25 04:14:07 +07:00
## Update Data
Simply use setValue function so that you can update your value in DB
```swift
itemArray[0].setValue(<#T##value: Any?##Any?#>, forKey: <#T##String#>)
```
> if you are using TableView or CollectionView, change 0 to indexPath.row
## Delete Data
Simply use delete function in context
```swift
context.delete(itemArray[0])
```
> change number for dynamic!
2021-07-23 01:03:30 +07:00
**You are GOOD TO GO** 👏👏👏
<p align="right">
<a href="#-content">Back to Content</a>
</p>
## Core Bluetooth
2021-07-24 02:56:55 +07:00
- [Introduction to BLE Mobile Development [iOS]](https://www.novelbits.io/intro-ble-mobile-development-ios/)
- [Core Bluetooth Tutorial for iOS: Heart Rate Monitor](https://www.raywenderlich.com/231-core-bluetooth-tutorial-for-ios-heart-rate-monitor)
- [Getting Started with Core Bluetooth](https://ditto.live/blog/posts/getting-started-with-core-bluetooth)
2021-07-23 01:03:30 +07:00
2021-05-24 08:20:37 +07:00
**You are GOOD TO GO** 👏👏👏
2021-06-04 03:18:23 +07:00
<p align="right">
<a href="#-content">Back to Content</a>
</p>
2021-06-04 03:13:46 +07:00
2022-03-03 05:21:13 +07:00
# Third Party Library
2021-06-04 07:29:08 +07:00
Third Party Library saves you time as you do not need to develop the functionality that the library provides.
[SHOULD DEVELOPERS USE THIRD-PARTY LIBRARIES?](https://www.scalablepath.com/blog/third-party-libraries/)
> Relying on library(abused) is not a good idea
- [awesome ios github](https://github.com/vsouza/awesome-ios) Contains all the popular libraries in Swift:+1:
- [awesome swift site](https://swift.libhunt.com/) You can broswe popular libraries related to iOS
- [Explore Swift](https://kandi.openweaver.com/explore/swift) Discover & find a curated list of popular & new libraries, top authors and trending discussions on kandi.
2021-05-07 15:10:24 +07:00
2021-05-30 06:00:21 +07:00
## Dependency/Package Manager
A package manager is a tool that simplifies the process of working with code from multiple sources.
- Centralised hosting of packages and source code with public server with access to developers or contributors
- Download the source code at the run time, so that we dont need to include it in the repository
- Link the source code to our working repository by including source files
[More Info](https://medium.com/xcblog/swift-dependency-management-for-ios-3bcfc4771ec0)
2021-05-29 03:15:35 +07:00
## CocoaPods
2021-05-30 06:18:25 +07:00
Download cocoapods
2021-05-30 06:00:21 +07:00
```bash
$ sudo gem install cocoapods
```
2021-05-30 06:18:25 +07:00
After finish download cocoapods, go to your root folder of your project and make pod file
```bash
$ pod init
```
Click into your pod file and edit
2021-06-01 08:54:36 +07:00
Image
2021-05-30 06:18:25 +07:00
After finish editing, update your pod file
```bash
$ pod install
```
2021-06-01 08:54:36 +07:00
2021-05-30 06:18:25 +07:00
**You are GOOD TO GO** 👏👏👏
2021-07-25 08:09:50 +07:00
<p align="right">
<a href="#-content">Back to Content</a>
</p>
2021-05-29 03:15:35 +07:00
## Carthage
2021-06-12 04:12:11 +07:00
- [Getting started with Carthage to manage dependencies in Swift and iOS](https://www.twilio.com/blog/2016/05/getting-started-with-carthage-to-manage-dependencies-in-swift-and-ios.html)
- [Carthage Tutorial: Getting Started](https://www.raywenderlich.com/7649117-carthage-tutorial-getting-started)
2021-06-12 13:07:37 +07:00
- [Carthage](https://github.com/Carthage/Carthage)
2021-06-12 04:12:11 +07:00
First, install Carthage through HomeBrew
2021-05-30 12:23:58 +07:00
```bash
$ brew install carthage
```
2021-06-12 04:12:11 +07:00
if already installed, check if there is latest version.
2021-05-30 12:23:58 +07:00
```bash
$ carthage update
```
2021-06-12 04:12:11 +07:00
Then, go to your root project folder, and do this
```bash
touch Cartfile
```
open cartfile, put library that you want to use
```bash
github "<owner>/<repo>" == <version>
```
Example
```bash
github "Alamofire/Alamofire" == 4.9.0
github "Alamofire/AlamofireImage" ~> 3.4
```
And then, do this
```bash
carthage update --platform iOS
```
After finish downloading it, go to **Xcode -> Build phases**
TBD
2021-05-30 12:23:58 +07:00
**You are GOOD TO GO** 👏👏👏
2021-07-25 08:09:50 +07:00
<p align="right">
<a href="#-content">Back to Content</a>
</p>
2021-05-29 03:15:35 +07:00
## Swift Package Manager
2021-07-18 05:32:18 +07:00
<img src = "https://github.com/jphong1111/awesome-ios-developer/blob/main/Images/SwiftPackageManager.png" width = "50%" height = "50%"/>
2021-05-29 03:15:35 +07:00
2021-07-18 05:40:28 +07:00
Enter url of library that you want to install
2021-07-18 05:38:47 +07:00
<img src = "https://github.com/jphong1111/awesome-ios-developer/blob/main/Images/SwiftPackageManager2.png" width = "50%" height = "50%"/>
<img src = "https://github.com/jphong1111/awesome-ios-developer/blob/main/Images/SwiftPackageManager3.png" width = "50%" height = "50%"/>
2021-07-18 05:40:28 +07:00
**You are GOOD TO GO** 👏👏👏
<p align="right">
<a href="#-content">Back to Content</a>
</p>
## Recommend Library
2021-05-27 10:45:26 +07:00
- SDWebImage - Downloading and caching images from the web
- Kingfisher - Downloading and caching images from the web
2021-05-25 03:02:19 +07:00
- Hero - Various kind of animation with using Segue
- Alamofire - Network Layer tool
2021-05-27 10:45:26 +07:00
- Moya - Network abstraction layer written in Swift
2021-05-25 03:02:19 +07:00
- RxSwift - Reactive Programming in Swift
2021-05-27 10:45:26 +07:00
- SwiftyJSON - JSON parsar Helper
- IQKeyboardManager - Easy to manage Keyboard settings
- SnapKit - Swift Auto Layout DSL for iOS
2021-05-27 23:42:36 +07:00
- Charts - Make Beutiful Charts in your App
2021-07-05 14:52:47 +07:00
- Quick/Nimble - Testing Library + Asynchronous tests purpose
- Periphery - A tool to identify unused code in Swift Projects
2022-02-25 12:13:26 +07:00
- ReactorKit - A framework for a reactive and unidirectional Swift application architecture
2022-08-13 08:44:25 +07:00
- SwiftGen - SwiftGen is a tool to automatically generate Swift code for resources of your projects (like images etc), to make them type-safe to use.
2021-05-27 10:45:26 +07:00
- etc...
2021-05-21 10:10:28 +07:00
2021-06-17 04:25:31 +07:00
<p align="right">
<a href="#-content">Back to Content</a>
</p>
2021-06-11 23:12:06 +07:00
## Localization
Localization is the process of making your app support other languages. (Base language is English)
2021-06-12 00:39:59 +07:00
- [Localization Apple](https://developer.apple.com/localization/)
- [Localization Apple Developer](https://developer.apple.com/documentation/xcode/localization)
- [iOS Localization Tutorial](https://medium.com/lean-localization/ios-localization-tutorial-938231f9f881)
- [Internationalizing Your iOS App: Getting Started](https://www.raywenderlich.com/250-internationalizing-your-ios-app-getting-started)
2021-06-11 23:12:06 +07:00
## Localization Usage
First, you have to check **Use Base Internationalization**
> It might be checked
2021-07-01 15:05:16 +07:00
<img src = "https://github.com/jphong1111/Useful_Swift/blob/main/Images/Internationalization.png" width="70%" height ="70%" />
2021-06-11 23:13:22 +07:00
2021-06-11 23:12:06 +07:00
> English is a base Language
After you check it, add languages that you want to support in your App
2021-07-01 15:05:16 +07:00
<img src = "https://github.com/jphong1111/Useful_Swift/blob/main/Images/Internationalization2.png" width="70%" height ="70%" />
2021-06-11 23:12:06 +07:00
Then, you can check your language file like this!
2021-07-01 15:05:16 +07:00
<img src = "https://github.com/jphong1111/Useful_Swift/blob/main/Images/Internationalization3.png" width="70%" height ="70%" />
2021-06-11 23:12:06 +07:00
2021-06-12 00:39:59 +07:00
Create **Localizable.strings** file into your project
> Unlike Swift, the .strings file requires that each line terminate with a **semicolon**
2021-06-12 00:58:46 +07:00
> .strings file is where you can add translation data as **key-value** pairs
2021-06-12 00:39:59 +07:00
2021-07-01 15:05:16 +07:00
<img src = "https://github.com/jphong1111/Useful_Swift/blob/main/Images/Internationalization4.png" width="70%" height ="70%" />
2021-06-12 00:39:59 +07:00
2021-06-12 00:58:46 +07:00
In your .strings file, check localization button and choose language
2021-06-12 00:39:59 +07:00
2022-03-16 08:46:05 +07:00
<img src = "https://github.com/jphong1111/Useful_Swift/blob/main/Images/Internationalization5.png" />
2021-06-12 00:39:59 +07:00
2021-06-12 00:58:46 +07:00
And then add Key - Value pairs for tanslation
2021-06-12 00:39:59 +07:00
2021-07-01 15:05:16 +07:00
<img src = "https://github.com/jphong1111/Useful_Swift/blob/main/Images/Internationalization6.png" width="70%" height ="70%"/>
2021-06-12 00:39:59 +07:00
2021-06-12 00:58:46 +07:00
To use localization, use **NSLocalizedString** to implement it
```swift
NSLocalizedString(<#T##key: String##String#>, comment: <#T##String#>)
```
- [key] - put (key - value) pair that you created in .strings file
- [comment] - It will help your translators significantly and result in better translations
2021-06-12 00:39:59 +07:00
2021-06-12 00:58:46 +07:00
Simple example below
2021-06-12 00:39:59 +07:00
```swift
@IBAction func showAlert() {
let alertTitle = NSLocalizedString("Welcome", comment: "")
let alertMessage = NSLocalizedString("How are you", comment: "")
let cancelButtonText = NSLocalizedString("Cancel", comment: "")
let signupButtonText = NSLocalizedString("Signup", comment: "")
let alert = UIAlertController(title: alertTitle, message: alertMessage, preferredStyle: UIAlertController.Style.alert)
let cancelAction = UIAlertAction(title: cancelButtonText, style: UIAlertAction.Style.cancel, handler: nil)
let signupAction = UIAlertAction(title: signupButtonText, style: UIAlertAction.Style.default, handler: nil)
alert.addAction(cancelAction)
alert.addAction(signupAction)
present(alert, animated: true, completion: nil)
}
```
2021-06-12 00:58:46 +07:00
After that, we have to test if localization is working correctly or not
To test it, you can do either **Edit Scheme** or **New Scheme**
2021-06-12 02:11:34 +07:00
go to Run section, and change **App Language**
2021-06-12 00:58:46 +07:00
2021-06-12 02:12:41 +07:00
<img src = "https://github.com/jphong1111/Useful_Swift/blob/main/Images/Internationalization7.png" />
2021-06-12 02:11:34 +07:00
After finish setting Scheme try to run it!
<img src = "https://github.com/jphong1111/Useful_Swift/blob/main/Images/Internationalization8.png" width="50%" height ="50%" />
<img src = "https://github.com/jphong1111/Useful_Swift/blob/main/Images/Internationalization9.png" width="50%" height ="50%" />
2021-06-12 02:26:13 +07:00
2021-06-12 02:11:34 +07:00
**You are GOOD TO GO** 👏👏👏
2021-05-21 10:10:28 +07:00
2021-09-03 22:27:43 +07:00
<p align="right">
<a href="#-content">Back to Content</a>
</p>
2021-06-12 02:26:13 +07:00
## Useful for Localization
- [localazy](https://localazy.com/) localization tool for iOS and macOS apps. Supporting .strings, .stringsdict, .plist and XLIFF files.
- [locastudio](https://www.cunningo.com/locastudio/index.html) Analyze, review, and edit your app translations.
2021-06-17 04:25:31 +07:00
<p align="right">
<a href="#-content">Back to Content</a>
</p>
2021-06-14 09:42:58 +07:00
## Accessibility
2021-06-14 22:48:36 +07:00
Accessibility is all about making the iPhone, iPod touch, and iPad work for as wide a range of people as possible. That can include the very young, the very old, people brand new to computers and mobile devices, and also people with disabilities and special needs.
2021-06-14 09:42:58 +07:00
2021-06-14 23:15:59 +07:00
- Designing your app for accessibility makes it easier to write functional tests, whether youre using the UI Testing in Xcode.
- Youll also broaden your market and user base by making your app usable by a larger group.
- Implementing accessibility in your app shows youre willing to go the extra mile for every user, and thats a good thing.
2021-06-14 22:48:36 +07:00
- [iOS Accessibility: Getting Started](https://www.raywenderlich.com/6827616-ios-accessibility-getting-started)
2021-06-14 09:42:58 +07:00
2021-06-14 23:15:59 +07:00
2021-06-14 22:48:36 +07:00
## Accessibility Usage
2021-06-14 09:42:58 +07:00
2021-06-14 23:15:59 +07:00
To use accessibility, you have to enable this
> For most UIKit classes, **the default is true, but for UILabel its false**
```swift
label.isAccessibilityElement = true
```
- accessibilityLabel - short description of control e.g. "Save" for button, "Rating" for label
- accessibilityHint - helps the user to understand result of the action e.g "Save the documents"
- accessibilityTraits - collection of constants that describe the type of control and/or hot it should be treated
- accessibilityValue - Used to describe the value of a none-label UI component e.g. "50%" for progress bar
2021-06-14 09:42:58 +07:00
2021-06-17 04:25:31 +07:00
<p align="right">
<a href="#-content">Back to Content</a>
</p>
2021-06-14 09:42:58 +07:00
2021-04-29 11:42:01 +07:00
## GCD
GCD(Grand Central Dispatch) is a low-level API for managing concurrent operations. It can help you improve your apps responsiveness by deferring computationally expensive tasks to the background.
2021-04-10 16:15:30 +07:00
2021-05-30 06:18:25 +07:00
## DispatchQueue
2021-04-30 14:06:31 +07:00
An object that manages the execution of tasks serially or concurrently on your app's main thread or on a background thread.
2021-04-30 13:40:48 +07:00
2021-07-02 15:41:22 +07:00
### main
2021-04-30 14:06:31 +07:00
We can say main is a serial queue
2021-04-30 13:40:48 +07:00
2021-07-02 15:41:22 +07:00
### global()
2021-04-30 14:06:31 +07:00
We can say global is a concurrent queue
2021-04-30 13:40:48 +07:00
2021-07-02 15:41:22 +07:00
## Thread Safety
[Concurrency & Thread Safety in Swift](https://medium.com/cubo-ai/concurrency-thread-safety-in-swift-5281535f7d3a)
2021-07-07 11:09:49 +07:00
[Thread Safety in Swift](https://swiftrocks.com/thread-safety-in-swift)
2021-07-02 15:41:22 +07:00
2021-07-07 11:09:49 +07:00
- **Dispatch Barrier**
Use a barrier to synchronize the execution of one or more tasks in your dispatch queue.
[Dispatch Barrier Apple Documentation](https://developer.apple.com/documentation/dispatch/dispatch_barrier)
- **Dispatch Semaphore**
[Dispatch Semaphore Apple Documentation](https://developer.apple.com/documentation/dispatch/dispatch_semaphore)
- **NSLock**
2021-07-02 15:41:22 +07:00
2021-07-28 11:12:03 +07:00
An object that coordinates the operation of multiple threads of execution within the same application.
[NSLock](https://developer.apple.com/documentation/foundation/nslock)
2021-07-02 15:41:22 +07:00
2021-05-30 06:18:25 +07:00
## DispatchGroup
2021-04-30 13:40:48 +07:00
2021-07-03 22:55:13 +07:00
[DispatchGroup Apple Document](https://developer.apple.com/documentation/dispatch/dispatchgroup)
2021-06-01 08:54:36 +07:00
2021-05-30 06:18:25 +07:00
## DispatchWorkItem
2021-04-30 13:40:48 +07:00
2021-07-14 14:22:24 +07:00
The work you want to perform, encapsulated in a way that lets you attach a completion handle or execution dependencies.
2021-07-07 11:09:49 +07:00
2021-07-14 14:22:24 +07:00
[DispatchWorkItem Apple Document](https://developer.apple.com/documentation/dispatch/dispatchworkitem)
2021-07-07 11:09:49 +07:00
## Operation
2021-07-08 14:59:02 +07:00
[NSOperation Apple Documentation](https://developer.apple.com/documentation/foundation/nsoperation)
2021-07-07 11:09:49 +07:00
## OperationQueue
2021-07-08 14:59:02 +07:00
[NSOperationQueue Apple Documentation](https://developer.apple.com/documentation/foundation/nsoperationqueue)
2021-07-07 11:09:49 +07:00
2021-07-25 08:09:50 +07:00
<p align="right">
<a href="#-content">Back to Content</a>
</p>
2021-07-07 11:09:49 +07:00
# Thread Sanitizer
2021-04-30 17:16:16 +07:00
Thread Sanitizer is a tool to identifies the potential thread-related corruption issues. And it is a good way to find the [Readers and Writers problem](https://en.wikipedia.org/wiki/Readers%E2%80%93writers_problem) in your application.
2021-04-30 13:58:38 +07:00
2021-06-17 04:25:31 +07:00
<p align="right">
<a href="#-content">Back to Content</a>
</p>
## How to Use Thread Sanitizer
2021-04-30 13:58:38 +07:00
Go to this Option and Click **EDIT SCHEME...** 👈
2021-04-30 14:01:13 +07:00
<img src="https://github.com/jphong1111/Useful_Swift/blob/main/Images/address_sanitizer.png">
2021-04-30 17:16:16 +07:00
And then go to **RUN** and check **THREAD SANITIZER** 👈
2021-04-30 13:58:38 +07:00
2021-06-21 15:41:47 +07:00
<img src="https://github.com/jphong1111/awesome-ios-developer/blob/main/Images/thread_sanitizer.png">
2021-04-30 13:40:48 +07:00
2022-03-15 10:23:07 +07:00
# Testing
## Five Factor Testing
[Five Factor Testing](https://madeintandem.com/blog/five-factor-testing/)
2021-05-07 15:10:24 +07:00
2021-08-11 01:35:58 +07:00
# Test Double
2021-08-13 09:15:25 +07:00
**Test Double is a generic term for any case where you replace a production object for testing purposes.**
2021-08-11 01:35:58 +07:00
- Mocks - Mocks are pre-programmered with expectations which form a specification of the calls they are expected to receive. They can throw an exception if they receive a call they don't expect and are checked during verification to ensure they got all the calls they were expecting.
```swift
2021-08-13 09:15:25 +07:00
// exaple code will update
2021-08-11 01:35:58 +07:00
```
2021-08-17 20:47:30 +07:00
- Fake - Objects actually have working implementations, but usually take some shortcut which makes them not suitable for production.
2021-08-13 09:15:25 +07:00
```swift
// exaple code will update
```
2021-08-17 20:47:30 +07:00
- Spies - Spies are stubs that also record some information based on how they were called. One form of this might be an email service that records how many messages it was sent.
2021-08-13 09:15:25 +07:00
```swift
// exaple code will update
```
2021-08-17 20:47:30 +07:00
- Stubs - Stubs provide canned answers to calls made during the test, usually not responding at all to anything outside what's programmed in for the test.
2021-08-13 09:15:25 +07:00
```swift
// exaple code will update
```
2021-08-13 22:07:52 +07:00
- Dummy - Objects are passed around but never actually used. Usually they are just used to fill parameter lists.
2021-08-11 01:35:58 +07:00
2021-08-13 09:15:25 +07:00
```swift
// exaple code will update
```
# Useful Debugging Technique
[Debugging in Xcode 13: Tips & Tricks (2022) iOS](https://www.youtube.com/watch?v=ZAqnJQn7xp4&list=LL&index=5&ab_channel=iOSAcademy)
2022-04-20 11:16:33 +07:00
## 1. Change expression in debugging stage
2022-04-20 11:16:33 +07:00
<img src="https://github.com/jphong1111/Useful_Swift/blob/main/Images/debugging_expression.png" width = "80%" height = "80%">
2022-04-20 11:16:33 +07:00
Use ```expression``` at the beginning and then add whatever what you want to change into. It will change in debugging stage 👍
## 2. Symbolic Breakpoint
If we want to know whenever hit certain function, use symbolic breakpoint
2021-08-13 09:15:25 +07:00
2021-08-11 01:35:58 +07:00
# TDD
2021-05-14 17:30:52 +07:00
2021-07-07 11:27:01 +07:00
**Test Driven Development**
2021-08-18 22:02:15 +07:00
<img src="https://github.com/jphong1111/awesome-ios-developer/blob/main/Images/TDD.png" width="30%" height="30%"/>
2021-08-18 22:00:37 +07:00
- [Why Test-Driven Development (TDD)](https://marsner.com/blog/why-test-driven-development-tdd/)
2021-07-01 11:05:40 +07:00
## Reduce Build Time
Normally in complicated Application, build time for testing is crazy therefore, TDD spent most of time in building the project.
Here are useful ways that we can reduce build time when we are working with TDD style.
2022-04-24 13:32:11 +07:00
2022-04-08 09:38:26 +07:00
### 1. tuist focus
2022-04-08 09:18:24 +07:00
2022-04-08 09:38:26 +07:00
### 2. Detach debugger in **Edit Scheme**
2022-04-08 09:18:24 +07:00
un-check Debugger option
2022-04-08 09:17:25 +07:00
<img src = "https://github.com/jphong1111/awesome-ios-developer/blob/main/Images/detach_debuger.png"/>
2022-04-24 13:32:11 +07:00
## Check build time in Xcode
2022-04-24 13:34:29 +07:00
Enter below code in your terminal, be sure to **restart Xcode** after enter this code and **Command + B**
2022-04-24 13:32:11 +07:00
2022-04-24 13:34:29 +07:00
```shell
2022-04-24 13:32:11 +07:00
defaults write com.apple.dt.Xcode ShowBuildOperationDuration YES
```
<img src = "https://github.com/jphong1111/awesome-ios-developer/blob/main/Images/show_build_time.png"/>
# BDD
2021-07-01 11:05:40 +07:00
2021-08-21 16:00:40 +07:00
<img src="https://github.com/jphong1111/awesome-ios-developer/blob/main/Images/BDDvsTDD.png" width="70%" height="70%"/>
2021-08-21 15:57:39 +07:00
2021-07-07 11:28:49 +07:00
BDD improves communication between tech and non-tech teams and stakeholders. In BDD, tests are more user-focused and based on the systems behavior.
2021-07-07 11:27:01 +07:00
**Behavior Driven Development**
- Encouraging collaboration across roles to build shared understanding of the problem to be solved
- Working in rapid, small iterations to increase feedback and the flow of value
- Producing system documentation that is automatically checked against the systems behaviour
## Three Steps(Iterative) in BDD
2021-07-07 11:27:01 +07:00
First, take a small upcoming change to the system a User Story and talk about concrete examples of the new functionality to explore, discover and agree on the details of whats expected to be done.
Next, document those examples in a way that can be automated, and check for agreement.
Finally, implement the behaviour described by each documented example, starting with an automated test to guide the development of the code.
2021-08-21 15:59:48 +07:00
- [Behaviour-Driven Development](https://cucumber.io/docs/bdd/)
- [What is BDD? An Introduction to Behavioral Driven Development](https://blog.testlodge.com/what-is-bdd/)
- [The WHY Behind the Code: BDD vs. TDD](https://saucelabs.com/blog/a-two-minute-bdd-overview)
# Code Coverage
2021-05-30 06:18:25 +07:00
Before start your Testing, add coverage will be a good option to show the result of test
2021-05-14 17:33:02 +07:00
First, check code coverage
2021-05-14 17:30:52 +07:00
<img src ="https://github.com/jphong1111/awesome-ios-developer/blob/main/Images/addCoverage1.png"/>
2021-05-14 17:30:52 +07:00
2021-05-14 17:33:02 +07:00
Then, go to **EDIT SHEME**, check like this
<img src ="https://github.com/jphong1111/awesome-ios-developer/blob/main/Images/addCoverage2.png"/>
2021-05-14 17:30:52 +07:00
# Integration Testing
2021-07-10 22:51:22 +07:00
2021-07-19 09:48:04 +07:00
[Integration Testing Swift by Sundell](https://www.swiftbysundell.com/articles/integration-tests-in-swift/)
2021-07-10 22:51:22 +07:00
# Unit Testing
2021-05-07 15:10:24 +07:00
2021-07-19 09:48:04 +07:00
[Unit Testing Swift by Sundell](https://www.swiftbysundell.com/basics/unit-testing/)
2021-06-23 14:34:17 +07:00
2021-07-10 22:51:22 +07:00
2021-09-11 21:32:59 +07:00
📚📚 Recommend Book 📚📚
| Book Name | Authors Name |
| :----------- | :----------- |
| iOS Unit Testing by Example | Jon Reid |
2021-06-23 14:34:17 +07:00
# UI Testing
2021-04-23 14:19:47 +07:00
UI Testing, also known as GUI Testing is basically a mechanism meant to test the aspects of any software that a user will come into contact with. This usually means testing the visual elements to verify that they are functioning according to requirements in terms of functionality and performance. UI testing ensures that UI functions are bug-free.
2021-09-23 22:50:09 +07:00
- [UI Testing: A Detailed Guide](https://www.browserstack.com/guide/ui-testing-guide)
- [Your first UITest in Swift](https://uxdesign.cc/your-first-uitest-in-swift-847bc5595c26)
## Robot Testing
Robot testing is a test design pattern that makes you to create stable, readable, and maintainable tests.
<img src ="https://github.com/jphong1111/awesome-ios-developer/blob/main/Images/robot_testing.png"/>
2022-07-20 08:49:45 +07:00
- [Robot Pattern Testing for XCUITest](https://www.capitalone.com/tech/software-engineering/robot-pattern-testing-for-xcuitest/)👍
- [Testing Robots- JAKE WHARTON](https://jakewharton.com/testing-robots/)
- [Robot Testing Pattern - Overview](https://www.youtube.com/watch?v=ykM9AiYtCz4&ab_channel=HandstandTechnologies)
2021-09-23 22:50:09 +07:00
## Snapshot Testing
2023-02-24 05:51:13 +07:00
Snapshot Testing is a testing technique that can be used in Swift (and other programming languages) to test the user interface (UI) of an application.
2021-09-23 22:50:09 +07:00
2023-02-24 05:51:13 +07:00
In Snapshot Testing, a snapshot of the UI is taken and compared to a previously saved snapshot to check if any changes have been made. This technique can be used to ensure that changes to the UI do not break the existing functionality of the application.
2021-09-23 22:50:09 +07:00
2023-02-24 05:51:13 +07:00
### Environment Variable
With using Environment Variable in Xcode, we can directly re-capture failing snapshot test cases
<img src ="https://github.com/jphong1111/awesome-ios-developer/blob/main/Images/env_variable.png"/>
SNAPSHOT_TESTING = YES
2021-09-23 22:50:09 +07:00
2021-09-23 22:50:09 +07:00
2021-06-23 14:34:17 +07:00
## TestFlight
TestFlight makes it easy to invite users to test your apps and App Clips and collect valuable feedback before releasing your apps on the App Store.
- [TestFlight Apple](https://developer.apple.com/testflight/)
2022-02-17 12:38:58 +07:00
# CI/CD
2021-06-09 00:29:03 +07:00
2021-08-30 09:47:10 +07:00
CI and CD stand for continuous integration and continuous delivery/continuous deployment
2021-06-09 00:29:03 +07:00
2021-08-30 09:47:10 +07:00
- [Why is CI/CD important?](#https://www.synopsys.com/glossary/what-is-cicd.html)
- [What is CI/CD? Continuous integration and continuous delivery explained](#https://www.infoworld.com/article/3271126/what-is-cicd-continuous-integration-and-continuous-delivery-explained.html)
- [Whats the difference between agile, CI/CD, and DevOps?](#https://www.synopsys.com/blogs/software-security/agile-cicd-devops-difference/)
2022-02-17 12:23:17 +07:00
## Fastlane
The easiest way to build and release mobile apps.
2022-03-17 14:24:52 +07:00
- [Fastlane](https://fastlane.tools/)
- [fastlane Tutorial: Getting Started](https://www.raywenderlich.com/233168-fastlane-tutorial-getting-started)
2022-02-17 12:23:17 +07:00
<img src ="https://github.com/jphong1111/awesome-ios-developer/blob/main/Images/fastlane.png" />
2021-06-09 00:29:03 +07:00
2021-07-16 14:38:06 +07:00
## Jenkins
2022-02-17 12:23:17 +07:00
Jenkins is most popular CI/CD tools
2021-07-16 14:38:06 +07:00
[Jenkins](https://www.jenkins.io/)
2021-07-29 01:17:12 +07:00
## Jira
2021-08-23 03:53:55 +07:00
Jira is project management software first and foremost, but it began its life in 2002 as an issue tracking platform for software developers
2021-07-29 01:17:12 +07:00
2021-08-23 03:53:55 +07:00
- [Jira](https://www.atlassian.com/software/jira)
- [What is Jira used for?](https://www.atlassian.com/software/jira/guides/use-cases/what-is-jira-used-for#Jira-for-requirements-&-test-case-management)
- [What Is Jira: An Overview of a Unique Project Management Tool](https://www.fool.com/the-blueprint/what-is-jira/)
2021-07-29 01:17:12 +07:00
2021-08-06 01:56:00 +07:00
## CircleCI
2021-08-06 21:54:59 +07:00
[CircleCI](https://circleci.com/)
2021-08-06 01:56:00 +07:00
2021-10-05 22:42:32 +07:00
You can integrate Circle CI into Github repo, therefore we can use it in PR.
2022-03-10 04:44:17 +07:00
## Danger
[Danger](https://github.com/danger/danger)
- Danger runs after your CI, automating your team's conventions surrounding code review.
- This provides another logical step in your process, through this Danger can help lint your rote tasks in daily code review.
- You can use Danger to codify your team's norms, leaving humans to think about harder problems.
2021-10-05 22:42:32 +07:00
## Codemagic
2021-08-09 10:32:58 +07:00
[Codemagic](https://codemagic.io/) - Build, test and deliver your mobile projects 20% faster.
2021-07-29 01:17:12 +07:00
2021-08-30 09:47:10 +07:00
## Xcode Cloud
2021-07-29 01:17:12 +07:00
2021-08-30 09:47:10 +07:00
[WWDC21](https://www.apple.com/apple-events/june-2021/?&cid=wwa-us-kwgo-features-slid--Brand-AppleLive-Post-&mtid=20925e1t39169&aosid=p238&mnid=sZH3E0Pf0-dc_mtid_20925e1t39169_pcrid_524281987644_pgrid_129696028064_) Apple released [Xcode Cloud](https://developer.apple.com/xcode-cloud/) for continuous integration
For more info, go to [Apple Developer Website](https://developer.apple.com/documentation/Xcode/Xcode-Cloud)
<p align="right">
<a href="#-content">Back to Content</a>
</p>
2021-07-16 14:38:06 +07:00
2022-02-17 12:40:22 +07:00
# Tuist
2022-02-17 12:38:58 +07:00
- Tuist is a command line tool that helps you generate, maintain and interact with Xcode projects.
- [Tuist](https://docs.tuist.io/tutorial/get-started)
- [Tuist Github](https://github.com/tuist/tuist)
- [Tuist Tutorial for Xcode](https://www.raywenderlich.com/24508362-tuist-tutorial-for-xcode)
2022-02-17 12:40:22 +07:00
# In App Purchase(IAP)
2021-05-21 10:16:54 +07:00
2021-05-26 03:42:26 +07:00
**Requirement**
2021-05-21 10:16:54 +07:00
2021-05-25 23:15:49 +07:00
- Full Apple Developoment Program($99)
- Physical IPhone Device to test IAP
> **Simulator can not test IAP!!**
2021-05-26 03:42:26 +07:00
## Paywall
2021-05-25 23:15:49 +07:00
2021-06-21 15:41:47 +07:00
<img src ="https://github.com/jphong1111/awesome-ios-developer/blob/main/Images/paywall.jpeg" />
2021-05-25 23:15:49 +07:00
Paywall is a way to restrict access to their information so that only paying users can use it.
2021-05-27 11:01:12 +07:00
Lots of developer recommend 80% - (Paywall) - 20%
2021-05-26 03:42:26 +07:00
## Set Up
TBD
For more info about getting start of IAP, go [here](https://www.raywenderlich.com/5456-in-app-purchase-tutorial-getting-started) 📑
2021-06-21 15:39:43 +07:00
<p align="right">
<a href="#-content">Back to Content</a>
</p>
2021-06-11 14:56:44 +07:00
## Notification
2021-06-21 15:39:43 +07:00
- Notifications are an integral way of conveying information to the user outside of an app.
- Notifications can be either local or remote. The app on the device schedules and configures local notifications. In contrast, a server sends remote notifications using Apple Push Notification Service (APNS)
- You can configure both local and remote notifications using the UserNotifications framework.
2021-06-11 14:56:44 +07:00
## Local Notification
2021-06-21 15:39:43 +07:00
- [Local Notifications: Getting Started](https://www.raywenderlich.com/21458686-local-notifications-getting-started)
- [Swift Local Notification All-In-One](https://itnext.io/swift-local-notification-all-in-one-ee6027ea6e3)
2021-06-25 23:16:57 +07:00
If you set repeatation **less than 60 sec**, it will cause ERROR!
<img src ="https://github.com/jphong1111/awesome-ios-developer/blob/main/Images/Repeatation_Error.png"/>
2021-06-21 15:39:43 +07:00
<p align="right">
<a href="#-content">Back to Content</a>
</p>
2021-06-11 14:56:44 +07:00
## Remote Notification
2021-05-29 03:15:35 +07:00
## APNs
2021-05-21 10:16:54 +07:00
APNS stands for **Apple Push Notification service**
2021-06-21 15:39:43 +07:00
## APNs Setting
First, go to **Signing & Capabilities** and add two features like this
2021-06-21 15:41:47 +07:00
<img src = "https://github.com/jphong1111/awesome-ios-developer/blob/main/Images/apsn_Setting.png"/>
2021-06-21 15:39:43 +07:00
2021-05-30 14:39:10 +07:00
## APNs Usage
2021-06-21 15:39:43 +07:00
2021-09-02 02:02:31 +07:00
- [Push Notifications Tutorial: Getting Started](https://www.raywenderlich.com/11395893-push-notifications-tutorial-getting-started)
2021-05-29 03:15:35 +07:00
2021-09-02 13:02:29 +07:00
2021-05-21 10:55:16 +07:00
## FRP
2021-05-28 12:45:01 +07:00
Functional Reactive Programming
## Rxswift
2021-06-08 03:25:16 +07:00
- [RxSwift raywenderlich](https://www.raywenderlich.com/books/rxswift-reactive-programming-with-swift/v4.0)
- [RxSwift](https://github.com/ReactiveX/RxSwift) - Github Repository
- [RxSwift](http://reactivex.io/intro.html) - Website
2021-06-04 03:10:45 +07:00
2021-08-20 22:39:32 +07:00
📚📚 Recommend Book 📚📚
| Book Name | Authors Name |
| :----------- | :----------- |
| RxSwift: Reactive Programming with Swift | raywenderlich Tutorial Team |
2021-06-04 03:22:19 +07:00
<p align="right">
<a href="#-content">Back to Content</a>
</p>
2021-05-28 12:45:01 +07:00
## Combine
2021-06-01 23:21:08 +07:00
Combine released on iOS13 from Apple for Functional Reactive Programming.
2021-05-28 12:45:01 +07:00
[Swiftbysundell](https://www.swiftbysundell.com/basics/combine/)
2021-05-21 10:16:54 +07:00
2021-08-20 22:39:32 +07:00
📚📚 Recommend Book 📚📚
| Book Name | Authors Name |
| :----------- | :----------- |
2021-08-30 13:21:58 +07:00
| Combine: Asynchronous Programming with Swift | raywenderlich Tutorial Team |
2021-08-06 01:56:00 +07:00
## RxCombine
RxCombine provides bi-directional type bridging between RxSwift and Apple's Combine framework.
[RxCombine](https://github.com/CombineCommunity/RxCombine)
2022-02-17 12:40:22 +07:00
# Security
2021-06-04 02:35:13 +07:00
2021-06-04 03:04:18 +07:00
Security secure the data your app manages, and control access to your app.
Check below for more detail about iOS Security as well as Application security
- [Introduction to Apple platform security](https://support.apple.com/ko-kr/guide/security/seccd5016d31/web)
- [iOS Security](https://www.cse.wustl.edu/~jain/cse571-14/ftp/ios_security/index.html)
- [Apple Developer Doc about Security](https://developer.apple.com/documentation/security)
- [iOS App Security: Best Practices](https://quickbirdstudios.com/blog/ios-app-security-best-practices/)
2021-06-04 03:22:19 +07:00
<p align="right">
<a href="#-content">Back to Content</a>
</p>
2021-06-04 02:35:13 +07:00
## Checklist For App Security
2021-06-04 02:42:38 +07:00
- [ ] Keychain For Sensitive Data Storage
2021-06-04 03:04:18 +07:00
- [ ] Application Transport Security Layer(TSL)
2021-06-04 02:42:38 +07:00
- [ ] SSL Pinning
- [ ] Jailbroken Device Check
- [ ] Disable Debug Logs
- [ ] Third-Party Library Usage Check
- [ ] Code Obfuscation
- [ ] Cryptography
- [ ] Biometric Access
2021-06-04 02:35:13 +07:00
## Keychain
2021-07-30 15:44:15 +07:00
- [Storing Keys in the Keychain](https://developer.apple.com/documentation/security/certificate_key_and_trust_services/keys/storing_keys_in_the_keychain)
- [Keychain raywenderlich](https://www.raywenderlich.com/9240-keychain-services-api-tutorial-for-passwords-in-swift)
2021-06-04 03:04:18 +07:00
2021-06-04 02:42:38 +07:00
## SSL Pinning
2021-06-05 00:48:44 +07:00
<img src = "https://github.com/jphong1111/awesome-ios-developer/blob/main/Images/SSLCertificate.png"/>
2021-06-04 23:46:28 +07:00
When a mobile app communicates with a server, it uses SSL(Secure Socket Layer) pinning technique for protecting the transmitted data against tampering and eavesdropping.
2021-06-04 03:04:18 +07:00
2021-06-04 23:42:54 +07:00
- [Preventing Man-in-the-Middle Attacks in iOS with SSL Pinning](https://www.raywenderlich.com/1484288-preventing-man-in-the-middle-attacks-in-ios-with-ssl-pinning)
- [How to Perform SSL Pinning in iOS Apps](https://appinventiv.com/blog/ssl-pinning-in-ios-app/)
2021-06-04 23:40:21 +07:00
2021-06-05 00:43:03 +07:00
## How SSL Works
2021-06-04 23:40:21 +07:00
1. A browser attempts to connect with a website which is secured with a SSL. The browser then requests the web server to identify itself.
2. Web server then sends the browser its SSL certificate copy.
3. The browser checks if the SSL certificate must be trusted. If it can be, a message is sent to the web server.
4. Web server then sends back an acknowledgement to begin the SSL encrypted session.
5. The encrypted data is then finally shared between the browser and web server.
2021-06-05 00:43:03 +07:00
## SSL pinning methods
2021-06-04 23:40:21 +07:00
- Pin the certificate you can download the servers certificate and bundle them in the app. At the runtime, the app compares the server certificate to ones that you have embedded.
- Pin the public key you can retrieve the public key of certificate in the code as string. At the runtime, the application compared the certificates public key to one which is hard-coded in the code.
2021-06-04 23:46:28 +07:00
2021-06-05 00:43:03 +07:00
## Using URLSession
2021-06-04 23:48:31 +07:00
2021-06-04 23:46:28 +07:00
```swift
func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
if (challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust) {
if let serverTrust = challenge.protectionSpace.serverTrust {
var secresult = SecTrustResultType.invalid
let status = SecTrustEvaluate(serverTrust, &secresult)
if (errSecSuccess == status) {
if let serverCertificate = SecTrustGetCertificateAtIndex(serverTrust, 0) {
let serverCertificateData = SecCertificateCopyData(serverCertificate)
let data = CFDataGetBytePtr(serverCertificateData);
let size = CFDataGetLength(serverCertificateData);
let cert1 = NSData(bytes: data, length: size)
let file_der = Bundle.main.path(forResource: "name-of-cert-file", ofType: "cer")
if let file = file_der {
if let cert2 = NSData(contentsOfFile: file) {
if cert1.isEqual(to: cert2 as Data) { completionHandler(URLSession.AuthChallengeDisposition.useCredential, URLCredential(trust:serverTrust))
return
}
}
}
}
}
}
}
// Pinning failed completionHandler(URLSession.AuthChallengeDisposition.cancelAuthenticationChallenge, nil)
}
```
2021-06-04 23:40:21 +07:00
2021-06-05 00:43:03 +07:00
## Using Alamofire 5
2021-06-04 23:48:31 +07:00
2021-06-05 00:38:58 +07:00
If you are using above version, this code should be changed
[More Info](https://devgenes.com/posts/SSL-Pinning-With-Alamofire/)
First, Download SSL certificate to your project folder
2021-06-05 00:44:33 +07:00
> https://www.yourdomain.com (NOT IN THIS WAY)
2021-06-05 00:38:58 +07:00
```bash
openssl s_client -showcerts -connect yourdomain.com:443 < /dev/null | openssl x509 -outform DER > yourdomain.cer
```
Make a SessionManager to get SSL Pinning
2021-06-04 23:48:31 +07:00
2021-06-05 00:38:58 +07:00
```swift
2021-06-04 23:48:31 +07:00
2021-06-05 00:38:58 +07:00
let sessionManager: SessionManager = {
let serverTrustPolicies: [String: ServerTrustPolicy] = ["yourdomain.com": .pinCertificates(certificates: ServerTrustPolicy.certificates(),
validateCertificateChain: true,
validateHost: true)]
return SessionManager(serverTrustPolicyManager: ServerTrustPolicyManager(policies: serverTrustPolicies))
}()
```
2021-06-04 23:48:31 +07:00
2021-06-05 00:38:58 +07:00
request from sessionManager, if it is invalid, print error
2021-06-04 23:48:31 +07:00
2021-06-05 00:38:58 +07:00
```swift
sessionManager.request("https://yourdomain.com").responseString { (dataResponse) in
switch dataResponse.result {
case .failure(let err):
print(err)
case .success(let val):
print(val)
if let headerFields = dataResponse.response?.allHeaderFields {
print(headerFields)
}
}
}
2021-06-04 23:48:31 +07:00
```
2021-06-04 03:04:18 +07:00
### Relative Stuff
2021-06-04 02:51:16 +07:00
TrustKit makes it easy to deploy SSL public key pinning
[TrustKit](https://github.com/datatheorem/TrustKit)
2021-06-04 02:44:25 +07:00
## Code Obfuscation
2021-06-07 11:08:08 +07:00
Code obfuscation is the act of deliberately obscuring source code, making it very difficult for humans to understand, and making it useless to hackers who may have ulterior motives.
2021-06-04 02:42:38 +07:00
## Cryptography
2021-07-13 16:02:59 +07:00
[Introducing Swift Crypto](https://swift.org/blog/crypto/)
2021-06-04 02:42:38 +07:00
## Biometric Access
2021-06-04 02:35:13 +07:00
2021-06-08 03:05:50 +07:00
Apple made a big change when it released the iPhone X: It ditched Touch ID fingerprint security for a new face-based biometric sign-on tool called Face ID. The fingerprint scanner on most post-iPhone X Apple products is gone, and in its place is a new camera array capable of capturing a face map that is, according to Apple, 20 times less likely to be hacked than a Touch ID fingerprint.
2021-06-08 01:10:34 +07:00
2021-06-08 03:05:50 +07:00
[Apple's Face ID: Cheat sheet](https://www.techrepublic.com/article/apples-face-id-everything-iphone-x-users-need-to-know/)
2021-06-08 01:10:34 +07:00
2021-06-08 03:05:50 +07:00
## Face ID & Touch ID
2021-06-08 01:10:34 +07:00
2021-06-08 03:05:50 +07:00
To use Face ID, Add **Privacy - Face ID Usage Description** into your info.plist file in your project
2021-06-08 03:10:20 +07:00
<img src = "https://github.com/jphong1111/Useful_Swift/blob/main/Images/FaceID_Info.png" width = "50%" height = "50%"/>
2021-06-08 03:09:04 +07:00
2021-06-08 03:05:50 +07:00
import LocalAuthentication, which can allow you to implement Biometric Access
```swift
import LocalAuthentication
```
After that, using LAContext() we can implement Face ID
Here are simple example that how Face ID can impelement
```swift
@IBAction private func isTouched(_ sender: UIButton!) {
let context = LAContext()
var error: NSError? = nil
if context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error) {
let reason = "touch id"
context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: reason) { [weak self](success, error) in
DispatchQueue.main.async {
guard success, error == nil else {
// If Fail
let alert = UIAlertController(title: "FAceID Fail", message: "error", preferredStyle: .alert)
let action = UIAlertAction(title: "cancle", style: .cancel, handler: nil)
alert.addAction(action)
self?.present(alert, animated: true, completion: nil)
return
}
// If success
let vc = UIViewController()
vc.title = "hi"
vc.view.backgroundColor = .blue
self?.present(vc, animated: true, completion: nil)
}
}
} else {
// If device is not supporting Face ID
}
}
```
> Error Handling is your own part
**You are GOOD TO GO** 👏👏👏
2021-07-09 14:01:18 +07:00
<p align="right">
<a href="#-content">Back to Content</a>
</p>
## Objective-C
Still we need to study Objective-C for legacy code which is still remain in our project!
Here are some useful website that you can study about simple concept of Obj-C!!
[Learn Objective-C in 24 Days](https://www.binpress.com/learn-objective-c-24-days/)
2021-08-20 22:39:32 +07:00
📚📚 Recommend Book 📚📚
| Book Name | Authors Name |
| :----------- | :----------- |
| Objective-C Programming: The Big Nerd Ranch Guide | Aaron Hillegass, Mikey Ward |
2021-07-13 16:16:38 +07:00
### Pure Swift Application?
Can we really say "Our application is built with pure Swift"?. NO! Lots of Objective-C codes are running in the background to built swift.
Here is a example that you can try
**Simply create a pure swift application and use this lines in debug console!!**
2021-07-13 11:09:18 +07:00
```swift
break set -r "-\[.*\]"
break set -r DebugMode
break set -r Emoji
```
2021-07-13 16:16:38 +07:00
Use one of above line when you want to find out how many Objective-C codes are consist in simple pure swift application!!
2021-07-13 11:09:18 +07:00
2021-07-13 16:16:38 +07:00
<img src="https://github.com/jphong1111/awesome-ios-developer/blob/main/Images/ObjcBreakPoint.png" />
2021-07-13 11:09:18 +07:00
2021-07-12 10:37:45 +07:00
<p align="right">
<a href="#-content">Back to Content</a>
</p>
2021-07-09 14:01:18 +07:00
## Bridging Header
Bridging header means access classes and other declarations from your Objective-C code in Swift.
[Importing Objective-C into Swift Apple Documentation](https://developer.apple.com/documentation/swift/imported_c_and_objective-c_apis/importing_objective-c_into_swift)
2021-06-08 03:05:50 +07:00
<p align="right">
<a href="#-content">Back to Content</a>
</p>
2021-06-08 01:10:34 +07:00
# Error Search
2021-05-24 03:37:34 +07:00
2021-05-24 03:52:46 +07:00
Find your common error here
[Error Search](https://github.com/jphong1111/Useful_Swift/blob/error-search/README.md)
2021-05-24 03:37:34 +07:00
# Useful Stuff
2021-04-23 14:19:47 +07:00
2021-06-04 03:22:19 +07:00
I listed some of the useful & interesting stuff related with Swift
<p align="right">
<a href="#-content">Back to Content</a>
</p>
## Useful Blogs for iOS Developers
Here are the useful blog list which you can get references & knowledges about iOS development
- [SwiftLee](https://www.avanderlee.com/) 👍
- [Apple Developer](https://developer.apple.com/videos/) Find recent technique with videos and example codes!!
2022-05-26 11:39:53 +07:00
- [appinventiv](https://appinventiv.com/blog/) Including iOS and others!!
- Continue adding lists...
2021-06-01 08:51:20 +07:00
## How to submit your app to the AppStore
2021-06-09 23:52:07 +07:00
- [Publishing to AppStore](https://codewithchris.com/submit-your-app-to-the-app-store/#apple-developer-program)
- [StoreKit](https://developer.apple.com/documentation/storekit)
2021-06-19 03:50:07 +07:00
- [What is a provisioning profile & code signing in iOS?](https://abhimuralidharan.medium.com/what-is-a-provisioning-profile-in-ios-77987a7c54c2)
2021-10-13 00:22:06 +07:00
## iOS Version Adoption Tracker
You can check the iOS Version adoption in this site
2023-03-03 09:54:00 +07:00
[iOS Version Adoption Tracker](https://mixpanel.com/trends/#report/ios_16)
2021-10-13 00:22:06 +07:00
2023-03-03 09:54:00 +07:00
<img src="https://github.com/jphong1111/awesome-ios-developer/blob/main/Images/iOS16_adoption.png" />
2021-10-13 00:22:06 +07:00
<p align="right">
<a href="#-content">Back to Content</a>
</p>
2021-06-12 13:05:53 +07:00
## Online Swift Playground
2021-06-12 13:04:31 +07:00
2021-06-12 13:05:53 +07:00
[SwiftPlayground](http://online.swiftplayground.run/) - Online Swift Playground
2021-06-12 13:04:31 +07:00
2021-06-01 08:51:20 +07:00
## Show Preview in UIKit(Build UI with Code Base) 👍 👍 👍 👍 👍
2021-04-23 14:25:02 +07:00
2022-04-27 11:19:18 +07:00
[Inject (3rd Party Library)](https://github.com/krzysztofzablocki/Inject)
2021-04-23 14:25:02 +07:00
Copy this code and Paste into your controller
2021-04-23 14:19:47 +07:00
```swift
2021-05-05 01:37:42 +07:00
#if canImport(SwiftUI) && DEBUG
2021-04-23 14:19:47 +07:00
import SwiftUI
2021-05-05 01:37:42 +07:00
struct SwiftLeeViewRepresentable: UIViewRepresentable {
func makeUIView(context: Context) -> UIView {
return UIStoryboard(name: "Main", bundle: Bundle.main).instantiateInitialViewController()!.view
2021-04-23 14:19:47 +07:00
}
2021-05-05 01:37:42 +07:00
func updateUIView(_ view: UIView, context: Context) {
2021-04-23 14:19:47 +07:00
}
}
2021-05-05 01:37:42 +07:00
@available(iOS 13.0, *)
struct SwiftLeeViewController_Preview: PreviewProvider {
2021-04-23 14:19:47 +07:00
static var previews: some View {
2021-05-05 01:37:42 +07:00
SwiftLeeViewRepresentable()
2021-04-23 14:19:47 +07:00
}
}
2021-05-05 01:37:42 +07:00
#endif
2021-04-23 14:19:47 +07:00
```
2021-04-23 14:25:02 +07:00
2021-06-05 22:39:59 +07:00
2021-04-23 14:25:02 +07:00
Enable canvas option like this
2021-11-19 07:26:09 +07:00
<img src="https://github.com/jphong1111/Useful_Swift/blob/main/Images/preview%20using%20canvas.png">
<img src="https://github.com/jphong1111/Useful_Swift/blob/main/Images/preivew_screenShot.png">
**You are GOOD TO GO** 👏👏👏
## Compare Changes in Swift Version
You can compare changes based on Swift Verison
[Whatsnewinswift](https://www.whatsnewinswift.com/?from=5.3&to=5.4)
## Managing Xcode Space
This will be helful when you are running out of storage in your mac
```bash
# 1
echo "Removing Derived Data..."
rm -rf ~/Library/Developer/Xcode/DerivedData/
# 2
echo "Removing Device Support..."
rm -rf ~/Library/Developer/Xcode/iOS\ DeviceSupport
rm -rf ~/Library/Developer/Xcode/watchOS\ DeviceSupport
rm -rf ~/Library/Developer/Xcode/tvOS\ DeviceSupport
# 3
echo "Removing old simulators..."
xcrun simctl delete unavailable
# 4
echo "Removing caches..."
rm -rf ~/Library/Caches/com.apple.dt.Xcode
rm -rf ~/Library/Caches/org.carthage.CarthageKit
# 5
if command -v pod &> /dev/null
then
# 6
pod cache clean --all
fi
echo "Done!"
```
After writing, run it with this command
```bash
chmod u+x clean-xcode.sh
```
And then
```script
./clean-xcode.sh
```
**This will cleans out derived data, device support, simulators and caches. So that once you execute it, You have to build your project AGAIN**
For More Info, visit [here](https://www.raywenderlich.com/19998365-understanding-and-managing-xcode-space)
<p align="right">
<a href="#-content">Back to Content</a>
</p>
## Roadmap for iOS Developer
check this out [here](https://github.com/BohdanOrlov/iOS-Developer-Roadmap)
## Use VIM in Xcode
2022-03-03 05:23:21 +07:00
Check [this](https://www.twilio.com/blog/2017/06/adding-vim-keybindings-to-xcode-with-xvim.html) site for more info!
2021-11-19 07:26:09 +07:00
2022-03-03 05:23:21 +07:00
~~Since Xcode 13(BETA), you can find Vim in **Preference -> Text Editing -> Editing -> Enable Vim Key bindings**~~
this feature deprecated in Xcode 13(BETA)
2021-11-19 07:26:09 +07:00
<img src="https://github.com/jphong1111/Useful_Swift/blob/main/Images/Vim.png">
## Write README.md
[how-to-write-a-readme](https://medium.com/@saumya.ranjan/how-to-write-a-readme-md-file-markdown-file-20cb7cbcd6f) will help you to write a README.md file more dynamically 👍
Also you can edit Readme.md file with VSCode Extension! Check out in VSCode!
[Markdown Preview Enhanced](https://github.com/shd101wyy/markdown-preview-enhanced)
<p align="right">
<a href="#-content">Back to Content</a>
</p>
# ❤ Supporters
2021-11-19 07:26:09 +07:00
## ⭐ Stargazers
2021-11-19 07:26:09 +07:00
<a href="https://github.com/jphong1111/awesome-ios-developer/stargazers">
<img src="https://reporoster.com/stars/jphong1111/awesome-ios-developer"></a>
## 🍴 Forks
2021-11-19 07:26:09 +07:00
<a href="https://github.com/jphong1111/awesome-ios-developer/fork">
<img src="https://reporoster.com/forks/jphong1111/awesome-ios-developer"></a>
## 🌟 GitHub Stargazers
2021-11-19 07:26:09 +07:00
[![Stargazers over time](https://starchart.cc/jphong1111/useful_swift.svg)](https://starchart.cc/jphong1111/awesome-ios-developer)
## Author
This README.md file is written by **Jungpyo Hong (Dennis)**
email: ghdwjdvy96@gmail.com
<p align="right">
<a href="#-content">Back to Content</a>
</p>