9 Notes In May 2020
1. Error "Use of unresolved identifier 'YourFile.swift' "
Image 1.0
If you have error like "Use of unresolved identifier" check in tab Show identifier inspektor in Target membership and checklist that for fixing this error.
2. etc host setting on mac
source: https://setapp.com/how-to/edit-mac-hosts-file
2. etc host setting on mac
sudo nano /etc/hosts
Password:: ********
------------ Example -------------
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
127.158.111.11 dirve-dave.me.com
127.158.121.10 koffice-dev.me.com
------------------------
ctrl+0 save
ctrl+x exit
source: https://setapp.com/how-to/edit-mac-hosts-file
3. Custom Limit TagsListView
I try to limit tags list in TagListView.swift
for max is 4 tags, set in below onLongPress
source github: https://github.com/ElaWorkshop/TagListView
edit in file: https://github.com/ElaWorkshop/TagListView/blob/master/TagListView/TagListView.swift
I try to limit tags list in TagListView.swift
for max is 4 tags, set in below onLongPress
// On long press, deselect all tags except this one tagView.onLongPress = { [unowned self] this in self.tagViews.forEach { $0.isSelected = $0 == this } } //MARK: FIX ME HERE tagView.onTap = { [unowned self] this in var arrBool = [Bool]() self.tagViews.forEach { if $0.isSelected == true { arrBool.append($0.isSelected) } } if arrBool.count < 5 { self.rearrangeViews() arrBool.removeAll() } else { self.tagViews.forEach { if this == $0 { $0.isSelected = false } } arrBool.removeAll() } }
source github: https://github.com/ElaWorkshop/TagListView
edit in file: https://github.com/ElaWorkshop/TagListView/blob/master/TagListView/TagListView.swift
4. Make navigationBar transparent with extension
source: https://twitter.com/hellalmoussa/status/1270633115031965699?s=21
extension UINavigationBar {
func makeTransparent(withTint tint: UIColor = .white) {
isTranslucent = true
backgroundColor = .clear
barTintColor = .clear
setBackgroundImage(UIImage(), for: .default)
tintColor = tint
titleTextAttributes = [.foregroundColor: tint]
shadowImage = UIImage()
}
}
source: https://twitter.com/hellalmoussa/status/1270633115031965699?s=21
5. Blur image view with extension
extension UIImageView {
func blurred() -> UIImageView {
let imgView = self
let blurEffect = UIBlurEffect(style: UIBlurEffect.Style.dark)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.frame = imgView.bounds
blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
imgView.addSubview(blurEffectView)
return imgView
}
}
6. GIT uncommit PR/MR (Pull Request / Merge Request)
In condition I try to unchange one file to back last commit,
and how to use that look code below.
and how to use that look code below.
git checkout origin/master -- path/to/file // git checkout <local repo name (default is origin)>/<branch name> -- path/to/file will checkout the particular file from the downloaded changes (origin/master). example: ($git checkout your_branch_want_to_change -- path/to/file) $git checkout origin/master -- 100DayOfSwift/Day29_Filter_Limit/LimitFilterViewController.swift
$git add -A $git commit -m "uncommit one file" $git push origin feature/mynewfeature
If condition your PR/MR that can update your commit
source: https://stackoverflow.com/a/28375437/8366535
Image 1.1
source: https://stackoverflow.com/a/28375437/8366535
7. Extension for UIApplication TopViewController
When you want your view controller or popup you call on top all viewcontroller
use this extension.
When you want your view controller or popup you call on top all viewcontroller
use this extension.
import UIKitextension UIApplication {class func topViewController(controller: UIViewController? = UIApplication.shared.keyWindow?.rootViewController) -> UIViewController? {if let navigationController = controller as? UINavigationController {return topViewController(controller: navigationController.visibleViewController)}if let tabController = controller as? UITabBarController {if let selected = tabController.selectedViewController {return topViewController(controller: selected)}}if let presented = controller?.presentedViewController {return topViewController(controller: presented)}return controller}}
8. Found error No such module 'Nimble' or 'Quick'
Try this solution, follow this image below
Try this solution, follow this image below
Image 1.2
Image 1.3
Image 1.4
Build again, for now that can be success, or you can update pod Quick and Nimble
Build again, for now that can be success, or you can update pod Quick and Nimble
9. Extension Constommize UISearchBar (loading)
Make Circle loading in left side
example result test in simulator.
Make Circle loading in left side
extension UISearchBar {public var textField: UITextField? {if #available(iOS 13, *) {return searchTextField}let subViews = subviews.flatMap { $0.subviews }guard let textField = (subViews.filter { $0 is UITextField }).first as? UITextField else {return nil}return textField}var isLoading: Bool {get {return activityIndicator != nil} set {if newValue {if activityIndicator == nil {let newActivityIndicator = UIActivityIndicatorView(style: .gray)newActivityIndicator.color = UIColor.whitenewActivityIndicator.startAnimating()newActivityIndicator.backgroundColor = textField?.backgroundColor ?? UIColor.whitetextField?.leftView?.addSubview(newActivityIndicator)let leftViewSize = textField?.leftView?.frame.size ?? CGSize.zeronewActivityIndicator.center = CGPoint(x: leftViewSize.width - newActivityIndicator.frame.width / 2,y: leftViewSize.height / 2)textField?.leftView = newActivityIndicator}} else {activityIndicator?.removeFromSuperview()}}}
}
example result test in simulator.
No comments: