swift - The Prototype Pattern

前端之家收集整理的这篇文章主要介绍了swift - The Prototype Pattern前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

import Foundation


class@H_@R_301_449@_10@ Sum : NSObject@H_@R_301_449@_10@,NSCopying@H_@R_301_449@_10@ {

var resultsCache: [[Int]];

var firstValue:Int;

var secondValue:Int;

init(first:Int,second:Int) {

resultsCache = [[Int]](count: 10,repeatedValue:

[Int](count:10,repeatedValue: 0));

for i in 0..<10 {

for j in 0..<10 {

resultsCache[i][j] = i + j;

}

}

self.firstValue = first;

self.secondValue = second;

}

private init(first:Int,second:Int,cache:[[Int]]) {

self.firstValue = first;

self.secondValue = second;

resultsCache = cache;

}

var Result:Int {

get {

@H_@R_301_449@_10@ return@H_@R_301_449@_10@ firstValue@H_@R_301_449@_10@ < resultsCache@H_@R_301_449@_10@.count

@H_@R_301_449@_10@ && secondValue@H_@R_301_449@_10@ < resultsCache@H_@R_301_449@_10@[firstValue@H_@R_301_449@_10@].count

@H_@R_301_449@_10@ ? resultsCache@H_@R_301_449@_10@[firstValue@H_@R_301_449@_10@][secondValue@H_@R_301_449@_10@]

: firstValue + secondValue;

}

}

func copyWithZone(zone: NSZone) -> AnyObject {

return Sum(first:self.firstValue,

second: self.secondValue,

cache: self.resultsCache);

}

}


var prototype = Sum(first:0,second:9);

var@H_@R_301_449@_10@ calc1 = prototype@H_@R_301_449@_10@.Result@H_@R_301_449@_10@;

var clone = prototype.copy() as! Sum;

clone@H_@R_301_449@_10@.firstValue@H_@R_301_449@_10@ = 3@H_@R_301_449@_10@; clone@H_@R_301_449@_10@.secondValue@H_@R_301_449@_10@ = 8@H_@R_301_449@_10@;

var calc2 = clone.Result;


println@H_@R_301_449@_10@("Calc1: @H_@R_301_449@_10@\(calc1) Calc2: @H_@R_301_449@_10@\(calc2)"@H_@R_301_449@_10@);

猜你在找的Swift相关文章