【IOS沉思录】开发软硬件SDK支持以及Swift语言

来源:互联网 发布:php rsasig 编辑:程序博客网 时间:2024/05/12 05:53

iPhone和iPad

软件支持


iOS

  • 2007年发布
  • 2008年发布开发者SDK
  • iOS当前的版本为:10.2
  • 官方开发者论坛:Apple Developer Forums
  • 官方开发者教程文档资源库:Resources

硬件支持


  • A10处理器(iPhone7/7+)
  • A9处理器(iPhone6s/6s+)
  • A8处理器(iPhone6/iPhone6+)
  • A8X处理器(iPad Air2)
  • A7处理器(iPad Mini3),A7开始处理器为64位
  • 运动辅助处理器(iPhone5s和iPad Air之后)
  • 3D Touch(iPhone6s/6s+之后)
  • 亮度传感器
  • 靠近设备感应器
  • 多点触控(multi-touch)屏幕
  • 加速器
  • 数字罗盘
  • 三轴陀螺仪
  • 辅助GPS(AGPS)
  • 气压计(iPhone 6和iPad Air2之后)
  • 指纹传感器(iPhone 5s和iPad Air2之后)
  • 压力传感器(iPhone 6s and iPhone 7)
  • 触觉反馈引擎(iPhone 6s and iPhone 7)
  • 前后摄像头(模式可调分辨率)

Apple Watch和Apple TV

Apple Watch

软件支持


  • WatchOS(最前版本WatchOS 3.0)

硬件支持


  • 处理器
    • 苹果S1单片机
    • 苹果S2单片计算机
  • 传感器
    • 环境光传感器
    • 加速传感器和陀螺仪
    • 心率传感器
    • GPS(只支持Series2)
  • 数据连接
    • 蓝牙4.0(LTE)
    • Wifi 802.11b/g/n 2.4 GHz(仅限在系统中使用)
  • 充电
    • 电感应充电

Apple TV(2015)

软件支持


  • Apple tvOS
  • SDK available for Apps Development

硬件支持


  • 处理器(A8)
  • 遥控传感器
    • 加速器和陀螺仪
    • 触摸传感器
    • Siri麦克风
  • 数据连接
    • 蓝牙4.0 (LE)
    • 红外线接收器
    • 820.11交流Wifi天线系统
    • 10/100 BASE-T以太网
    • USB-C服务和支持

iOS SDK

2009年iPhone SDK 3.0发布,现在已经更新到iOS SDK 10.0。

iOS SDK 9.0/9.1特性


  • Apple Pay
  • App应用程序扩展
  • Touch ID指纹识别授权认证
  • Metal游戏引擎
  • HealthKit, HomeKit, iPad多任务切换改进功能
  • 3D Touch搜索GameplayKit
  • App应用瘦身
  • 从左到右的语言支持
  • Swift改进

iOS SDK 10.0新特性


  • SiriKit
  • Callkit
    • 集成VOIP
    • 呼叫屏蔽
  • Homekit改进(在控制中心组织Homekit配件)
  • Apple Pay改进
  • 消息应用程序集成
  • Widget改进

iOS技术架构

  • Cocoa Touch框架层
    • UI组件
    • 触摸处理和事件驱动
    • 系统接口
  • Media媒体层
    • 音频视频播放
    • 动画
    • 2d和3d图形
  • Core Servie核心服务层
    • 底层特性
    • 文件
    • 网络
    • 位置服务等
  • Core OS系统层
    • 内存管理
    • 底层网络
    • 硬件管理

新型语言Swift(从OC到Swift)

Swift是一门新型语言,借鉴了Haskell, Ruby, Python, C#等语言特性,看上去偏脚本化,swift仍然支持已有的Cocoa和Cocoa Touch框架。

Swift的主要新特性:

  • 安全【严格的类型检查】
  • 强大【高度优化的LLVM编译器】
  • 新型【借鉴多种语言特性,表达更简单精确】

这里写图片描述

从基本的ViewController代码窥探OC和Swift区别


Swift

// ViewController.swiftimport UIKitclass 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.}

Objective-C

// 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 Foundationclass 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()

流程控制语句

Objective-c

// 条件判断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);

Swift

// 条件判断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字符串


Objective-C

NSString * Str = @"string"; NSString * formatStr = [NSString stringWithFormat:@"%@and float%f", Str, 3.1415"]; 

Swift

// 可变字符串var Str = "string"var Str:String = "string"var Str = String("string")// 不可变字符串let Str = "string"let Str:String = "string"let Str = String("string")

数组Array和MultableArray


Objective-C

// 静态数组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];

Swift

// 静态数组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


Objective-C

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);

Swift

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)

… …

1 0