 
 
 
-extension StreamReader : SequenceType {
-    func generate() -> GeneratorOf<String> {
-        return GeneratorOf<String> {
+extension StreamReader : Sequence {
+    func makeIterator() -> AnyIterator<String> {
+        return AnyIterator<String> {
             return self.nextLine()
         }
     }

        if atEOF {
            return nil
        }

        // Read data chunks from file until a line delimiter is found:
        var range = buffer.rangeOfData(delimData, options: nil, range: NSMakeRange(0, buffer.length))
        while range.location == NSNotFound {
            var tmpData = fileHandle.readDataOfLength(chunkSize)
            if tmpData.length == 0 {
                // EOF or read error.
                atEOF = true
                if buffer.length > 0 {
                    // Buffer contains last line in file (not terminated by delimiter).
                    let line = NSString(data: buffer, encoding: encoding);
                    buffer.length = 0
                    return line
                }
                // No more lines.
                return nil
            }
            buffer.appendData(tmpData)
            range = buffer.rangeOfData(delimData, options: nil, range: NSMakeRange(0, buffer.length))
        }
        
        // Convert complete line (excluding the delimiter) to a string:
        let line = NSString(data: buffer.subdataWithRange(NSMakeRange(0, range.location)),
            encoding: encoding)
        // Remove line (and the delimiter) from the buffer:
        buffer.replaceBytesInRange(NSMakeRange(0, range.location + range.length), withBytes: nil, length: 0)
        
        return line
    }
    
    func rewind() {
        fileHandle.seekToFileOffset(0)
        buffer.length = 0
        atEOF = false
    }

            return nil
        }
        
        if let delimData = delimiter.data(using: encoding) {
            self.delimData = delimData as NSData!
        }else{
            return nil
        }
