zoukankan      html  css  js  c++  java
  • 第1年6月30日 swiftui playgrounds

    1.

    import SwiftUI
    import PlaygroundSupport
    
    struct ContentView : View {
        @State var index = 0
        var body: some View {
        
            VStack{
                Text("hello world")
                .padding()
                Text("(self.index)")
                    .padding()
                
                Button("tap me"){
                    self.index = self.index+1
                }
            }
        }
        
    }
    
    
    PlaygroundPage.current.setLiveView(ContentView())

    https://www.jianshu.com/p/00eeafbfc163

    import UIKit
    
    func sortArr(_ nums: [Int]) -> ([Int]) 
    {
        var nums = nums
        for i in 0..<nums.count {
            for j in 0..<nums.count-i-1 {
                if(nums[j]>nums[j+1]) {
                    let temp = nums[j]
                    nums[j] = nums[j+1]
                    nums[j+1] = temp
                }
            }
        }
        return nums
    }
    
    class NumWrap {
    
        var nums: [Int] = []
        
        init(nums:[Int]) {
            self.nums = nums
        }
        
        func sort(){
            self.nums = sortArr(self.nums)
        }
        
        func toString() -> (String) {
            var text = ""
            for i in 0..<nums.count{
                text += "(nums[i]),"
            }
            
            return text
        }
    }
    
    
    var nums = [2,4,1,5,3]
    print("排序前:",nums)
    print("排序后:",sortArr(nums))
    
    let num = NumWrap(nums: nums)
    
    print(num.toString())
    
    import SwiftUI
    import PlaygroundSupport
    
    struct ContentView : View {
        @State  var index = 0
        @State  var text = ""
        var num: NumWrap
        
        init(num:NumWrap) {
            self.num = num
            _text = State(initialValue: num.toString())
        }
        
        var body: some View {
            
            VStack(spacing:10){
                Text("(self.text)")
                    .padding()
                Text("(self.index)")
                    .padding()
                
                Button("sort") {
                    self.num.sort()
                    self.text = "排序后:"
                    self.text += self.num.toString()
                }.padding()
                Button("tap me") {
                    
                    self.index = self.index+1
                }.padding()
            }
        }
        
    }
    
    var view = ContentView(num:num )
    PlaygroundPage.current.setLiveView(view)

    初始化@state

    https://zhuanlan.zhihu.com/p/266137663

  • 相关阅读:
    C
    C
    你好,欢迎到这里来
    数组专题
    web前端的性能优化
    MornUI 源码阅读笔记
    application tips
    [转]就这样,创建了自己的运行时共享库(RSL)
    [转]glew, glee与 gl glu glut glx glext的区别和关系
    编码相关了解
  • 原文地址:https://www.cnblogs.com/javastart/p/14953462.html
Copyright © 2011-2022 走看看