Skip to content

Instantly share code, notes, and snippets.

View erdemildiz's full-sized avatar
🏠
Working from home

Erdem ILDIZ erdemildiz

🏠
Working from home
View GitHub Profile
@erdemildiz
erdemildiz / String+subscript.swift
Last active September 26, 2020 16:12 — forked from foxicode/String+subscript.swift
Swift String subscript extension
#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 {
@erdemildiz
erdemildiz / xcode-simulator-status-bar-terminal
Last active September 26, 2020 16:12
Xcode Simulator changed status bar status
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>
@erdemildiz
erdemildiz / insetForSectionAt-center-for-ipad.swift
Last active September 26, 2020 16:12
UICollectionView center items fro ipad
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)
}
@erdemildiz
erdemildiz / trottle.swift
Last active September 26, 2020 16:12
Trottle in swit
NSObject.cancelPreviousPerformRequests(withTarget: self)
perform(#selector(updateSearch), with: searchText, afterDelay: 0.3)
@objc
func updateSearch() {
....
}
@erdemildiz
erdemildiz / custom-search-bar.swift
Last active September 26, 2020 16:13
Customize UISearchBar
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)
@erdemildiz
erdemildiz / Gauge.swift
Last active September 26, 2020 16:13
Gauge
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())
@erdemildiz
erdemildiz / ProgressView.swift
Last active September 26, 2020 16:13
ProgressView
import SwiftUI
import ClockKit
struct ProgressSample: View {
var body: some View {
ProgressView(value: 0.7)
.progressViewStyle(CircularProgressViewStyle())
}
}
@erdemildiz
erdemildiz / dealloc-detection.txt
Last active September 26, 2020 16:13
Dealloc Detection by using Symbolic Breakpoint
// 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
@erdemildiz
erdemildiz / keypad.swift
Last active September 26, 2020 16:13
Keypad Solution
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 }
@erdemildiz
erdemildiz / xcframework.sh
Last active September 26, 2020 16:13
xcframework samplecode
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"