You may directly use
replacingOccurrences (that removes all non-overlapping matches from the input string) with [^A-Za-z0-9]+ pattern:let str = "_<$abc$>_"
let pattern = "[^A-Za-z0-9]+"
let result = str.replacingOccurrences(of: pattern, with: "", options: [.regularExpression])
print(result) // => abc
link here -> https://stackoverflow.com/a/52052465/8366535In my case
if let newString = textInput.text {
let pattern = "[^A-Za-z0-9]+"
let result = newString.replacingOccurrences(of: pattern, with: "", options: [.regularExpression])
if result != "" {
print(result)
}
}
2. Set Image in swift 5.1
if #available(iOS 13.0, *) { // Use image by system imageview.image = UIImage(systemName: "bolt.slash", withConfiguration: .none) } else { // Use image by custom imageview.image = #imageLiteral(resourceName: "name_icon"}
3. How to set action after navigate back "backBarButtonItem"
this example for navigation back to set action after back first viewController without use "leftBarButtonItem"
in firstViewControllers :
import UIKit class FirstViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .plain, target: self, action: nil) } @IBAction func handleButton(_ sender: Any) { navigationController?.pushViewController(EventKitViewController(), animated: true) } }
in secondViewController.
import UIKit
class SecondViewController: UIViewController, UINavigationControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
navigationController?.delegate = self
}
func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) {
if viewController.isKind(of:EvenKitViewController.self) {
print("After Back to first controller you can navigate to another process and set here")
navigationController.pushViewController(AnimationScanningViewController(), animated: true)
}
}
}
4. Realm Error "Cannot convert value of type 'Bool' to expected dictionary value type 'String' "
in terminal: pod update
//Change update type
from:
update: true
to :
update: .modified
3.20.0 -> update 4.0.0


5. PropertyWarpper In Swift 5.1
PropertyWarpper introduces in swift 5.1, make your code less than before
source how to use that :
- https://medium.com/better-programming/create-the-perfect-userdefaults-wrapper-using-property-wrapper-42ca76005ac8
- https://medium.com/better-programming/swift-property-delegates-powerful-new-annotations-attributes-system-2e3968b29624
- https://medium.com/better-programming/property-wrappers-in-swift-657bead85501
simple use
//create
@propertyWrapper
struct myProperty {
private let print = ""
}
//call
@myProperty static var naem: String?
6. GitZip Extention for GitHub

- Download just for those few dirs/files you need instead of whole project.
- Choose more than one dirs/files.- Just double click on items and click download button.
https://chrome.google.com/webstore/detail/gitzip-for-github/ffabmkklhbepgcgfonabamgnfafbdlkn
7. IOS 13 Does the Apple iPhone 6s have NFC ?
I try to develop NFC use iPhone 6s, but not working, that error because iPhone 6 will never be able to read NFC tags either with or without an App. error in debug area I found.
2019-11-16 15:10:04.396302+0700 100DayOfCode[7504:2523821]
[CoreNFC] 00000002 83719380 -[NFCNDEFReaderSession beginSession]:318
error:Error Domain=NFCError Code=202 "Session invalidated unexpectedly"
UserInfo={NSLocalizedDescription=Session invalidated unexpectedly},
errorCode: 0xca
Error reading NFC: Session invalidated unexpectedly
source: https://learn.seritag.com/nfc-enabled-phones/apple-iphone-6s
8. Image system resize swift 5.1(xcode 11), use in TabbatItem and ImageView
Resize use image system in Xcode 11 example:
let scale = UIImage.SymbolConfiguration(pointSize: 12)
let scaleImage = UIImage(systemName: "qrcode.viewfinder", withConfiguration: scale)
// use in tabbar
mid.tabBarItem = UITabBarItem(title: "", image: scaleImage?.withRenderingMode(.alwaysTemplate), tag: 1)
// use in UIImage
imageVIew.image = scaleImage
9. UserDefault use suite
The power of UserDefault in swift, this time example for using group in userDefault make really simple to add object and remove it.
- create group = UserDefaults.init(suiteName: "name_groups") .
- add object = UserDefaults.init(suiteName: "name_groups").set(Object, forkey: "key") .
- call object = UserDefaults.init(suiteName: "name_groups").object(forkey: "key)" .
- remove single object = UserDefaults.init(suiteName: "name_groups").removeObject(forkey: "key") .
- remove all object in group = UserDefaults.init(suiteName: "name_groups").removePersistentDomain(forName: "name_group")
import UIKit
struct Default {
static let suite = UserDefaults.init(suiteName: "groups.luffy.app")
static let _s = UserDefaults.standard
}
class AddSuiteViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
Default.suite?.set("haha", forKey: "key1")
Default.suite?.set("wkwkk", forKey: "key2")
Default.suite?.set("hehehe", forKey: "key3")
Timer.scheduledTimer(withTimeInterval: 5, repeats: true) { _ in
print(
Default.suite?.object(forKey: "key1"),
Default.suite?.object(forKey: "key2"),
Default.suite?.object(forKey: "key3")
)
Timer.scheduledTimer(withTimeInterval: 2, repeats: false) { _ in
Default.suite?.removeObject(forKey: "key1") // remove single object
Default._s.removePersistentDomain(forName: "groups.luffy.app") // remove all object in group
}
}
}
}
https://medium.com/swift-india/userdefaults-under-the-hood-457461c8d262
https://www.swiftbysundell.com/articles/the-power-of-userdefaults-in-swift/
Comments