Skip to content

Instantly share code, notes, and snippets.

View lalkrishna's full-sized avatar
🤩

Lal Krishna lalkrishna

🤩
View GitHub Profile
@lalkrishna
lalkrishna / universalFrameworkGuide.md
Last active December 16, 2020 19:44
Creating Universal Framework with Bitcode support
import UIKit
class SelfSizedTableView: UITableView {
var maxHeight: CGFloat = UIScreen.main.bounds.size.height
override func reloadData() {
super.reloadData()
self.invalidateIntrinsicContentSize()
self.layoutIfNeeded()
}
@lalkrishna
lalkrishna / Fonts.swift
Created September 13, 2020 13:18
Make use of custom fonts with the help of extensions. Note: iOS not detecting `black` font weight for Montserrat font. Please comment if you know the solution for it.
// MARK: - Usage
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
UIFont.registerAllCustomFonts()
// Or You can add manually,
// https://developer.apple.com/documentation/uikit/text_display_and_fonts/adding_a_custom_font_to_your_app
return true
}
// Using Default family name
//
// LocalAuthorization.swift
// LocalAuthorization
//
// Created by lalkrishna.
//
// Copyright © 2020 Lal Krishna. All rights reserved.
//
import Foundation
@lalkrishna
lalkrishna / UIStoryboard+Extensions.swift
Created August 15, 2020 17:23
UIStoryboard Extension for Easy Instantiate Viewcontrollers [Swift]
enum Storyboard: String {
case main = "Main",
onboarding = "Onboarding"
}
protocol Instantiatable {
static var storyboard: Storyboard { get }
static func instantiate() -> Self
}
@lalkrishna
lalkrishna / GradientButton.dart
Created August 9, 2020 04:17
GradientButton Widget for Flutter Apps
import 'package:flutter/material.dart';
class GradientButton extends StatelessWidget {
final String title;
final VoidCallback onPressed;
const GradientButton({
Key key,
@required this.title,
@required this.onPressed,
}) : super(key: key);
@lalkrishna
lalkrishna / UpdateManager.swift
Created July 18, 2020 10:26
Checking for Update in GitHub project release
struct UpdateManager {
let updateURL = "https://api.github.com/repos/{user_name}/{repo_title}/releases/latest"
static let shared = UpdateManager()
private init() { }
func checkForUpdates(updateAvailable: @escaping (String?) -> Void) {
let session = URLSession(configuration: .default)
let updateTask = session.dataTask(with: URL(string: updateURL)!) { (data, response, error) in
DispatchQueue.main.async {
guard let data = data else {
@lalkrishna
lalkrishna / StreamingFileReader.swift
Created June 30, 2020 10:52
If you need to read a very large file you’ll want to stream it so you’re not loading the entire thing into memory at once. Here’s a snippet for doing that.
class UseItHere {
func readFile() {
let fileReader = StreamingFileReader(path: logFile)
while let line = fileReader.readLine() {
// Do something with the line
}
}
}
class StreamingFileReader {
extension UIApplication {
var topViewController: UIViewController? {
if #available(iOS 13.0, *) {
if UIApplication.shared.supportsMultipleScenes, let keyWindow = UIApplication.shared.windows.first(where: { $0.isKeyWindow }) {
return keyWindow.visibleViewController
} else {
return UIApplication.shared.keyWindow?.visibleViewController
}
} else {
return UIApplication.shared.keyWindow?.visibleViewController
@lalkrishna
lalkrishna / Notes
Last active December 13, 2019 06:14
https://medium.com/swift2go/mastering-generics-with-protocols-the-specification-pattern-5e2e303af4ca
https://www.hackingwithswift.com/read/30/4/fixing-the-bugs-slow-shadows
https://www.raywenderlich.com/261-how-to-make-a-uiviewcontroller-transition-animation-like-in-the-ping-app#toc-anchor-007
https://medium.com/@phanquanghoang/using-gitlab-ci-cd-fastlane-for-ios-project-part-1-5e7db82a3566
https://developer.apple.com/documentation/metrickit/improving_your_app_s_performance/