This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#https://medium.com/better-programming/24-swift-extensions-for-cleaner-code-41e250c9c4c3 | |
import Foundation | |
extension String { | |
subscript (i: Int) -> Character { | |
return self[index(startIndex, offsetBy: i)] | |
} | |
subscript (bounds: CountableRange<Int>) -> Substring { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xcrun simctl status_bar booted override --time 23:03 --dataNetwork lte --batteryState charging --batteryLevel 60 | |
--time <string> | |
Set the date or time to a fixed value. | |
If the string is a valid ISO date string it will also set the date on relevant devices. | |
--dataNetwork <dataNetworkType> | |
If specified must be one of 'wifi', '3g', '4g', 'lte', 'lte-a', or 'lte+'. | |
--wifiMode <mode> | |
If specified must be one of 'searching', 'failed', or 'active'. | |
--wifiBars <int> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets { | |
if isiPad() { | |
let cellWidth = 54.0 // Sample | |
let extraSubscribeNumber = CGFloat(cellWidth / 2) | |
return UIEdgeInsets(top: 0, left: CGFloat(ScreenSize.width / 2) - ((cellWidth * CGFloat(CGFloat((slots.count / 2) + 1)).rounded()) + extraSubscribeNumber), bottom: 0, right: 0) | |
} | |
return UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSObject.cancelPreviousPerformRequests(withTarget: self) | |
perform(#selector(updateSearch), with: searchText, afterDelay: 0.3) | |
@objc | |
func updateSearch() { | |
.... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fileprivate func customizeSearchField(){ | |
UISearchBar.appearance().setSearchFieldBackgroundImage(UIImage(), for: .normal) | |
searchField.backgroundColor = .white | |
if let searchTextField = searchField.value(forKey: "searchField") as? UITextField { | |
searchTextField.translatesAutoresizingMaskIntoConstraints = false | |
NSLayoutConstraint.activate([ | |
searchTextField.heightAnchor.constraint(equalToConstant: 50), | |
searchTextField.leadingAnchor.constraint(equalTo: searchField.leadingAnchor, constant: 10), | |
searchTextField.trailingAnchor.constraint(equalTo: searchField.trailingAnchor, constant: -10), | |
searchTextField.centerYAnchor.constraint(equalTo: searchField.centerYAnchor, constant: 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
import ClockKit | |
struct GaugeSample: View { | |
var body: some View { | |
Gauge(value: 5.8, in: 3...10) { | |
Image(systemName: "drop.fill") | |
.foregroundColor(.green) | |
} | |
.gaugeStyle(CircularGaugeStyle()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
import ClockKit | |
struct ProgressSample: View { | |
var body: some View { | |
ProgressView(value: 0.7) | |
.progressViewStyle(CircularProgressViewStyle()) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Source: https://sarunw.com/posts/easy-way-to-detect-retain-cycle-in-view-controller/ | |
IMAGE URL: https://d33wubrfki0l68.cloudfront.net/ed072d774d90c6c39313c572521165b1cd23e5da/c5b38/images/debug-deinit-breakpoint-result.png |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
func entryTime(s: String, keypad: String) -> Int { | |
var time = 0 | |
var lastKeyPadIndex = -1 | |
s.forEach { charOfs in | |
if let currentIndex = keypad.firstIndex(of: charOfs)?.utf16Offset(in: keypad) { | |
var keyPadIndex = 1 | |
if (currentIndex > 2 && currentIndex < 6) { keyPadIndex = 2 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xcodebuild archive -scheme SampleMyFramework -archivePath "./build/ios_sim.xcarchive" -sdk iphonesimulator SKIP_INSTALL=NO | |
xcodebuild archive -scheme SampleMyFramework -archivePath "./build/ios.xcarchive" -sdk iphoneos SKIP_INSTALL=NO | |
xcodebuild -create-xcframework -framework "./build/ios.xcarchive/Products/Library/Frameworks/SampleMyFramework.framework" -framework "./build/ios_sim.xcarchive/Products/Library/Frameworks/SampleMyFramework.framework" -output "./build/SampleMyFramework.xcframework" |