9 Notes March 2021
1. Notification Center willResignActiveNotification call multiple times
When using notification center set in interactor init class (module fullscreen)I get multiple call willResignActiveNotification
because of that module I've used more than one navigation
Solution:
Move notification center from interactor to viewController
before (Interactor)
init() {
NotificationCenter.default.addObserver(self, selector: #selector(handleApplicationDidEnterBackground(_:)), name: UIApplication.willResignActiveNotification, object: nil)
}
@objc internal func handleApplicationDidEnterBackground(_ aNotification: Notification) {
self.proses()
}
override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(self, selector: #selector(handleApplicationDidEnterBackground(_:)), name: UIApplication.willResignActiveNotification, object: nil)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
NotificationCenter.default.removeObserver(self, name: UIApplication.willResignActiveNotification, object: nil)
}
@objc internal func handleApplicationDidEnterBackground(_ aNotification: Notification) {
self.interactor?.prosess()
}
Source: https://stackoverflow.com/a/61710674/8366535
2. Get data LPMetadataProvider
When I need data from LPMedataProvider
import LinkPresentation
let url = URL(string: "###URL HERE")
let metadataProvider = LPMetadataProvider()
metadataProvider.startFetchingMetadata(for: url) { (metaData, error) in
if let error = error {
print(error)
} else if let metaData = metaData {
print(metaData)
let desc = metaData.dictionaryWithValues(forKeys: ["_summary"]).description
let title = metaData.title
}
}
3. Navigation Present Not Fullscreen in IOS 14 +
### View controller (1)
### set in button action
let vc = PopupInfoViewController()
vc.modalTransitionStyle = .coverVertical
vc.modalPresentationStyle = .overFullScreen
self.present(vc, animated: true, completion: nil)
### View controller (2)
### set in viewDidLoad or viewWillAppear
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
UIView.animate(withDuration: 1) {
self.view.backgroundColor = UIColor.black.withAlphaComponent(0.5)
}
}
### set in viewWillDisappear
self.view.backgroundColor = UIColor.clear
4. Add Unit Test to Existing Project
File -> New -> Target -> Test -> Unit Testing bundle
and select your project
source: https://stackoverflow.com/a/34793806/8366535
5. Swiftlint always show Trailing Whitespace Violation
for fixing you can run in terminal this code
$ swiftlint autocorrect
autocorrect work for me
source: https://stackoverflow.com/a/57051011/8366535
6. Round Int
I want to round multiple $50.000/ ticket
let amount = 60000
let rounded = amount/50000 * 1
print("You get \(rounded) " + "ticket(s)") //You get 1 ticket(s)
7. Underline for UILabel (learn more)
just underline for UILabel, without any custom ui
let underlineAttribute = [NSAttributedString.Key.underlineStyle: NSUnderlineStyle.thick.rawValue] let underlineAttributedString = NSAttributedString(string: "StringWithUnderLine", attributes: underlineAttribute) labelLearnMore.attributedText = underlineAttributedString
source: https://stackoverflow.com/a/28053652/8366535
8. Button in table cell can't tap
- check if the button isEnable in UI or you can set it by code
- check if button isUserInteractionEnable
- check button delegate
programmatically set active button
button.isEnable = true button.isUserInteractionEnabled = true
9. Error Jenkins CompileSwift normal arm64
When I've build failure in jenkins I got this error
----------------------------------------------------------------------------------------------------------------
** ARCHIVE FAILED **
.
.
.
/Volumes/Data/jenkins/workspace/xxx/xxxxx_build/xxxx/Apps/Modules/General/Popup/Dialog/DxxxViewController.swift:746:39: cannot convert value of type '() -> ()' to expected argument type '((Bool) -> Void)?' .
.
The following build commands failed:
CompileSwift normal arm64 /Volumes/Data/jenkins/workspace/xxxx/xxxxx_build/xxxxxxx/Apps/Modules/General/Popup/Dialog/DxxxxViewController.swift
CompileSwiftSources normal arm64 com.apple.xcode.tools.swift.compiler
(2 failures)
[10:39:32]: Exit status: 65
----------------------------------------------------------------------------------------------------------------
Solution is:
use completion to action call dialog again, don’t call dialog in same class
Note:
Because in jenkins xcode version not update / xcode version higher than setup xcode version in jenkins