From 1f3969e2b88a353061d4ea538d9ee05fd0f1a669 Mon Sep 17 00:00:00 2001 From: Richard Newman Date: Thu, 15 Jan 2015 17:53:28 -0800 Subject: [PATCH] Bug 1122224 - Part 8: move and extend Cursor. --- Client.xcodeproj/project.pbxproj | 18 ++------- Providers/Cursor.swift | 69 +++++++++++++++++++------------- 2 files changed, 46 insertions(+), 41 deletions(-) diff --git a/Client.xcodeproj/project.pbxproj b/Client.xcodeproj/project.pbxproj index e43f18982e1f..8be4646a017b 100644 --- a/Client.xcodeproj/project.pbxproj +++ b/Client.xcodeproj/project.pbxproj @@ -9,6 +9,7 @@ /* Begin PBXBuildFile section */ 0AE491A61A41C88C0046C724 /* BackForwardListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AE491A51A41C88C0046C724 /* BackForwardListViewController.swift */; }; 0B3342DE1A5CA93D000AE428 /* libsqlite3.0.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 0B3342DB1A5CA929000AE428 /* libsqlite3.0.dylib */; }; + 0B33431B1A5CB14B000AE428 /* Cursor.swift in Sources */ = {isa = PBXBuildFile; fileRef = D34DC8501A16C40C00D49B7B /* Cursor.swift */; }; 0B657B451A3B9CAB005A9E43 /* Site.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BDB952B1A3B9918000F2B0F /* Site.swift */; }; 0B657B461A3B9CAB005A9E43 /* Favicon.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BDB95291A3B9917000F2B0F /* Favicon.swift */; }; 0B79B17F1A3F6DD500DBECB3 /* Favicons.swift in Sources */ = {isa = PBXBuildFile; fileRef = D34DC8511A16C40C00D49B7B /* Favicons.swift */; }; @@ -17,6 +18,7 @@ 0B79B1891A3F6DE000DBECB3 /* Favicon.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BDB95291A3B9917000F2B0F /* Favicon.swift */; }; 0B79B18A1A3F6DE900DBECB3 /* Site.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BDB952B1A3B9918000F2B0F /* Site.swift */; }; 0B79B18B1A3F6DE900DBECB3 /* Site.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BDB952B1A3B9918000F2B0F /* Site.swift */; }; + 0B925B491A5C56E1007EA8E7 /* Cursor.swift in Sources */ = {isa = PBXBuildFile; fileRef = D34DC8501A16C40C00D49B7B /* Cursor.swift */; }; 0B9E3DE71A23FBD1008A7877 /* TestPanels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B9E3DE31A23FBD1008A7877 /* TestPanels.swift */; }; 0BA8964B1A250E6500C1010C /* AccountTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BA896491A250E6500C1010C /* AccountTest.swift */; }; 0BA8964C1A250E6500C1010C /* TestBookmarks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BA8964A1A250E6500C1010C /* TestBookmarks.swift */; }; @@ -81,48 +83,35 @@ D34DC8581A16C40C00D49B7B /* RestAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = D34DC8521A16C40C00D49B7B /* RestAPI.swift */; }; D34DC8611A16C47300D49B7B /* Profile.swift in Sources */ = {isa = PBXBuildFile; fileRef = D34DC84D1A16C40C00D49B7B /* Profile.swift */; }; D34DC8621A16C49600D49B7B /* AccountManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = D34DC84E1A16C40C00D49B7B /* AccountManager.swift */; }; - D34DC8631A16C49600D49B7B /* BookmarksREST.swift in Sources */ = {isa = PBXBuildFile; fileRef = D34DC84F1A16C40C00D49B7B /* BookmarksREST.swift */; }; - D34DC8641A16C49600D49B7B /* Cursor.swift in Sources */ = {isa = PBXBuildFile; fileRef = D34DC8501A16C40C00D49B7B /* Cursor.swift */; }; - D34DC8651A16C49600D49B7B /* Favicons.swift in Sources */ = {isa = PBXBuildFile; fileRef = D34DC8511A16C40C00D49B7B /* Favicons.swift */; }; - D34DC8661A16C49600D49B7B /* RestAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = D34DC8521A16C40C00D49B7B /* RestAPI.swift */; }; D34F86DB1A1AC35B00331EC4 /* LoginView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D34F86DA1A1AC35B00331EC4 /* LoginView.swift */; }; D34F86E71A1AC7DD00331EC4 /* PasswordTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = D34F86E61A1AC7DD00331EC4 /* PasswordTextField.swift */; }; D34F86E91A1ACD1200331EC4 /* ImageTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = D34F86E81A1ACD1200331EC4 /* ImageTextField.swift */; }; - D35179BC1A5C69FE00E7622E /* SearchViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D35179BB1A5C69FE00E7622E /* SearchViewController.swift */; }; D35179BD1A5C6D4200E7622E /* SearchViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D35179BB1A5C69FE00E7622E /* SearchViewController.swift */; }; - D35179BE1A5C8D5F00E7622E /* SearchEngines.swift in Sources */ = {isa = PBXBuildFile; fileRef = D308E4E31A5306F500842685 /* SearchEngines.swift */; }; D35179BF1A5C8D5F00E7622E /* SearchEngines.swift in Sources */ = {isa = PBXBuildFile; fileRef = D308E4E31A5306F500842685 /* SearchEngines.swift */; }; - D35179C01A5C8D6700E7622E /* OpenSearch.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3FA77831A43B2CE0010CD32 /* OpenSearch.swift */; }; D35179C11A5C8D6800E7622E /* OpenSearch.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3FA77831A43B2CE0010CD32 /* OpenSearch.swift */; }; D3968F251A38FE8500CEFD3B /* TabManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3968F241A38FE8500CEFD3B /* TabManager.swift */; }; D3A9949C1A3686BD008AD1AC /* BrowserViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3A994951A3686BD008AD1AC /* BrowserViewController.swift */; }; D3A9949D1A3686BD008AD1AC /* Browser.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3A994961A3686BD008AD1AC /* Browser.swift */; }; D3FA777B1A43B2990010CD32 /* SearchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3FA777A1A43B2990010CD32 /* SearchTests.swift */; }; - D3FA77841A43B2CE0010CD32 /* OpenSearch.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3FA77831A43B2CE0010CD32 /* OpenSearch.swift */; }; D3FA77971A43B5390010CD32 /* OpenSearch.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3FA77831A43B2CE0010CD32 /* OpenSearch.swift */; }; D3FA77C41A44F9A80010CD32 /* Locales in Resources */ = {isa = PBXBuildFile; fileRef = D3FA77C31A44F9A80010CD32 /* Locales */; }; E418D0D91A251B3200CAE47A /* Profile.swift in Sources */ = {isa = PBXBuildFile; fileRef = D34DC84D1A16C40C00D49B7B /* Profile.swift */; }; E418D0DA1A251B3200CAE47A /* AccountManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = D34DC84E1A16C40C00D49B7B /* AccountManager.swift */; }; E418D0DB1A251B3200CAE47A /* BookmarksREST.swift in Sources */ = {isa = PBXBuildFile; fileRef = D34DC84F1A16C40C00D49B7B /* BookmarksREST.swift */; }; E418D0DC1A251B3200CAE47A /* Clients.swift in Sources */ = {isa = PBXBuildFile; fileRef = E42CCDE21A23A6F900B794D3 /* Clients.swift */; }; - E418D0DD1A251B3200CAE47A /* Cursor.swift in Sources */ = {isa = PBXBuildFile; fileRef = D34DC8501A16C40C00D49B7B /* Cursor.swift */; }; E418D0DF1A251B3200CAE47A /* RestAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = D34DC8521A16C40C00D49B7B /* RestAPI.swift */; }; E418D0E01A25634D00CAE47A /* Alamofire.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F84B22301A0913F200AAB793 /* Alamofire.framework */; }; - E41A7D431A1BDFD800245963 /* FiraSans-Regular.ttf in Resources */ = {isa = PBXBuildFile; fileRef = E41A7D421A1BDFD800245963 /* FiraSans-Regular.ttf */; }; E41A7D441A1BDFD800245963 /* FiraSans-Regular.ttf in Resources */ = {isa = PBXBuildFile; fileRef = E41A7D421A1BDFD800245963 /* FiraSans-Regular.ttf */; }; - E41A7D481A1BE00100245963 /* FiraMono-Medium.ttf in Resources */ = {isa = PBXBuildFile; fileRef = E41A7D471A1BE00100245963 /* FiraMono-Medium.ttf */; }; E41A7D491A1BE00100245963 /* FiraMono-Medium.ttf in Resources */ = {isa = PBXBuildFile; fileRef = E41A7D471A1BE00100245963 /* FiraMono-Medium.ttf */; }; E41A7D4B1A1BE04500245963 /* InitialViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E41A7D4A1A1BE04500245963 /* InitialViewController.swift */; }; E41A7D4C1A1BE26000245963 /* FiraSans-SemiBold.ttf in Resources */ = {isa = PBXBuildFile; fileRef = F84B223B1A0914A300AAB793 /* FiraSans-SemiBold.ttf */; }; E41A7D4D1A1BE26700245963 /* FiraSans-Light.ttf in Resources */ = {isa = PBXBuildFile; fileRef = F84B223A1A0914A300AAB793 /* FiraSans-Light.ttf */; }; E41A7D4E1A1BE26B00245963 /* FiraSans-UltraLight.ttf in Resources */ = {isa = PBXBuildFile; fileRef = F84B223C1A0914A300AAB793 /* FiraSans-UltraLight.ttf */; }; E42CCDE31A23A6F900B794D3 /* Clients.swift in Sources */ = {isa = PBXBuildFile; fileRef = E42CCDE21A23A6F900B794D3 /* Clients.swift */; }; - E42CCDE71A23A73800B794D3 /* Clients.swift in Sources */ = {isa = PBXBuildFile; fileRef = E42CCDE21A23A6F900B794D3 /* Clients.swift */; }; E42CCDE81A23A73D00B794D3 /* Profile.swift in Sources */ = {isa = PBXBuildFile; fileRef = D34DC84D1A16C40C00D49B7B /* Profile.swift */; }; E42CCDE91A23A74000B794D3 /* AccountManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = D34DC84E1A16C40C00D49B7B /* AccountManager.swift */; }; E42CCDEA1A23A74400B794D3 /* RestAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = D34DC8521A16C40C00D49B7B /* RestAPI.swift */; }; E42CCDEB1A23A76200B794D3 /* BookmarksREST.swift in Sources */ = {isa = PBXBuildFile; fileRef = D34DC84F1A16C40C00D49B7B /* BookmarksREST.swift */; }; - E42CCDEC1A23A76400B794D3 /* Cursor.swift in Sources */ = {isa = PBXBuildFile; fileRef = D34DC8501A16C40C00D49B7B /* Cursor.swift */; }; E42CCDEE1A23C2C600B794D3 /* Clients.swift in Sources */ = {isa = PBXBuildFile; fileRef = E42CCDE21A23A6F900B794D3 /* Clients.swift */; }; E42CCDEF1A23C84700B794D3 /* FiraSans-Regular.ttf in Resources */ = {isa = PBXBuildFile; fileRef = E41A7D421A1BDFD800245963 /* FiraSans-Regular.ttf */; }; E42CCDF01A23C8FC00B794D3 /* Snappy.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E4D6BEAD1A092AD300F538BD /* Snappy.framework */; }; @@ -1190,6 +1179,7 @@ 28784D491A39C48900021E35 /* Bytes.swift in Sources */, E418D0DC1A251B3200CAE47A /* Clients.swift in Sources */, 0B79B1881A3F6DE000DBECB3 /* Favicon.swift in Sources */, + 0B925B491A5C56E1007EA8E7 /* Cursor.swift in Sources */, 28784D1A1A38CA9400021E35 /* Bookmarks.swift in Sources */, E42CCE031A24C4E300B794D3 /* ExtensionUtils.swift in Sources */, D34C5AF41A5E0C9B00E0DF7B /* SWXMLHash.swift in Sources */, @@ -1197,7 +1187,6 @@ F8708D321A0970B70051AB07 /* ShareViewController.swift in Sources */, E418D0DF1A251B3200CAE47A /* RestAPI.swift in Sources */, 28CDA55C1A43C37C005C318C /* ProfilePrefs.swift in Sources */, - E418D0DD1A251B3200CAE47A /* Cursor.swift in Sources */, E41A7D4B1A1BE04500245963 /* InitialViewController.swift in Sources */, D35179BE1A5C8D5F00E7622E /* SearchEngines.swift in Sources */, 0BE00DC31A5DE1CE0081E374 /* FileAccessor.swift in Sources */, @@ -1219,6 +1208,7 @@ D35179C11A5C8D6800E7622E /* OpenSearch.swift in Sources */, E42CCDEB1A23A76200B794D3 /* BookmarksREST.swift in Sources */, E42CCDE91A23A74000B794D3 /* AccountManager.swift in Sources */, + 0B33431B1A5CB14B000AE428 /* Cursor.swift in Sources */, E42CCDE81A23A73D00B794D3 /* Profile.swift in Sources */, E42CCDEC1A23A76400B794D3 /* Cursor.swift in Sources */, E42CCE041A24C4E300B794D3 /* ExtensionUtils.swift in Sources */, diff --git a/Providers/Cursor.swift b/Providers/Cursor.swift index b8d28379ba68..e9d228d2cd8c 100644 --- a/Providers/Cursor.swift +++ b/Providers/Cursor.swift @@ -13,62 +13,77 @@ enum CursorStatus { } /** - * Provides a generic method of returning some data and status information about a request. - */ -protocol Cursor : SequenceType { - typealias ItemType - var count: Int { get } +* Provides a generic method of returning some data and status information about a request. +*/ +public class Cursor :SequenceType { + var count: Int { + get { return 0 } + } // Extra status information - var status : CursorStatus { get } - var statusMessage : String { get } + var status: CursorStatus + var statusMessage: String + + init(err: NSError) { + self.status = .Failure + self.statusMessage = err.description + } + + init(status: CursorStatus = CursorStatus.Success, msg: String = "") { + self.status = status + self.statusMessage = msg + } // Collection iteration and access functions - subscript(index: Int) -> ItemType? { get } - func generate() -> GeneratorOf + subscript(index: Int) -> Any? { + get { return nil } + } + + public func generate() -> GeneratorOf { + var nextIndex = 0; + return GeneratorOf() { + if (nextIndex >= self.count || self.status != CursorStatus.Success) { + return nil + } + + return self[nextIndex++] + } + } } /* * A cursor implementation that wraps an array. */ -class ArrayCursor : Cursor { +class ArrayCursor : Cursor { private let data : [T]; - let status : CursorStatus; - let statusMessage : String = ""; - var count : Int { + override var count : Int { if (status != CursorStatus.Success) { return 0; } return data.count; } - - func generate() -> GeneratorOf { - var nextIndex = 0; - return GeneratorOf() { - if (nextIndex >= self.data.count || self.status != CursorStatus.Success) { - return nil; - } - return self.data[nextIndex++]; - } - } init(data: [T], status: CursorStatus, statusMessage: String) { self.data = data; + super.init() self.status = status; self.statusMessage = statusMessage; } init(data: [T]) { self.data = data; + super.init() self.status = CursorStatus.Success; self.statusMessage = "Success"; } - subscript(index: Int) -> T? { - if (index >= data.count || index < 0 || status != CursorStatus.Success) { - return nil; + override subscript(index: Int) -> Any? { + get { + if (index >= data.count || index < 0 || status != CursorStatus.Success) { + return nil; + } + return data[index]; } - return data[index]; } }