@@ -61,51 +61,47 @@ public protocol ObjCCompat_SubscriptionHandling {
6161 optional func didUnsubscribe( query: PFQuery , client: Client )
6262}
6363
64+ // HACK: Compiler bug causes enums that are declared in structs that are marked as @objc to not actually be emitted by
65+ // the compiler (lolwut?). Moving this to global scope fixes the problem, but we can't change the objc name of an enum
66+ // either, so we pollute the swift namespace here.
67+ // TODO: Fix this eventually.
68+
69+ /**
70+ A type of an update event on a specific object from the live query server.
71+ */
72+ @objc
73+ public enum PFLiveQueryEventType : Int {
74+ /// The object has been updated, and is now included in the query.
75+ case Entered
76+ /// The object has been updated, and is no longer included in the query.
77+ case Left
78+ /// The object has been created, and is a part of the query.
79+ case Created
80+ /// The object has been updated, and is still a part of the query.
81+ case Updated
82+ /// The object has been deleted, and is no longer included in the query.
83+ case Deleted
84+ }
85+
6486/**
6587 This struct wraps up all of our Objective-C compatibility layer. You should never need to touch this if you're using Swift.
6688 */
6789public struct ObjCCompat {
6890 private init ( ) { }
6991
70- /**
71- A type of an update event on a specific object from the live query server.
72- */
73- @objc
74- public enum PFLiveQueryEventType : Int {
75- /// The object has been updated, and is now included in the query.
76- case Entered
77- /// The object has been updated, and is no longer included in the query.
78- case Left
79- /// The object has been created, and is a part of the query.
80- case Created
81- /// The object has been updated, and is still a part of the query.
82- case Updated
83- /// The object has been deleted, and is no longer included in the query.
84- case Deleted
85- }
86-
8792 /**
8893 Represents an update on a specific object from the live query server.
8994 */
9095 @objc ( PFLiveQueryEvent)
9196 public class Event : NSObject {
9297 /// Type of the event.
98+ @objc
9399 public let type : PFLiveQueryEventType
100+
94101 /// Object this event is for.
102+ @objc
95103 public let object : PFObject
96104
97- init < T> ( event: ParseLiveQuery . Event < T > ) {
98- ( type, object) = {
99- switch event {
100- case . Entered( let object) : return ( . Entered, object)
101- case . Left( let object) : return ( . Left, object)
102- case . Created( let object) : return ( . Created, object)
103- case . Updated( let object) : return ( . Updated, object)
104- case . Deleted( let object) : return ( . Deleted, object)
105- }
106- } ( )
107- }
108-
109105 init ( type: PFLiveQueryEventType , object: PFObject ) {
110106 self . type = type
111107 self . object = object
@@ -329,6 +325,25 @@ extension Client {
329325 }
330326}
331327
328+ // HACK: Another compiler bug - if you have a required initializer with a generic type, the compiler simply refuses to
329+ // emit the entire class altogether. Moving this to an extension for now solves the issue.
330+
331+ extension ObjCCompat . Event {
332+ convenience init < T> ( event: ParseLiveQuery . Event < T > ) {
333+ let results : ( type: PFLiveQueryEventType , object: PFObject ) = {
334+ switch event {
335+ case . Entered( let object) : return ( . Entered, object)
336+ case . Left( let object) : return ( . Left, object)
337+ case . Created( let object) : return ( . Created, object)
338+ case . Updated( let object) : return ( . Updated, object)
339+ case . Deleted( let object) : return ( . Deleted, object)
340+ }
341+ } ( )
342+
343+ self . init ( type: results. type, object: results. object)
344+ }
345+ }
346+
332347extension PFQuery {
333348 /**
334349 Register this PFQuery for updates with Live Queries.
0 commit comments