Skip to content

Instantly share code, notes, and snippets.

View KiranJasvanee's full-sized avatar
🖼️
Painting Something

Kiran Jasvanee KiranJasvanee

🖼️
Painting Something
View GitHub Profile
@KiranJasvanee
KiranJasvanee / PubNub_Payload
Created May 21, 2020 07:16
PubNub Push Notification Payload
{
"pn_apns": {
"aps": {
"alert": "hello world"
},
"pn_push": [
{
"targets": [
{
"environment": "development",
@KiranJasvanee
KiranJasvanee / PubNub_PushNotifications_And_PubSubListener
Last active May 21, 2020 06:39
Includes PubNub push notification configuration & message listener too.
import UIKit
import PubNub
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var pubnub: PubNub!
let listener = SubscriptionListener(queue: .main)
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
@KiranJasvanee
KiranJasvanee / ContentView.swift
Last active December 26, 2019 06:47
GettingStartedwith-SwiftUI-2
import SwiftUI
struct ContentView: View {
var body: some View {
Text("Hello, World!")
}
}
#if DEBUG
struct ContentView_Previews: PreviewProvider {
@KiranJasvanee
KiranJasvanee / GettingStartedwith-SwiftUI-2.swift
Last active December 26, 2019 06:31
GettingStartedwith-SwiftUI-2
// Create the SwiftUI view that provides the window contents.
let contentView = ContentView()
// Use a UIHostingController as window root view controller.
if let windowScene = scene as? UIWindowScene {
// cast UIScene instance to UIWindowScene to assign that scene to UIWindow.
let window = UIWindow(windowScene: windowScene)
// Use UIHostingController to create a view controller for SwiftUI view contentView.
window.rootViewController = UIHostingController(rootView: contentView)
// assign UIWindow instance to your delegate's window object to make it display when app launch happens.
@KiranJasvanee
KiranJasvanee / GettingStartedwith-SwiftUI-1.swift
Last active December 26, 2019 06:06
GettingStartedwith-SwiftUI-1
optional func scene(_ scene: UIScene,
willConnectTo session: UISceneSession,
options connectionOptions: UIScene.ConnectionOptions)
func tryUnowned() {
// let's get image data from server to load it in our imageview.
self.getData(from: URL.init(string: self.imageToBeShown)!) { [unowned self] (data, response, error) in
DispatchQueue.main.async {
self.imageView.image = UIImage.init(data: data!)
}
}
}
func tryWeak() {
// let's get image data from server to load it in our imageview.
self.getData(from: URL.init(string: self.imageToBeShown)!) { [weak self] (data, response, error) in
DispatchQueue.main.async {
self?.imageView.image = UIImage.init(data: data!)
}
}
}
let imageToBeShown = "https://images.pexels.com/photos/221433/pexels-photo-221433.jpeg"
func tryNone() {
// let's get image data from server to load it in our imageview.
self.getData(from: URL.init(string: self.imageToBeShown)!) { (data, response, error) in
DispatchQueue.main.async {
self.imageView.image = UIImage.init(data: data!)
}
}
}
func getData(from url: URL, completion: @escaping (Data?, URLResponse?, Error?) -> ()) {