@@ -124,32 +124,52 @@ struct CurrentInstallationContainer<T: ParseInstallation>: Codable {
124124
125125// MARK: Current Installation Support
126126extension ParseInstallation {
127- static var currentInstallationContainer : CurrentInstallationContainer < Self > {
127+ static var currentContainer : CurrentInstallationContainer < Self > {
128128 get {
129129 guard let installationInMemory: CurrentInstallationContainer < Self > =
130- try ? ParseStorage . shared. get ( valueFor: ParseStorage . Keys. currentInstallation) else {
130+ try ? ParseStorage . shared. get ( valueFor: ParseStorage . Keys. currentInstallation) else {
131131 #if !os(Linux) && !os(Android)
132- guard let installationFromKeyChain: CurrentInstallationContainer < Self > =
132+ guard let installationFromKeyChain: CurrentInstallationContainer < Self > =
133133 try ? KeychainStore . shared. get ( valueFor: ParseStorage . Keys. currentInstallation)
134- else {
135- var newInstallation = CurrentInstallationContainer < Self > ( )
136- let newInstallationId = UUID ( ) . uuidString. lowercased ( )
137- newInstallation. installationId = newInstallationId
138- newInstallation. currentInstallation? . createInstallationId ( newId: newInstallationId)
139- newInstallation. currentInstallation? . updateAutomaticInfo ( )
140- try ? KeychainStore . shared. set ( newInstallation, for: ParseStorage . Keys. currentInstallation)
141- try ? ParseStorage . shared. set ( newInstallation, for: ParseStorage . Keys. currentInstallation)
142- return newInstallation
134+ else {
135+ let newInstallationId = UUID ( ) . uuidString. lowercased ( )
136+ var newInstallation = BaseParseInstallation ( )
137+ newInstallation. installationId = newInstallationId
138+ newInstallation. createInstallationId ( newId: newInstallationId)
139+ newInstallation. updateAutomaticInfo ( )
140+ let newBaseInstallationContainer =
141+ CurrentInstallationContainer < BaseParseInstallation > ( currentInstallation: newInstallation,
142+ installationId: newInstallationId)
143+ try ? KeychainStore . shared. set ( newBaseInstallationContainer,
144+ for: ParseStorage . Keys. currentInstallation)
145+ guard let installationFromKeyChain: CurrentInstallationContainer < Self > =
146+ try ? KeychainStore . shared. get ( valueFor: ParseStorage . Keys. currentInstallation)
147+ else {
148+ // Couldn't create container correctly, return empty one.
149+ return CurrentInstallationContainer < Self > ( )
143150 }
151+ try ? ParseStorage . shared. set ( installationFromKeyChain, for: ParseStorage . Keys. currentInstallation)
144152 return installationFromKeyChain
153+ }
154+ return installationFromKeyChain
145155 #else
146- var newInstallation = CurrentInstallationContainer < Self > ( )
147- let newInstallationId = UUID ( ) . uuidString. lowercased ( )
148- newInstallation. installationId = newInstallationId
149- newInstallation. currentInstallation? . createInstallationId ( newId: newInstallationId)
150- newInstallation. currentInstallation? . updateAutomaticInfo ( )
151- try ? ParseStorage . shared. set ( newInstallation, for: ParseStorage . Keys. currentInstallation)
152- return newInstallation
156+ let newInstallationId = UUID ( ) . uuidString. lowercased ( )
157+ var newInstallation = BaseParseInstallation ( )
158+ newInstallation. installationId = newInstallationId
159+ newInstallation. createInstallationId ( newId: newInstallationId)
160+ newInstallation. updateAutomaticInfo ( )
161+ let newBaseInstallationContainer =
162+ CurrentInstallationContainer < BaseParseInstallation > ( currentInstallation: newInstallation,
163+ installationId: newInstallationId)
164+ try ? ParseStorage . shared. set ( newBaseInstallationContainer,
165+ for: ParseStorage . Keys. currentInstallation)
166+ guard let installationFromMemory: CurrentInstallationContainer < Self > =
167+ try ? ParseStorage . shared. get ( valueFor: ParseStorage . Keys. currentInstallation)
168+ else {
169+ // Couldn't create container correctly, return empty one.
170+ return CurrentInstallationContainer < Self > ( )
171+ }
172+ return installationFromMemory
153173 #endif
154174 }
155175 return installationInMemory
@@ -160,19 +180,19 @@ extension ParseInstallation {
160180 }
161181
162182 internal static func updateInternalFieldsCorrectly( ) {
163- if Self . currentInstallationContainer . currentInstallation? . installationId !=
164- Self . currentInstallationContainer . installationId! {
183+ if Self . currentContainer . currentInstallation? . installationId !=
184+ Self . currentContainer . installationId! {
165185 //If the user made changes, set back to the original
166- Self . currentInstallationContainer . currentInstallation? . installationId =
167- Self . currentInstallationContainer . installationId!
186+ Self . currentContainer . currentInstallation? . installationId =
187+ Self . currentContainer . installationId!
168188 }
169189 //Always pull automatic info to ensure user made no changes to immutable values
170- Self . currentInstallationContainer . currentInstallation? . updateAutomaticInfo ( )
190+ Self . currentContainer . currentInstallation? . updateAutomaticInfo ( )
171191 }
172192
173193 internal static func saveCurrentContainerToKeychain( ) {
174194 #if !os(Linux) && !os(Android)
175- try ? KeychainStore . shared. set ( Self . currentInstallationContainer , for: ParseStorage . Keys. currentInstallation)
195+ try ? KeychainStore . shared. set ( Self . currentContainer , for: ParseStorage . Keys. currentInstallation)
176196 #endif
177197 }
178198
@@ -182,7 +202,7 @@ extension ParseInstallation {
182202 try ? KeychainStore . shared. delete ( valueFor: ParseStorage . Keys. currentInstallation)
183203 #endif
184204 //Prepare new installation
185- _ = BaseParseInstallation ( )
205+ BaseParseInstallation . createNewInstallationIfNeeded ( )
186206 }
187207
188208 /**
@@ -192,10 +212,10 @@ extension ParseInstallation {
192212 */
193213 public static var current : Self ? {
194214 get {
195- return Self . currentInstallationContainer . currentInstallation
215+ return Self . currentContainer . currentInstallation
196216 }
197217 set {
198- Self . currentInstallationContainer . currentInstallation = newValue
218+ Self . currentContainer . currentInstallation = newValue
199219 Self . updateInternalFieldsCorrectly ( )
200220 }
201221 }
0 commit comments