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 SwiftUI | |
class FirstViewController: UIViewController { | |
lazy var infoLabel: UILabel = { | |
let view = UILabel() | |
view.translatesAutoresizingMaskIntoConstraints = false | |
view.text = "Initial Text" | |
view.textAlignment = .center |
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 ViewControllerPreview: UIViewControllerRepresentable { | |
let viewControllerBuilder: () -> UIViewController | |
init(_ viewControllerBuilder: @escaping () -> UIViewController) { | |
self.viewControllerBuilder = viewControllerBuilder | |
} |
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 { | |
@StateObject var userPreference = UserPreferences() | |
var body: some View { | |
ZStack() { | |
Color(userPreference.darkMode ? .black : .white) | |
.edgesIgnoringSafeArea(.all) |
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 Foundation | |
class UserPreferences : ObservableObject { | |
@Published var darkMode = false | |
@Published var notificationOn = false | |
} |
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
@AddCustomWebsiteExtension var website = "giray" |
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
@propertyWrapper struct AddCustomWebsiteExtension { | |
var wrappedValue : String { | |
didSet { | |
if !(wrappedValue.hasPrefix("https://") || wrappedValue.hasSuffix(".dev")) { | |
self.wrappedValue = "https://" + wrappedValue + ".dev" | |
} | |
} | |
} | |
init(wrappedValue: String) { | |
if wrappedValue.hasPrefix("https://") || wrappedValue.hasSuffix(".dev") { |
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 { | |
@State private var infoString : String? | |
var body: some View { | |
VStack { | |
Text(infoString ?? "No name") | |
Button("Change text") { |
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 | |
class ViewController: UIViewController { | |
@IBOutlet weak var infoLabel: UILabel! | |
var infoString : String? | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
infoLabel.text = "Property Wrappers" | |
} |
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 { | |
@State var text = "" | |
var body: some View { | |
VStack { | |
TextField("Type here", text: $text) | |
.textFieldStyle(RoundedBorderTextFieldStyle()) |
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 { | |
@State var isOn = false | |
var body: some View { | |
ZStack { | |
ContentView2(isOnFromContentView: $isOn) | |
Button("Flip color") { |
NewerOlder