Skip to content

Instantly share code, notes, and snippets.

Mohammad Azam azamsharp

Block or report user

Report or block azamsharp

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View .swift
struct ContentView: View {
@State private var isOn: Bool = false
var body: some View {
return VStack(spacing: 20) {
Facebook()
Twitter()
View .swift
struct TotalLikes: View {
@EnvironmentObject var userSettings: UserSettings
var body: some View {
HStack {
Text("Total Likes: ")
Text("\(userSettings.likes)")
}
}
View .swift
struct ContentView: View {
@State private var isOn: Bool = false
var body: some View {
return VStack(spacing: 20) {
Facebook()
Twitter()
View .swift
import SwiftUI
struct Facebook: View {
@EnvironmentObject var userSettings: UserSettings
var body: some View {
VStack {
Text("Facebook")
View .swift
if let windowScene = scene as? UIWindowScene {
let window = UIWindow(windowScene: windowScene)
let userSettings = UserSettings()
let contentView = ContentView().environmentObject(userSettings)
window.rootViewController = UIHostingController(rootView: contentView)
self.window = window
window.makeKeyAndVisible()
}
View .swift
import Foundation
class UserSettings: ObservableObject {
@Published var likes: Int = 0
}
View .swift
struct PostListView: View {
@ObservedObject private var postListVM = PostListViewModel()
var body: some View {
List(postListVM.posts, id: \.id) { post in
VStack(alignment: .leading, spacing: 10) {
Text(post.title).font(.headline)
Text(post.body)
}
View .swift
class PostListViewModel: ObservableObject {
let webservice = Webservice()
@Published var posts = [PostViewModel]()
init() {
self.webservice.fetchPosts { posts in
self.posts = posts.map(PostViewModel.init)
}
}
View .swift
struct Post {
let id = UUID().uuidString
let title: String
let body: String
}
class Webservice {
func fetchPosts(completion: @escaping ([Post]) -> Void) {
View .swift
struct ContentView: View {
@State private var isOn: Bool = false
var body: some View {
return VStack {
Text(self.isOn ? "🌞" : "🌙")
.font(.custom("Arial", size: 100))
You can’t perform that action at this time.