Skip to content

Instantly share code, notes, and snippets.

@SandeepAggarwal
SandeepAggarwal / SubclassedUITableViewController.swift
Created November 20, 2021 08:42
Fixes UITableView footer color issue in iOS 15 using Xcode 13
/// There is a footer color issue in the case of a plain styled (not grouped style) tableView.
/// Before iOS 15, the footer was colored but now it was transparent
func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
let footer = UIView()
footer.isUserInteractionEnabled = false
footer.backgroundColor = UIColor(red: 229/255, green: 229/255, blue: 229/255, alpha: 1)
return footer
}
@SandeepAggarwal
SandeepAggarwal / SubclassedTableView.swift
Created November 20, 2021 08:37
Fixes section header top spacing in iOS 15 using Xcode 13
///Remove section header top spacing - https://developer.apple.com/forums/thread/684706
if #available(iOS 15, *) {
sectionHeaderTopPadding = 0
}
@SandeepAggarwal
SandeepAggarwal / AnotherTabChildViewController.swift
Created November 20, 2021 08:32
StatusBar appearance changes for TabBar in iOS 15 using Xcode 13
override var preferredStatusBarStyle : UIStatusBarStyle {
return .default
}
@SandeepAggarwal
SandeepAggarwal / AnotherNavChildViewController.swift
Last active November 20, 2021 08:33
StatusBar appearance changes for NavBar Controller in iOS 15 using Xcode 13
override var preferredStatusBarStyle : UIStatusBarStyle {
return .default
}
@SandeepAggarwal
SandeepAggarwal / fixiOS15AppearanceIssues.swift
Created November 20, 2021 08:08
Fixes NavBar and TabBar issues on iOS 15 using Xcode 13
func fixiOS15AppearanceIssues() {
fixiOS15NavBarIssues()
fixiOS15TabBarIssues()
}
private func fixiOS15NavBarIssues() {
if #available(iOS 15, *) {
let appearance = UINavigationBarAppearance()
appearance.configureWithOpaqueBackground()
appearance.backgroundColor = .blue //customised nav bar background color
@SandeepAggarwal
SandeepAggarwal / RemoveAppTrackingFromBranchSDK.rb
Created September 25, 2021 13:56
Podfile contents for removing App Tracking From Branch SDK
def configure_branch_settings(target)
target.build_configurations.each do |config|
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] = ['$(inherited)', 'BRANCH_EXCLUDE_IDFA_CODE=1']
end
end
post_install do |installer|
installer.pods_project.targets.each do |target|
if target.name == 'Branch'
# NOTE: we need to set this in order to compile Branch pod such that it won't call https://developer.apple.com/documentation/adsupport/asidentifiermanager/1614151-advertisingidentifier at runtime. This is to prevent Apple from requiring us to show https://developer.apple.com/documentation/apptrackingtransparency/attrackingmanager to users
@SandeepAggarwal
SandeepAggarwal / PrintPathFromRootToNode.swift
Created July 27, 2021 14:17
Prints a path from root node to a specified node in a tree
import Foundation
class TreeNode {
var data: Int
var left: TreeNode?
var right: TreeNode?
init(data: Int) {
self.data = data
}
@SandeepAggarwal
SandeepAggarwal / MyNotificationCenter.swift
Created July 18, 2021 12:04
Demonstrates how Apple's NotificationCenter works
import Foundation
protocol MyNotificationCenterInterface {
func addObserver(_ observer: Any, selector: Selector, name: NSNotification.Name?, object: Any?)
func post(_ notification: Notification)
}
struct NotificationObserverData {
let observer: Any,
selector: Selector,
@SandeepAggarwal
SandeepAggarwal / SwiftSelector.swift
Created July 18, 2021 11:43
Demonstrates how an obj-c selector can be replaced in Swift
import Foundation
class A {
func call(selector: Selector, on destination: Any) {
if let object = destination as? NSObject {
object.performSelector(onMainThread: selector, with: self, waitUntilDone: true)
} else {
DispatchQueue.main.async {
Thread.detachNewThreadSelector(selector, toTarget: destination, with: self)
}
import PlaygroundSupport
class Node {
var data: Int
var next: Node?
init(data: Int) {
self.data = data
}