当前位置: 首页 > 工具软件 > Flying-Swift > 使用案例 >

swift

安泰平
2023-12-01

import UIKit

var str = "Hello, playground hello world"
var hello = "hello world"


print(hello)

var a = 1
var b = 1
print(a+b)

print(a / b)
print(a * b)
print(a - b)
let c = 10
print(c)

if (a < 4 && b > 2){
    print("success!!")
}
//else if a == 2 {
//    print(a)
//}
else{
    print("ooooo")
}

var someCharactor:Character = "a"



switch someCharactor {
case "a":
    print("aaaaa")
    break
default:
    print("bbbbb")

}

for i in 1...100{
    print("hello word" )
}

func  addTwonumbers(arg para:Int ,arg2 para2:Int) -> Int{
    
    let  sum = para + para2
    
    print(sum)
    
    return sum
}

let f = addTwonumbers(arg:12,arg2:23)
print(f)


class BlogPost{
    var title = ""
    var body = ""
    var author = ""
    var numberofcomments = 0
    
    func addComment(){
        numberofcomments += 1
    }
}

let myPost = BlogPost()

myPost.title = "Hello world"
myPost.author = "zengjunjie"
myPost.body = "hello@@@@"
myPost.addComment()
myPost.addComment()
print(myPost.numberofcomments)


let mysecondpost = BlogPost()

mysecondpost.title = "pkoshc"
mysecondpost.body = "khudbu"
mysecondpost.author = "hello"

mysecondpost.addComment()
mysecondpost.addComment()

for i in 1...13{
    mysecondpost.addComment()
}

print(mysecondpost.numberofcomments)

class Car{
    var speed = 200
    func drive(){
        print("Driving at \(speed)")}
}


class FastCar{
    var speed = 359
    
    func drive(){
    print("Driving at \(speed)")}
    
    func fun() {
        print("flying")
    
    }
    
}

class InheritCar:Car{
    func mycar(){
        print("this my car")
    }
    
    override func drive() {
        super.drive()
        print("my hahahahahha")
    }
}

let car = InheritCar()

car.mycar()
car.drive()


class Person{
    var name = ""
    var age = 0
    
    init(_ name:String, _ age:Int){
        self.name = name
        self.age = age
    }
    
    func driver() {
         print("I can driving")
    }
}

let zengjunjie = Person("zengjunjie",12)

zengjunjie.driver()





 类似资料: