This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"pn_apns": { | |
"aps": { | |
"alert": "hello world" | |
}, | |
"pn_push": [ | |
{ | |
"targets": [ | |
{ | |
"environment": "development", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct ContentView: View { | |
var body: some View { | |
Text("Hello, World!") | |
} | |
} | |
#if DEBUG | |
struct ContentView_Previews: PreviewProvider { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
optional func scene(_ scene: UIScene, | |
willConnectTo session: UISceneSession, | |
options connectionOptions: UIScene.ConnectionOptions) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!) | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!) | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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?) -> ()) { |