Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // AppDelegate.swift
- // MoneyConverter
- //
- // Created by Sabin Tabirca on 26/01/2024.
- //
- import UIKit
- @main
- class AppDelegate: UIResponder, UIApplicationDelegate {
- func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
- // 应用程序启动后自定义的覆盖点.
- return true
- }
- // MARK: UISceneSession Lifecycle 场景会话生命周期
- func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
- // 创建新场景会话时调用。
- // 使用此方法选择用于创建新场景的配置。
- return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
- }
- func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
- // 当用户放弃场景会话时调用。
- // 如果在应用程序未运行时丢弃任何会话,则将在 application:didFinishLaunchingWithOptions 之后不久调用此方法。
- //使用此方法释放特定于已丢弃场景的任何资源,因为它们不会返回。
- }
- }
- //
- // SceneDelegate.swift
- // MoneyConverter
- //
- // Created by Sabin Tabirca on 26/01/2024.
- //
- import UIKit
- class SceneDelegate: UIResponder, UIWindowSceneDelegate {
- var window: UIWindow?
- func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
- // 使用此方法可以选择配置 UIWindow `window` 并将其附加到提供的UIWindowScene `scene`。
- // 如果使用故事板,`window` 属性将自动初始化并附加到场景。
- // 此委托并不意味着连接场景或会话是新的(请参阅 `application:configurationForConnectingSceneSession` )。
- guard let _ = (scene as? UIWindowScene) else { return }
- }
- func sceneDidDisconnect(_ scene: UIScene) {
- // 系统正在释放场景时调用。
- // 这会在场景进入后台后不久发生,或者在其会话被丢弃时发生。
- // 释放与该场景关联的所有资源,这些资源可以在下次场景连接时重新创建。
- // 场景稍后可能会重新连接,因为其会话不一定被丢弃(请参阅 `application:didDiscardSceneSessions` )。
- }
- func sceneDidBecomeActive(_ scene: UIScene) {
- // 当场景从非活动状态转变为活动状态时调用。
- // 使用此方法重新启动场景不活动时暂停(或尚未启动)的任何任务。
- }
- func sceneWillResignActive(_ scene: UIScene) {
- // 当场景从活动状态转变为非活动状态时调用。
- // 这可能是由于临时中断(例如来电)而发生的。
- }
- func sceneWillEnterForeground(_ scene: UIScene) {
- // 当场景从背景过渡到前景时调用。
- // 使用此方法撤消进入后台时所做的更改。
- }
- func sceneDidEnterBackground(_ scene: UIScene) {
- //当场景从前景过渡到背景时调用。
- // 使用该方法保存数据、释放共享资源、存储足够的场景特定状态信息
- // 将场景恢复到当前状态。
- }
- }
- //
- // ViewController.swift
- // MoneyConverter
- //
- // Created by Sabin Tabirca on 26/01/2024.
- //
- import UIKit
- class ViewController: UIViewController {
- // outlets and actions
- @IBOutlet weak var euroTextField: UITextField!
- @IBOutlet weak var dollarTextField: UITextField!
- @IBAction func clearAction(_ sender: Any) {
- // clear the fields
- euroTextField.text = ""
- dollarTextField.text = ""
- }
- @IBAction func convertAction(_ sender: Any) {
- if euroTextField.text != "" && dollarTextField.text == ""{
- // get the value from euroTextField
- let euroAmount = Double(euroTextField.text!)
- // convert it to dollars
- let dollarAmount = convert(amount: euroAmount!, rate: convertRate)
- // put the dollar value to dollarTextField
- dollarTextField.text = "converted \(dollarAmount)"
- }
- else if euroTextField.text == "" && dollarTextField.text != ""{
- // get the value from dollarTextField
- let dollarAmount = Double(dollarTextField.text!)
- // convert it to euros
- let euroAmount = convert(amount: dollarAmount!, rate: 1/convertRate)
- // put the euros value to euroTextField
- euroTextField.text = "converted \(euroAmount)"
- }
- }
- // vars and methods
- let convertRate = 1.234
- func convert(amount:Double, rate:Double)->Double
- {
- let convertedAmount = amount * rate
- return convertedAmount
- }
- override func viewDidLoad() {
- super.viewDidLoad()
- // Do any additional setup after loading the view.
- }
- }
Add Comment
Please, Sign In to add comment