9 Notes January 2021
1. Remove Tabbar Title
- This code will be remove all title in tabbar item
func removeTabbarItemsText() {
var offset: CGFloat = 0.0
if #available(iOS 11.0, *), traitCollection.horizontalSizeClass == .regular {
offset = 0.0
}
if let items = tabBar.items {
for item in items {
if item.tag != 2 {
item.title = ""
item.imageInsets = UIEdgeInsets(top: offset, left: 0, bottom: -offset, right: 0)
}
}
}
}
2. Invalid Apple Certificates provisioning profile make Jenkins error code signing
This is the explanation
https://stackoverflow.com/a/39590933/8366535
Q: What causes the provisioning profile "Invalid" status? How do I resolve it, and how do I prevent it?
A: The provisioning profile invalid status is caused by changes to the profile’s associated certificate or App ID. Any time an App ID or certificate changes, all profiles that are associated to it are marked Invalid. This does not apply to Xcode's team profiles, but applies to all profiles that Xcode does not manage, specifically, custom development profiles and distribution profiles. This document explains the causes in detail and provides steps to resolve and avoid the profile invalid status.
The provisioning profile lives for 1 year, maybe it expired so simply remove it and make another one with the same certificates, app ids and devices and you can use it without any problem.
If you generate a new provisioning profile, your old installations (store or adhoc) won't be affected
3. Remove unique character in String
This extension for string
// MARK: remove unique character
func removeSpecialCharsFromString() -> String {
let okayChars = Set("abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLKMNOPQRSTUVWXYZ1234567890+-=.!_")
return self.filter {okayChars.contains($0) }
}
4. Remove Array duplicates
This extension array
extension Array where Element: Hashable {
func removingDuplicates() -> [Element] {
var addedDict = [Element: Bool]()
return filter {
addedDict.updateValue(true, forKey: $0) == nil
}
}
mutating func removeDuplicates() {
self = self.removingDuplicates()
}
}
5. This Cocoapod is really usefully
- SwiftLint
SwiftLint is a great tool that will make sure you and your team are following the swift coding styles and conventions. It’s really easy to use and integrate. It’s open-source and you can use only the rules you want and even write your own rules.
- SDWebImage
It is an Asynchronous image downloader with cache support as a UIImageView category. It has UIKit categories to do things such as set a UIImageView image to a URL.
- Alamofire
Alamofire is a Swift-based, HTTP networking library. It provides a simple interface on top of Apple’s Foundation networking stack that simplifies common networking tasks. Its specialties include chainable request/response methods, JSON and Codable decoding, authentication, and more.
- SwiftyJson
SwiftyJSON is a simplified JSON parsing library that gives you more precise syntax than the built-in iOS libraries (yes, even more than JSONEncoder from Codable).
- PromiseKit
PromiseKit is a framework that will simplify working with async code and make your code very elegant and simple to follow.
6. XCode Version 11.5 debugger is extremely slow
In my case, I got troubles after update OS Big Sur my Xcode extremely slow, so I found a solution in
for unchecking/disable "Main threat Checker"
Open your run configurations -> Manage schemes -> Edit scheme -> Run -> Diagnostics tab
source: https://stackoverflow.com/a/58516376/8366535
7. Update Xcode 12 Error building for iOS Simulator, but linking in object file built for iOS, for architecture arm64
I get a solution for this error
- To do that, navigate to Build Settings of your project and add Any iOS Simulator SDK with value arm64 inside Excluded Architecture.
- In place of this, you can add this snippet in your Podfile. It will write the necessary Build Settings every time you run pod install
Can be fixing this bug error too
arm64 (in target 'Realm' from project 'Pods')
post_install do |installer|
installer.pods_project.build_configurations.each do |config|
config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
end
end
source: https://stackoverflow.com/a/63955114/8366535
8. Create Thumbnail use youtube id URL
// Get Youtube ID
// MARK: Use query item
func getYoutubeId(youtubeUrl: String) -> String? {
return URLComponents(string: youtubeUrl)?.queryItems?.first(where: { $0.name == "v" })?.value
}
// MARK: Use regex
extension String {
var youtubeID: String? {
let pattern = "((?<=(v|V)/)|(?<=be/)|(?<=(\\?|\\&)v=)|(?<=embed/))([\\w-]++)"
let regex = try? NSRegularExpression(pattern: pattern, options: .caseInsensitive)
let range = NSRange(location: 0, length: count)
guard let result = regex?.firstMatch(in: self, range: range) else {
return nil
}
return (self as NSString).substring(with: result.range)
}
}
9. Cancel DispatchQueue.main.asyncAfter
In some conditions, I need to cancel or stop action DispatchQueue, use DispatchWorkItem to fix that.
so this for full code in viewController
import UIKit
class Extend45View: UIViewController {
@IBOutlet weak var ululu: UILabel!
var task: DispatchWorkItem?
override func viewDidLoad() {
super.viewDidLoad()
// Wrap our request in a work item
let requestWorkItem = DispatchWorkItem { [weak self] in
self?.handleAnnouncement()
}
Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(handleCancel), userInfo: nil, repeats: false)
task = requestWorkItem
DispatchQueue.main.asyncAfter(deadline: .now() + 1, execute: requestWorkItem)
}
@objc func handleCancel() {
task?.cancel()
print("is cancel")
}
func handleAnnouncement() {
print("comment")
}
}
No comments: