编辑代码

var myString = "Hello world!     -  swift.jsrun.net"
print(myString)
NavigationView {
    VStack {
        ZStack {
            Rectangle()
                .fill(Color.secondary)

            // 显示图片
        }
        .onTapGesture {
            // 选择图片
        }

        HStack {
            Text("强度")
            Slider(value: self.$filterIntensity)
        }.padding(.vertical)

        HStack {
            Button("切换滤镜") {
                // 切换滤镜
            }

            Spacer()

            Button("保存") {
                // 保存图片
            }
        }
    }
    .padding([.horizontal, .bottom])
    .navigationBarTitle("Instafilter")
}
if image != nil {
    image?
        .resizable()
        .scaledToFit()
} else {
    Text("Tap to select a picture")
        .foregroundColor(.white)
        .font(.headline)
}
var myString = "Hello world!     -  swift.jsrun.net"
print(myString)
func dispalyArrayGraphButtonTips0 [
let myView1 = self.view.viewWithTag(2001) as! UllmageView
 let myView2 = self.view.viewWithTag(2002) as! UllmageViewmyView1.blackgroundColor=.darkGray
myView2.blackgroundColor= .darkGray
//支持View可以进行交互等操作
myView1.isUserInteractionEnabled = ture
myView2.isUserInteractionEnabled = ture
let h = myView1.frame.size.height
let w = myView1.frame.size.width
let padding : CGFloat = 5
let margin : CGFloat = 10
//计算每个格子的高度和宽度
let grid_w = (w - margin * 2 - padding * CGFloat(cols-1)) / CGFloat(cols) 
let grid h = (h - margin * 2 - padding * CGFloat(rows-1)) / CGFloat(rows) 
for i in 0..<rows{
for j in 0..<cols {
let x = margin + CGFloat(i) * (grid_w + padding)
let y = margin + CGFloat(i) * (grid h + padding)
let rect = CGRect(x: xy: y width: grid w.height: grid_h)
//在上面的ImageView中显示
let fileName1 = iv1[ cols+i]
let tag1 = icols+i +500
addButton(view: myView1, rect: rect,fileName: fileName1,tag: tag1)
//在上面的ImageView中显示
let fileName1 = iv1[i cols+i]
let tag1 = i cols+j + 500
addButton(view: myView1,rect: rect,fileName: fileName1,tag; tag1)
}
}
}
# encoding:utf-8
import requestsimport base64
车型识别
1f1
request url="https://aip.baidubce.com/rest/2.0/image-classify/v1/car"
#二进制方式打开图片文件
f=open('[本地文件]'rb)
img = base64.b64encode(f.read0)
params = ("image":img,"top num";5)
access token='[调用鉴权接口获取的token]
request url = request url + "?access token=” + access token
headers=('content-type:'application/x-www-form-urlencoded')
response = requests.post (request url, data-params, headers-headers)if response:
 print (response.json())返回的 JSON数据
Z:
log_id": 4086212218842203806,"location result":{
width": 447,"top": 226,"height": 209,"left": 188},
"result"; [{
"baike info":{
baike url":"http://baike.baidu.com/item/%E5&B8883%E588A8A0%E8%BFAAChiron/20419512"
"description""布加迪Chiron 是法国跑车品牌布加迪出品的豪华超跑车。配置四涡轮增压发动机,420公里每小时,有23种颜色的选择,售价高达260万美元。"
},
"score"0.98793351650238,“name":“布加迪 Chiron""year”:”无年份信息”
}
"score":0.0021970034576952,"name":“奥迪RS5",
"year":"2011-2017"
},
{
"score"0.0021096928976476,
“name":"奥迪RS4",
"year":"无年份信息
"score:0.0015581247862428,
"name""奧迪RS7",
"year" "'2014-2016"
"score";0.00082337751518935,
"name":"布加迪威航”
"year" :*2004-2015"
}],
"color result":"预色无法识别"
“Name":"Chen Zhifeng",
"Profession":"Teacher",
“Age":46,
"Email":"134025063010163.com",
"Friends":["Zhang San","Li Si"]
("TeamName":"iOS-Orange-Team",
"Teacher":"Chen Zhifeng",
'Students":[
{“Name":"Zhang Bo","Hometown":"Xuzhou"},
{"Name" :" Chang Wenxiang',"Hometown":"Yancheng"},
{"Name" :' Hu Yinting","Hometown":"Suzhou"}
}
}
'coord":("lon":-0.13,"lat":51.51),
"weather":[("id":300,"main":"Drizzle","description":"lightintensity drizzle","icon":"09d"}],
"base":"stations",
"main":{
"temp":280.32,
"pressure":1012,
"humidity":81,
"temp min":279.15,
"temp max":281.15),
"visibility":10000
"wind": {"speed":4.1,"deg":80},
"clouds":{"all":90},
"dt”:1485789600
sys":{
"type":1,
"id":5091,
"message":0.0103,
country":"GB"
sunrise":1485762037,
'sunset":1485794875
"id":2643743,
"name":"London"cod:200
# myjson.js
module. exports = function () {
var data =(users:[1}
// Create 1000 users
for (vari= O;i< 100; i+) {
'user'+ i})
data.users.push((id: i,name:
}
# myjson.js
module.exports =function ()var data =f users:[]]
// Create 1000 users
for (vari= 0; i< 1000; i++) [
data .users .push (f id: i,name: 'user'+i ])
)
return data
#news.Js
let Mock = require ('mockjs'); let Random = Mock. Random; module.exports =function() var data =(
news:[]
];
var images=[1,2,3].map
(x=>Random.image('200×100',Random. color (),
Random. word (2, 5)));
for (vari=0;i< 100; i++)
var content - Random.
cparagraph (0,10);
data.news.push([
id: i,
title: Random.cword (8,20),
desc: content.substr (0,40),
tag: Random.cword (2,6),
views: Random.integer
(100,5000),
images:images.slice (0,Random.integer (1,3) )
}
}
return data
]
imoort UlKit
import Foundation
//uri为MOCKMOCK 服务器的网址if let url = URL (string: "http: / /1ocalhost:3004/news")(
JRlSession. shared.dataTask (with: url) t(datar response, error) in
if error != nil (
print ("Network errors")
else
let rs = String (data: data!,
encoding: String.Encoding.utf8)!print (rs)
if let json = try?
JSONSerialization.jsonObject (with: data!,
options:.allowFragments)]
print(json)
}
}
}
.resume()
}
Amor.Y:
//构造器
init (name: String, origin: CGPoint, center: CGPoint, radius: CGFloat, angel
CGFloat, soundFile: String ="SO.m4a")(
super.init (name: name,origin: origin, soundFile: soundFile)
self.center =center
self .radius = radius
self.angel = angel
import ulkit
import Foundation import
AVFoundation
class Shape 
var name :String?
var soundPlayer : AVAudioPlayer? var soundFile :String?
//UlBezierPath
var path : UlBezierPath?
//selected?
var selectedFlag:Bool=false var origin :CGPoint?
var lineColor:UIColor?=UIColor. red
var fillcolor:UIColor?=UlColor. green
var lineWidth : CGFloat?=5
init(name :string,origin :CGPoint, soundFile :String -“DO.m4a“)self.name =name
self.origin = origin
self.soundFile = soundFile
convenience init(origin :CGPoint)self.init(name:“Shape
Bassclass", origin: origin)
)

Amor.Y:
func drawBezierPath()[print(“Draw\(name!) “)
]
func playAudio()f
print("Play sound:\(soundFile!)") let path = Bundle.
mainpath(forResource: soundfile, ofType:nil) let
url=URL(fileURWithPath:path!) soundPlayer =try?
AVAudioPlayer(contentsof:url) soundPlayer?.play()
]
func isSelected(point :CGPoint) ->Boolf
if (path?.contains(point))!(
selectedFlag =true
return true
]
else [selectedFlag =false
return false
class Line :Shape (
var start: CGPoint?
var end: CGPoint?
init(name: String,origin: CGPoint, start:CGPoint,end:CGPoint,
soundFile :String-“FA.m4a“)(super.init(name:name,origin:origin,soundfile:soundFile)
self.startmstart
self.end=end
convenience init(start :CGPoint, end:CGPoint) [self.init(name:“Line“, origin: start, start: start, end: end)
]
override func drawBezierPath()f

Amor.Y:
print(“Draw\(name!) “
path = UlBezierPath()
path?.move(to: start!)
path?.addLine(to:end!)
path?.lineWidth =linewidth!
path?.lineCapStyle=.round
lineColor?.setStroke()
path?.stroke()
class Rectangle:Shapef
var size: CGSize?
var corner:CGFloat?
init(name:String,origin: CGPoint, size:CGSire, Corner:0GFloat,soundFile:
String ="LA.mda") (
super.init(name:Name,rigingin, soundFile:soundFile)
self.sizewsize
self.corner = corner
convenience init(origin: CGPoint, size:CGSize, corner:CGFloat-0)
self.init(name:“Rectangle“,origin:origin,size: size,corner :corner)]
//重载 drawBezierPath 方法画矩形或者正方形
override func drawBezierPath()f print("Draw \(name!)") [path=UlBezierPath(roundedRect: CGRect(origin: originl, size
size!),cornerRadius: corner!)
if selectedFlag 
let dashes:[CGFloat] = [1,3]
path?.setLineDash(dashescount: dashes.count, phase:0)
]
path?.lineWidth = lineWidth!
lineColor?.setstroke()

Amor.Y:
path?.stroke()
)]
class Circle:Shape 
var center:CGPoint?
var raduis :CGFloat?
var size:CGSize?
init(name:String,origin:CGPoint, center:CGPoint, raduis :CGFloat,size:
CGSize,soundFile:String=“MI.m4a“)(
super.init(name:name,origin: origin,soundFile:soundfile)
self.center=center
self.raduis = raduis
self.size= size
]
convenience init(center:CGPoint, raduis:CGFloat)(
let x = center.x - raduis
let y =center.y -raduis
self.init(name:“Circle“,originiCGPoint(xiXry:y), center: center, raduis: raduis, Bize: CGSize(width; raduis, height; raduia))
]
convenience init(center: CGPoint, size : CGSize)(
let x=center.x-size.width/2let y =center.y - size.height/2self.init(name:"Oval/Ellipse",
origin:CGPoint(xix,y:y),center: center, raduis:0, size:size)
]
override func drawBezierPath()f print("Draw \(name!)")
path=UlBezierPath(ovalln:
CGRect(origin: origin!, size: size!)) if selectedFlag (
let dashes:[CGFloat]=[1,3]
path?.setLineDash(dashes,count: dashes.count, phase:0)
]

Amor.Y:
path?.lineWidth =lineWidth!
lineColor?.setStroke()
path?.stroke()
class Polygons :Shape [var points:Array<cgpoint>? init(name:String,origin:CGPoint, oints:Array<CGPoint>soundFile: String
="RE.m4a") [super.init(name:name,origin: origin,soundfile: soundFile) self. points =points
convenience init(points:
Array<CGPoint>)[if points.count == 3(
self.init(name:"Triangel",origin: points.first!, points:
points)
]
else if points.count >=3
self.init(name:"Polygons",origin: points.first!, points:
points)
]
else f
let origin =CGPoint(x: 0, y: 0)self.init(name:"Error",origin: origin, points:points)
]
]
override fune drawBezierPath() print("Draw \(name!)")
if(name=="Error") [return
]
path = UIBezierPath()
path?.move(to:origin!)
for each in points! (
path?.addLine(to:each

Amor.Y:
] 
path?.close()
path?.lineWidth =lineWidth!
lineColor?.setStroke()
path?.stroke()
path?.fill()
לl
class FiveStar:Shape (
var center:CGPoint?
var radius:CGFloat?
var angel:CGFloat?
init(name: String,origin: CGPoint, center:CGPoint,radius :CGFloat, angel:
CGFloat,soundFile :String="so.m4a")(
super.init(name: name,origin: origin,soundFile: soundFile)
self.center= center
self.radius = radius
self.angel = angel
]
convenience init(center: CGPoint, radiun i carlont,angel:CGrloat
=0)(
let x = center.x - radius
let y = center.y - radius
selfinit(name:"FiveStar",
origintCGPoint(uik,yiy), center: contei
radius: radius, angel: angel)
]
override func drawBezierPath()f print("Draw\(name!)")
//调用贝塞尔曲线函数
UTBezierPath()
path =UIBezierPath()
let i= 360/angel!
let xzAngle=CGFloat.pi*2/i

Amor.Y:
let xzX=(center?.x)!-
sin(xzAngle)*radius!
let xzY=(center?.y)!-
cos(xzAngle)*radius!
let p1= CGPoint(x: xzX, y; xzY) path?.move(to:pl)
let angle = CGFloat.pi*4/5
for i in 1...5 (
letx= (center?.x)! - sin(CGFloat(i)* angle+xzAngle)*radius!
let y=(center?.y)!-
cos(CGFloat(i)*angle+xzAngle)* radius!
path?.addLine(to:CGPoint(x:x,y: y))
]
path?.close()
if selectedFlagf
let dashes:[CGFloat] = [1,3]
path?.setLineDash(dashes,count: dashes.count, phase:0)
] 
path?.lineWidth =lineWidth!
//线条颜色为 red 红色
lineColor?.setStroke()
path?.stroke()
class CzfView:UlView [//成员变量(属性)shapes,其类型为Array<Shape>
private var shapes
Array<Shape>=[]
//重载 UIView 的 draw 方法
override func draw( rect: CGRect)[//调用 shapes这个数组中的每个实例的方法
for s in shapes (
s.drawBezierPath()
]
)

Amor.Y:
//增加实例到数组 shapes 中
func add(shape :Shape)(
shapes.append(shape)
]
//触摸事件
override func touchesBegan(_ touches : Set<UlTouch>, with event:
UlEvent?) [//获得 UITouch 集合
let touch:UlTouch =touches.first! as UlTouch
//获得触摸所在位置的坐标
let point = touch.location(in: self)//调用 shapes 这个数组中的每个实例的方法
for s in shapes 
//如果被选中
if s.isSelected(point:point)
// 声音播放
s.playAudio()
//更新屏幕显示
self.setNeedsDisplay()
]IIl
class ViewController:
UIViewController(
override func viewDidLoad() super.viewDidLoad()
// Do any additional setup after loading the view,typically from a nib.
//此处调用 FiveStar类,建立一个对象(实例)star

Amor.Y:
//五角星的中心坐标为(180,180)let starCenter =CGPoint(x:180,y:180)
//五角星的半径设定了90,旋转角度为15 度
let star =FiveStar(center:
starCenter,radius: 50, angel: 45star.lineColor =UlColor.blue
//此处调用 Circle 类,建立一个对象oval
let ovalCenter =CGPoint(x:100,y;300)
let ovalSize = CGSize(width:100,height:60)
let ovalmCircle(center:ovalCenter, size: ovalSize)
//此处调用 Rectangle 类,建立一个对象 rect
let rectOrigin=CGPoint(x:60,y:50)letrectSize = GSize(width: 100,height:50)
Let rect = Rectangle(origin:
rectorigin,size:rectSize,corner:6)rect.lineColor =UIColorgray
//此处建立了一个 Czfview 的实例myview
let myView =CzfView(frame:CGRect(x:0,y:0,width: self.view. frame.size width, height: self. viewframe.size.height))
//清除背景色
myView.backgroundColor=
UIColor.clear
//赋值给 myView 中的成员变量(属性)shape
myView.add(shape:star)
myView.add(shape:oval)
myView.add(shape:rect)
//显示 myView
self.view.addSubview(myView)
struct ManyFaces: View {
    static let emoji = [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "]

    var body: some View {
        TimelineView(.periodic(from: .now, by: 0.2)) { timeline in

            HStack(spacing: 120) {

                let randomEmoji = ManyFaces.emoji[Int.random(in: 0..<ManyFaces.emoji.count)]

                Text(randomEmoji)
                    .font(.largeTitle)
                    .scaleEffect(4.0)

                SubView()

            }
        }
    }

    struct SubView: View {
        var body: some View {
            let randomEmoji = ManyFaces.emoji[Int.random(in: 0..<ManyFaces.emoji.count)]

            Text(randomEmoji)
                .font(.largeTitle)
                .scaleEffect(4.0)
        }
    }
}
//url为MOCKMOCK 服务器的网址
if let url = URL(string: "http://localhost:3004/news") {
   URLSession.shared.dataTask(with: url) { (data, response, error) in
       if error != nil {
           print("Network errors")
        }
       else {
           let rs = String(data: data!, encoding: String.Encoding.utf8)! 
           print(rs)
           if let json = try? JSONSerialization.jsonObject(with: data!,
options: .allowFragments) {
                     print(json)
                 }
            }
      }
      .resume()
}

func sessionGetData() (
         //创建URL对象
         let uriString = "http://www.tuling123.com/" 
         let url = URL(string:urlString)
         //创建请求对象
         let request = URLRequest(url: url!)
         let session = URLSession.shared
         let dataTask = session.dataTask(with: request,
                 completionHandler: {(data, response, error) -> Void in
                        if error != nil{
                                 print(error.debugDescription)
                          }else{
                                 let str = String(data: data!, encoding:
String.Encoding.utf8)
                                 print(str!)
                          }
            }) as URLSessionTask
            //使用resume 方法启动任务 
            dataTask.resume()
        }

fune sessionDownloadImage(){
     // 下载地址
    let url = URL(string: "http://hangge.com/blog/images/logo.png")
    //请求
    let request = URLRequest(url: url!)
    let session = URLSession.shared
    // 下载任务
    let downloadTask = session.downloadTask(with: request,
completionHandler: {
(location:URL?, response:URLResponse?, error:Error?)
-> Void in
         //输出下载文件原来的存放目录
         print("location:\(String(describing: location))")
         //location 位置转换
         let locationPath = location? path
         // 获取当前时间 
         let now = NSDate() 
         //当前时间的时间截
         let timeInterval:TimeInterval = now.timeIntervalSince1970
         let timeStamp = String(timeInterval)
         //拷贝到用户目录
         let documents:String = NSHomeDirectory() + "/Documents/\
(timeStamp).png"
         //创建文件管理器
         let fileManager = FileManager.default
         try! fileManager.moveItem(atPath: locationPath!, topath:
documents)
         print("new location:\(documents)")
     })
     //使用resume方法启动任务 
     downloadTask.resume()
}

$ sudo apachectl start | stop | restart
#LoadModule php5_module libexec/apache2/libphp5.so
$ sudo cp /etc/php.ini.default /etc/php.ini
<?php
phpinfo();
?>
<?php
/** php 接收流文件
* @param String $file接收后保存的文件名
* @return boolean
*/
function receiveStreamFile($receiveFile){
    $streamData = isset($GLOBALS['HTTP_RAW_POST_DATA'])? $GLOBALS['HTTP_
RAW_POST_DATA'] :'';
    if(empty($streamData)){
        $streamData = file_get_contents('php://input');
        }
    if($streamData!=''){
        $ret = file_put_contents($receiveFile, $streamData, true);
    }else{
        $ret = false;
    }
    return $ret;
}
//定义服务器存储路径和文件名
$receiveFile = $_SERVER["DOCUMENT_ROOT"]."/uploadFiles/swift.png"; 
echo $receiveFile;
$ret = receiveStreamFile($receiveFile);
echo json_encode(array('success'=>(bool)$ret));
?>

func sessionUploadPhp(){
    //以文本或者二进制方式读入源程序文件的 Loader 
public struct Loader {
    static func readTxt(file url:URL) -> string? {
        do {
            let source = try String(contentsOf: url) 
            return source
        }
        catch {
            return nil
        }
    }
static func readBin(file url:URL) -> Data? {
        do {
            let data = try Data(contentsOf: url) 
            return data
        }
        catch {
            return nil
        }
}