Skip to content

Commit

Permalink
Use arrayLiteralConvertible
Browse files Browse the repository at this point in the history
  • Loading branch information
dmauro committed Aug 20, 2014
1 parent 1bb5c62 commit 4a4cf5a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
type = "1"
version = "2.0">
</Bucket>
12 changes: 9 additions & 3 deletions WeakArray/WeakArray.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private class Weak<T: AnyObject> {

// MARK:-

public struct WeakArray<T: AnyObject>: SequenceType, Printable, DebugPrintable {
public struct WeakArray<T: AnyObject>: SequenceType, Printable, DebugPrintable, ArrayLiteralConvertible {
// MARK: Private
private typealias WeakObject = Weak<T>
private typealias GeneratorType = WeakGenerator<T>
Expand All @@ -58,10 +58,16 @@ public struct WeakArray<T: AnyObject>: SequenceType, Printable, DebugPrintable {
}

// MARK: Methods
public init(array: [T] = []) {
self += array
public static func convertFromArrayLiteral(elements: T...) -> WeakArray<T> {
var a = WeakArray<T>()
for element in elements {
a.append(element)
}
return a
}

public init() {}

public func generate() -> GeneratorType {
let weakSlice: Slice<WeakObject> = items[0..<items.count]
let slice: Slice<T?> = weakSlice.map { $0.value }
Expand Down
2 changes: 1 addition & 1 deletion WeakArrayTests/WeakArrayTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class WeakArrayTests: XCTestCase {

func testCanBeConstructedWithArrayLiteral() {
var obj: Object? = Object()
var a = WeakArray<Object>(array: [obj!])
var a: WeakArray<Object> = [obj!]
XCTAssert(a[0] == obj, "Object was not added")
}
}
Expand Down

0 comments on commit 4a4cf5a

Please sign in to comment.