Skip to content

Instantly share code, notes, and snippets.

View shantaramk's full-sized avatar
🎯
Focusing

Shantaram Kokate shantaramk

🎯
Focusing
  • India
View GitHub Profile
@shantaramk
shantaramk / StructExtensionWithDefaultInit.swift
Created February 6, 2022 08:52
How to add a custom initializer to a struct without losing its memberwise initialize
struct Point {
let x: Int
let y: Int
}
extension Point {
init(x: Int) {
self.x = x
y = 10
}
@shantaramk
shantaramk / StructCustomInitialize.swift
Created February 6, 2022 08:44
Struct Custom initialize
struct Point {
let x: Int
let y: Int
init(x: Int) {
self.x = x
y = 10
}
}
struct Point {
let x: Int
let y: Int
}
@shantaramk
shantaramk / HigherOrderFuncation.swift
Last active May 23, 2021 15:04
Inside Higher Order Function in swift
extension Array {
///Filter function check element isIncluded
func sk_Filter(isIncluded: (Element) -> Bool) -> [Element] {
var resultList = [Element]()
for element in self {
let isIncluded = isIncluded(element)
if isIncluded {
resultList.append(element)
@shantaramk
shantaramk / ProfileViewController3.swift
Created August 19, 2020 10:27
Understanding UIKit's View display lifecycle
class ProfileViewController: UIViewController {
var imageView: UIImageView = {
let imageView = UIImageView()
imageView.backgroundColor = UIColor.black
imageView.translatesAutoresizingMaskIntoConstraints = false
return imageView
}()
override func viewDidLoad() {
@shantaramk
shantaramk / ProfileViewController1.swift
Created August 18, 2020 08:55
Understanding UIKit's View display lifecycle
imageView.layer.masksToBounds = false
imageView.layer.cornerRadius = imageView.frame.height * 0.5
imageView.clipsToBounds = true
@shantaramk
shantaramk / ProfileViewController.swift
Created August 17, 2020 10:48
Understanding UIKit's View display lifecycle
class ProfileViewController: UIViewController {
var imageView: UIImageView = {
let imageView = UIImageView()
imageView.backgroundColor = UIColor.black
imageView.translatesAutoresizingMaskIntoConstraints = false
return imageView
}()
override func viewDidLoad() {
@shantaramk
shantaramk / AppGroupsManager3.swift
Created August 14, 2020 13:59
This can also be shared between apps in the same AppGroup.
// save the message in the app A side
if let image = AppGroupsManager.loadImage(imageNameKey: "imageURL") {
imgNotification.image = image
}
// call the message at the application B side
AppGroupsManager.saveImage(imageData: data, imageName: "imagesName", imageNameKey: "imageURL")
@shantaramk
shantaramk / AppGroupsManager2.swift
Last active August 15, 2020 19:23
AppGroup: Share images with File Manager
class AppGroupsManager: NSObject {
private static let groupID = "group.www.iSkyNet.demo"
class func saveMessage(_ message: String, key: String) {
let defaults = UserDefaults(suiteName: groupID)
defaults?.set(message, forKey: key)
defaults?.synchronize()
}
class func loadMessage(key: String) -> String? {
@shantaramk
shantaramk / AppGroupsManager1.swift
Created August 14, 2020 10:48
You can share between apps in the same AppGroup.
// save the message in the app A side
let message = "iSkyNet"
AppGroupsManager.saveMessage(message, key: "name")
// call the message at the application B side
if let savedMessage = AppGroupsManager.loadMessage(key: "samplekey") {
print(savedMessage)
}