9 Notes In March 2020
1. Set Multiple navbars with extension
- Extension
extension UIViewController {
func setupNavigationBarRightItems(items: UIBarButtonItem...) {
self.navigationItem.rightBarButtonItems = items
}
}
- How to use code
func setNavigationItem() {
let first = UIBarButtonItem(image: #imageLiteral(resourceName: "ic_GoldCoin"), style: .plain, target: self, action: #selector(navItemFirst))
let second = UIBarButtonItem(image: #imageLiteral(resourceName: "ic_Mystery"), style: .plain, target: self, action: #selector(navItemSecond))
self.setupNavigationBarRightItems(items: first, second)
}
@objc func navItemFirst() {
print("Action Here")
}
@objc func navItemSecond() {
print("Action Here")
}
2 . Firebase dynamic links error in pod file FIRDynamicLinks.m
Firebase dynamic links diagnosticString have an error in
ERROR: UIApplication delegate %@ does not implements selector "
ERROR: Specified custom URL scheme is %@ but Info.plist do "
Describe environment:
Xcode version: 11.3.1
Firebase SDK version: 6.18.0
Firebase Component: Dynamic link
Component version: 4.0.7
Installation method: `CocoaPods
Error in firebase dynamic link file "FIRDynamicLinks.m" If I ran Project success but in build jenkins is error because pod firebase dynamicLiks an error
My friend help to solve this error remove nERRORTAG.
from file .xcodeproj in line sheelscript
3. After pull from master and build project xib 'invalid element name'
Error screenshot
- check error -> open file xib with sourecode
- and found conflict in here, and fixing this code
4. Multiple commands produce
Multiple commands produce '/Users/Library/Developer/Xcode/DerivedData/Project-ccinzvugeclpcufoplddugllxter/Build/Products/Production-iphoneos/Project.swiftmodule/arm64-apple-ios.swiftdoc':
1) Target 'project' (project 'project'): Ditto /Users/Library/Developer/Xcode/DerivedData/project-ccinzvugeclpcufoplddugllxter/Build/Products/Production-iphoneos/project.swiftmodule/arm64-apple-ios.swiftdoc /Users/Library/Developer/Xcode/DerivedData/project-ccinzvugeclpcufoplddugllxter/...../project.swiftdoc
2) Target 'project' (project 'project'): Ditto /Users/Library/Developer/Xcode/DerivedData/project-ccinzvugeclpcufoplddugllxter/Build/Products/Production-iphoneos/project.swiftmodule/arm64-apple-ios.swiftdoc /Users/Library/Developer/Xcode/DerivedData/project-ccinzvugeclpcufoplddugllxter/Build/....../arm64-apple-ios.swiftmodule
How to fixing:
You most likely have two targets with the same product name. (Check in Target left side)
Can you both targets in the project, go to Build Settings and check the values for "Product Module Name" in the Packaging section?
Source: https://stackoverflow.com/questions/55856786/error-multiple-commands-produce-x86-64-swiftmodule
5. Fixing Clickable UITextView
Just select the UITextView in your storyboard and go to "Show Attributes inspector" and select selectable and links. As the image below shows. Make sure Editable is unchecked.
enter image description here https://stackoverflow.com/a/34425135/8366535
6. Count Line Breaks
This example how to count line break with data string
// Count - line breaks
let base = "Hello, playground\r\nhere too\r\nGalahad\r\n\n i"
let ns = base as NSString
var intArr = [Any]()
ns.enumerateLines { (str, _) in
intArr.append(str)
print(str)
}
print(intArr.count)
Source: https://stackoverflow.com/a/46491196/83665357. Filter Link in tap gesture TextView
you want to deference tap url or navigation in one tap gesture check this handle
this example use by sentence.
@objc func tappedTextView(tapGesture: UIGestureRecognizer) {
let location: CGPoint = tapGesture.location(in: textViewQuotes)
let position: CGPoint = CGPoint(x: location.x, y: location.y)
let tapPosition: UITextPosition = textViewQuotes.closestPosition(to: position)!
guard let textRange: UITextRange = textViewQuotes.tokenizer.rangeEnclosingPosition(tapPosition, with: UITextGranularity.sentence, inDirection: UITextDirection(rawValue: 1)) else {return}
let tappedWord: String = textViewQuotes.text(in: textRange) ?? ""
let verifyURL = self.verifyUrl(urlString: "Test with the URL http://scripttes.blogspot.com/ \n check.)
if verifyURL == true {
if let url = URL(string: tappedWord.filterUrl()) {
UIApplication.shared.open(url)
}
} else {
print("navigation controller")
}
}
////
func verifyUrl (urlString: String?) -> Bool {
if let input = urlString {
let url = input.filterUrl()
if let url = NSURL(string: String(url)) {
return UIApplication.shared.canOpenURL(url as URL)
}
}
return false
}
/////
extension String {
func filterUrl() -> String {
var str: String = ""
let detector = try! NSDataDetector(types: NSTextCheckingResult.CheckingType.link.rawValue)
let matches = detector.matches(in: self, options: [], range: NSRange(location: 0, length: self.utf16.count))
for match in matches {
guard let range = Range(match.range, in: self) else { continue }
let urlStr = self[range]
str = String(urlStr)
}
return str
}
}
This example use storyBoard as navigation
extension UIViewController {
func pushViewControllerOfType<T: Navigatable>(viewControllerType: T.Type, completion: (T) -> Void) {
let viewController = T.instantiateFromStoryboard()
if let view = viewController as? UIViewController {
self.navigationController?.pushViewController(view, animated: true)
}
completion(viewController)
}
}
9. Regex Check Email
extension String {
func handleCheckEmail() -> Bool {
let regEx = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,6}"
let test = NSPredicate(format: "SELF MATCHES%@", regEx)
return test.evaluate(with: self)
}
}
9 Notes In March 2020
Reviewed by Luffyselah
on
April 01, 2020
Rating: 5