【IOS沉思录】开发软硬件SDK支持以及Swift语言
发布时间:2020-12-14 06:32:42 所属栏目:百科 来源:网络整理
导读:iPhone和iPad 软件支持 iOS 2007年发布 2008年发布开发者SDK iOS当前的版本为:10.2 官方开发者论坛:Apple Developer Forums 官方开发者教程文档资源库:Resources 硬件支持 A10处理器(iPhone7/7+) A9处理器(iPhone6s/6s+) A8处理器(iPhone6/iPhone6+)
软件支持iOS
硬件支持
Apple Watch软件支持
硬件支持
Apple TV(2015)软件支持
硬件支持
iOS SDK 9.0/9.1特性
iOS SDK 10.0新特性
Swift的主要新特性:
从基本的ViewController代码窥探OC和Swift区别
// ViewController.swift
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var label1: UILabel!
@IBAction func button1(sender: AnyObject) {
label1.text = "Hello iOS!!!"
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view,typically from a nib.
}
override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// ViewController.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@property (weak,nonatomic) IBOutlet UILabel *label1; - (IBAction)button1:(id)sender;
@end
// ViewController.m
#import "ViewController.h"
@interface ViewController () @end
@implementation ViewController @synthesize label1 ;
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view,typically from a nib.
}
- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)button1:(id)sender {
label1.text = @"Hello iOS!!!" ;
}
@end
Swift类的定义整个类文件都定义在一个swift文件内: import Foundation
class Ball {
// 变量
var centerX: Float
var centerY: Float
var radius: Float
// 初始化方法
init(centerX:Float,centerY:Float,radius:Float) {
self.centerX = centerX
self.centerY = centerY
self.radius = radius
}
// 实例方法
func move(moveX:Float,_ moveY:Float) {
self.centerX += moveX
self.centerY += moveY
}
// 类方法
class func aClassMethod() {
print("I am a class method")
}
}
...
// 创建对象
var ball1 = Ball(centerX: 7.0,centerY: 5.0,radius: 6.0)
// 方法调用
ball1.move(moveX:1.0,1.0)
Ball.aClassMethod()
流程控制语句
// 条件判断
if (a < b) {
// Do something here
} else {
// Do another thing here
}
// for循环
for (int i = 0; i < 10; i++){
// Do something here
}
// while循环
while (count < 10) {
// Do something here
}
// do-while循环
do {
// Do something here
} while (count < 10);
// 条件判断
if a < b {
// Do something here
} else {
// Do another thing here
}
// for循环
for int i = 0; i < 10; i++{
// Do something here
}
// while循环
while count < 10 {
// Do something here
}
// repeat-while循环
repeat {
// Do something here
} while count < 10
基本数据类型String字符串
NSString * Str = @"string";
NSString * formatStr = [NSString stringWithFormat:@"%@and float%f",Str,3.1415"];
// 可变字符串
var Str = "string"
var Str:String = "string"
var Str = String("string")
// 不可变字符串
let Str = "string"
let Str:String = "string"
let Str = String("string")
数组Array和MultableArray
// 静态数组
NSArray *array = [[NSArray alloc] initWithObjects: ball1,ball2,nil];
array[0].radius = 10;
// 可变数组
NSMutableArray *mArray = [[NSMutableArray alloc] initWithCapacity: 2];
[mArray addObject:ball1];
[mArray addObject:ball2];
Ball *newball = [mArray objectAtIndex:1];
[mArray removeObjectAtIndex:1];
// 静态数组
let myArray: Array<Ball> = [ball1,ball2]
let myArray: [Ball] = [ball1,ball2]
let myArray = [ball1,ball2]
myArray[0].radius = 10
// 可变数组
var myArray: [Ball] = []
myArray.append(ball1)
myArray.append(ball2)
var newBall = myArray[1];
myArray.remove(at: 0)
UIImageView
UIImageView *myImage = [[UIImageView alloc] initWithImage: [UIImage imageNamed:@”tiger.png”]];
[self.view addSubview:myImage];
myImage.center = CGPointMake(150,200);
myImage.frame = CGRectMake(0,0,50,25);
let myImage = UIImageView(image: UIImage(named: "tiger.png"))
view.addSubview(myImage)
myImage2.frame = CGRect(x:0,y:0,width:50,height:25)
myImage2.center = CGPoint(x:150,y:200)
… … (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |