![](https://img-blog.csdnimg.cn/20201014180756780.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
swift
vczxh
c++
展开
-
swift2.0 - study
//// main.swift// mycmd//// Created by zhaoxuhui on 15/10/27.// Copyright © 2015年 zhaoxuhui. All rights reserved.//import Foundationvar str = "Hello, pl原创 2015-11-05 22:59:44 · 612 阅读 · 0 评论 -
swift - The Builder Pattern
利用类构造函数默认参数,创建一个类。未完待续,code。翻译 2015-08-10 09:18:35 · 440 阅读 · 0 评论 -
swift - The Factory Method Pattern
class RentalCar { private var nameBV:String; private var passengersBV:Int; private var priceBV:Float; private init(name:String, passengers:Int, price:Float) {翻译 2015-08-09 23:00:52 · 377 阅读 · 0 评论 -
swift - The Prototype Pattern
Pro Design Pattern in Swift翻译 2015-08-09 22:22:25 · 358 阅读 · 0 评论 -
swift - Abstract Factory Pattern
It allows a calling component to obtain a family or group of related objects without needing to know which classes were used to create them.每一层的创建都是工厂,并且客户端和中间层是不知道具体零件的类型的。client:let car翻译 2015-08-09 23:49:19 · 622 阅读 · 0 评论 -
swift enum Int
enum rank:Int{ case r1 = 1 case r2 = 2 case r3 = 3 func description()->String{ //enum转String switch(self){ case r1: return "R1";原创 2015-06-14 11:27:55 · 2247 阅读 · 0 评论 -
swift class
//: Playground - noun: a place where people can playimport Cocoavar str = "Hello, playground"class Person { var age:Int;//类成员变量默认是public var name:String?;//原创 2015-06-14 11:24:55 · 402 阅读 · 0 评论 -
swift struct
//: Playground - noun: a place where people can playimport Cocoavar str = "Hello, playground"struct point{ var x = 0; var y = 0; init(x:Int,y:Int){原创 2015-06-14 11:22:45 · 521 阅读 · 0 评论 -
swift override --有一个递归问题未解决
class ca{ var count:Int{ get{ return 1; } set{ self.count = newValue; } } func describe()->String{ return "原创 2015-06-14 23:22:33 · 583 阅读 · 2 评论 -
swift generics 泛型
//泛型函数func repeat(item:ItemType,count:Int)->[ItemType] { var result = [ItemType](); for i in 0.. result.append(item); } return result;}var re = r原创 2015-06-14 11:30:17 · 385 阅读 · 0 评论 -
swift closure
//: Playground - noun: a place where people can play//闭包closure,类似c语言的函数指针或oc的blocks//闭包可以让代码显得非常简洁import Cocoa////////////////////////////函数定义func iscontain(arr:[Int],value:Int,cb:(原创 2015-06-14 11:20:07 · 514 阅读 · 0 评论 -
swift - 函数指针的应用 - 避免重复算法
class DataSourceBase : EmployeeDataSource {var employees = [Employee]();func searchByName(name: String) -> [Employee] {return search({e -> Bool inreturn e.name.rangeOfString(name) != nil;});翻译 2015-08-11 09:04:53 · 348 阅读 · 0 评论 -
swift - The Facade Pattern
Facade(外观)模式为子系统中的各类(或结构与方法)提供一个简明一致的界面,隐藏子系统的复杂性,使子系统更加容易使用。它是为子系统中的一组接口所提供的一个一致的界面。client:import Foundation;let facade =PirateFacade();let prize = facade.getTreasur翻译 2015-08-25 23:20:47 · 315 阅读 · 0 评论 -
swift public、internal和private
Swift提供了3种不同访问级别,对应的访问修饰符为:public、internal和private。这些访问修饰符可以修饰类、结构体、枚举等面向对象的类型,还可以修饰变量、常量、下标、元组、函数、属性等内容。提示 为了便于描述,我们把类、结构体、枚举、变量、常量、下标、元组、函数、属性等内容统一称为“实体”。public。可以访问自己模块中的任何public实体。原创 2015-08-06 22:21:52 · 5624 阅读 · 0 评论 -
swift - The command pattern
The command pattern provides a mechanism by which details of how to invoke a method can beencapsulated so that the method can be invoked later or by a different component. 命令模式:把每一次执行的命令放到一个队翻译 2015-09-01 23:41:24 · 422 阅读 · 0 评论 -
swift 一疑问:reduce
var products = [Product(name: "Kayak", description: "A boat for one person",price: 275, stock: 10),Product(name: "Lifejacket", description: "Protective and fashionable",price: 48.95, stock: 14原创 2015-08-06 09:34:04 · 601 阅读 · 1 评论 -
swift - The Chain Responsibility pattern
The chain of responsibility pattern is useful when there are multiple objects that could takeresponsibility for a request but you don’t want to expose details of those objects to the callingcomponent.翻译 2015-08-31 23:40:31 · 394 阅读 · 0 评论 -
swift - The Flyweight Pattern
The flyweight pattern is applied when a number of similar objects all rely on the same set of datavalues. Rather than create a new set of data valued for each of the objects, the flyweight patternsh翻译 2015-08-27 23:33:30 · 392 阅读 · 0 评论 -
swift - The Proxy Pattern
I describe the proxy pattern in this chapter, which is used when an object is required to act as an interface to another object or resource. There are three main ways in which the proxy pattern is a翻译 2015-08-28 23:51:27 · 406 阅读 · 0 评论 -
AVAudioPlayer播放mp3模拟器有声真机无声的解决方法
使用AVAudioPlayer播放mp3,在模拟器中能播放,真机上播放却没有声音,后来逐一检查以下几项用来排除问题:1、设备是否静音2、其他应用是否有声音3、clean target、删除应用并重新安装来回折腾后问题依旧,最终的解决方法如下:在- (void)applicationDidFinishLaunching:(UIApplication *)app原创 2015-08-02 20:13:27 · 2041 阅读 · 0 评论 -
swift - The Composite Pattern
It shows you how the composite pattern can be used so that different kinds of objects in a tree data structure can be treated consistently. 复合模式:这个设计模式为你展示了不同类型的在树中的数据结构如何一致的对待。翻译 2015-08-12 22:48:11 · 355 阅读 · 0 评论 -
swift - The Decorator Pattern
装饰者模式:多个类派生于一个基础类,这几个类可以嵌套构造来装饰。client:let account =CustomerAccount(name:"Joe");account.addPurchase(Purchase(product:"Red Hat", price: 10));account.addPurchase(Purchase(product:翻译 2015-08-12 22:08:17 · 399 阅读 · 0 评论 -
swift - The Adapter Pattern
This pattern allows two objects that provide related functionality to work together even when they have incompatible APIs.Diagram:client:let search = SearchTool(dataSources: SalesDataSou翻译 2015-08-11 09:29:45 · 385 阅读 · 0 评论 -
swift protocol
//: Playground - noun: a place where people can playimport Cocoa@objc protocol SortProtocol:NSObjectProtocol{ func same(value:Int)->Bool; //@optional func beg原创 2015-06-14 11:26:44 · 324 阅读 · 0 评论 -
Swift中的required修饰符
http://blog.csdn.net/yongyinmg/article/details/39673345普通子类通常情况下,一说到required修饰符,我们最先想到的应该就是普通类(class)的init()方法了。比如下面这个类:class MyClass { var str:String init(str:String) { self.str =转载 2015-06-14 11:27:32 · 399 阅读 · 0 评论 -
swift 传值 引用 (=、&)
var a =1;var b =a;a=2;println("\(a),\(b)");//2,1struct cs{ var v:Int =99;}var i =cs();var j =i;i.v =98;println("\(i.v),\(j.v)");//98,99class c原创 2015-06-21 16:25:56 · 1056 阅读 · 1 评论 -
swift runtime type
var v =1.0;println(v.dynamicType);//Swift.Double原创 2015-06-21 11:35:18 · 706 阅读 · 0 评论 -
swift operator+()
class mypoint{ var x:Int =1; var y:Int =1; init(#x:Int,#y:Int){ self.x = x; self.y = y; } var description:String{//在这里稍有贪心,做一描述成员get变量 get{ ret原创 2015-06-21 15:55:40 · 761 阅读 · 0 评论 -
swift optional chaining
class ca{ var num:Int =1;}class cb{ var a:ca?;}class cc{ var b:cb?;}var x:cc =cc();var y:Int? =x.b?.a?.num;//或var y = x.b?.a?.num;println("y =\(y),\r\原创 2015-06-21 11:32:28 · 701 阅读 · 0 评论 -
swift oerator[](int i)
class ca{ var v:[Int] = [Int](); subscript(index:Int)->Int{ return v[index]; }}var v =ca();v.v.append(1);v.v.append(2);println(v[1]);原创 2015-06-21 17:11:19 · 414 阅读 · 0 评论 -
swift ??
var a:Int?;var b:Int =a ?? 1;//注意空格,相当于c语言 a!=NULL?a:1;println(b);原创 2015-06-21 10:58:25 · 509 阅读 · 0 评论 -
swift tuple多元组
func swapme(inout a:T,inout b:T,inout c:T){ (a,b,c) = (b,c,a);}var a:Int =1;var b:Int =2;var c:Int =3;println("\(a),\(b),\(c)");swapme(&a, &b, &c);println("\(a),\(原创 2015-06-21 10:46:36 · 864 阅读 · 0 评论 -
swift protocol mutating
protocol base{ var number:Int{get}; mutatingfunc changeNum();//如果protocol不写mutating那么struct、enum实现此协议将会报错}struct Derive:base { var number = 1; mutating func change原创 2015-06-21 10:16:57 · 403 阅读 · 0 评论 -
swift down cast
class ca{ var vaName = "ca";}class cb:ca { var vbName = "cb";}var item:ca =cb();iflet cbitem = itemas? cb{ println(cbitem.vbName);}原创 2015-06-16 21:13:18 · 409 阅读 · 0 评论 -
swift Any AnyObject
class ca{ }class cb:ca{ }var library:[Any] = [ca(),cb(),1,]for itemin library{ if let intitem = itemas? Int{ println(item); }}原创 2015-06-16 22:58:44 · 468 阅读 · 0 评论 -
swift 单例模式
class ca{ var count = 1; static var instance:ca =ca(); class func GetInstance()->ca{ return instance; }}var a = ca.GetInstance();var b = ca.GetInstan原创 2015-06-22 17:09:53 · 677 阅读 · 0 评论 -
swift switch Double
var v =0.5;switch v{case0...1: println("0...1");default: println("区间外");}原创 2015-06-22 22:12:28 · 609 阅读 · 0 评论 -
swift enum
//: Playground - noun: a place where people can playimport Cocoavar str = "Hello, playground"enum Direction{ case North case South case East原创 2015-06-14 11:21:37 · 431 阅读 · 0 评论 -
swift dataStruct
println("Hello, World!")var v1 = ["name":"zxh","age":30,"score":100];println(v1);for v in v1{ println(v);}v1["work"] = "c++";println(v1);var v2 = [原创 2015-06-14 11:18:10 · 386 阅读 · 0 评论 -
swift func
//初学者,记事本是最好的记忆工具,因为它不会矫正语法变量拼写错误,然后转移到IDE会提示语法错误,单词错误。从此记忆深刻。//// main.swift// myswift//// Created by zhaoxuhui on 15/4/9.// Copyright (c) 2015年 zhaoxuhui. All rights rese原创 2015-06-14 10:52:00 · 578 阅读 · 0 评论