Skip to content

Instantly share code, notes, and snippets.

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

Prateek Sharma prat14k

🏠
Working from home
View GitHub Profile
@prat14k
prat14k / Combine+Extension.swift
Created November 9, 2021 10:00
An extension for Combine
import Foundation
import UIKit
import Combine
extension UIControl {
class Publisher: Combine.Publisher {
typealias Output = UIControl.Event
typealias Failure = Never
let subject = PassthroughSubject<Output, Failure>()
@prat14k
prat14k / Log.swift
Created September 15, 2021 06:57 — forked from aryamansharda/Log.swift
Logging In Swift [The Right Way]
import Foundation
enum Log {
enum LogLevel {
case info
case warning
case error
fileprivate var prefix: String {
switch self {
@prat14k
prat14k / Podfile
Created June 16, 2020 10:50
Set the swift version and any other build setting of the installed cocoapods;
#... Pods defined above
post_install do |installer|
installer.pods_project.targets.each do |target|
if ['URITemplate'].include? target.name
target.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '4.0'
end
else
target.build_configurations.each do |config|
@prat14k
prat14k / Sorting.swift
Created November 21, 2019 09:46
Playing with sort method of Swift
enum EN: Int, CaseIterable {
case a, b, c, d, e, f, j, k
var sis: Bool {
switch self {
case .a, .b, .d, .f, .j, .k: return true
default: return false
}
}
}
@prat14k
prat14k / Enum.swift
Created August 2, 2019 14:13
associated type enums
As brilliantly described here, in Swift4 you can now use Codable protocol to store enum with associated values in NSUserDefaults. You can use something like the following
enum Example {
case caseOne(a: DownloadState, b: Route)
case caseTwo(a: String, b: Int, c: Data?)
}
extension Example: Codable {
private enum CodingKeys: String, CodingKey {
case base, caseOneParams, caseTwoParams
@prat14k
prat14k / DispatchGroup.swift
Created July 2, 2019 11:15
DispatchGroup Demo
/*
##: DispatchGroup
- Lets you wait for task to happen and then we can continue to do what we want
- Whenever starting a task, use enter() to denote the start of a task
- Whenever completed, use leave() to denote finishing of the task
- You call wait() to block the current thread while waiting for tasks’ completion.
This waits forever which is fine because the photos creation task always completes.
You can use wait(timeout:) to specify a timeout and bail out on waiting after a specified time.
- To let know when all tasks are done, use notify() which automatically gets triggered when all tasks are done
*/
@prat14k
prat14k / String.swift
Created July 2, 2019 06:54
String extension to get character like array indices
extension String {
var length: Int {
return count
}
subscript (i: Int) -> String {
return self[i ..< i + 1]
}
@prat14k
prat14k / UITableView+Select.swift
Created July 2, 2019 06:05
UITableView clearing the subview's background color on selection
// UITableViewCell changes the background color of all sub views when cell is selected or highlighted.
// You can Solve this problem by overriding Tableview cell's setSelected:animated and setHighlighted:animated and resetting view background color.
// In Swift 3.1 :
override func setSelected(_ selected: Bool, animated: Bool) {
let color = yourView.backgroundColor
super.setSelected(selected, animated: animated)
if selected {
@prat14k
prat14k / MD5StringTest.swift
Created March 19, 2019 09:26 — forked from khanlou/MD5StringTest.swift
MD5 and SHA1 on String in Swift 3
import XCTest
@testable import <#project#>
class StringMD5Test: XCTestCase {
func testMD5() {
let string = "soroush khanlou"
XCTAssertEqual(string.md5, "954d741d14b14002d1ba88f600eee635")
@prat14k
prat14k / iOS App upload Requirements.md
Created February 22, 2019 07:49
Basic Requirements to upload an app to app-store
  1. Register for the Apple Developer Program:
  • Delevopment Team Account ($299)
  • Individual Person Account ($99)
  1. Create an App entry in iTunes Connect
    • This account will be accessible as soon as you have enrolled in the developer program
  2. App-Icon
    • There are multiple sizes.
  • Can be made first for 1024 x 1024 and generated for all sizes using Sketch or XD
  1. Screenshot/App previews
    • Should add screenshots of your app and can add preview video, containing the overview of the app.