ReactiveCocoa Issue

I am trying to use ReactiveCocoa in my project to handle a collection of UITableView.

When I load data, if there is none, I want to set the property hidden tableView.backgroundViewto false. Here is what I still have:

func loadData() {
    let dataSource = tableView.dataSource as! BlockedTableViewDataSource
    let load = dataSource.load(currentUser) # RACSignal

    load.map {
        return ($0 as! [AnyObject]).count > 0
    }.startWith(true).distinctUntilChanged().setKeyPath("hidden", onObject: tableView.backgroundView!)

    load.subscribeError({ error in
        println(error)
    }, completed: {
        self.tableView.reloadData()
        self.refreshControl?.endRefreshing()
    })
}

This, however, leads to errors saying that I need to wait for the completion of the network request. I am using Parse to retrieve data, but I think my ReactiveCocoa code is simply not configured correctly and is causing this error. If I comment on the part load.map..., the table will populate as expected.

How could this be implemented in the Jet Way?

Update # 1

Here is the loaddata source function

func load(user: User) -> RACSignal {
    return self.getBlocks(user).doNext {
        self.blocks = $0 as! [Block]
    }
}

private func getBlocks(fromUser: User) -> RACSignal {
    let query = Block.query()!
    query.whereKey("fromUser", equalTo: fromUser)
    query.includeKey("toUser")

    return query.rac_findObjects()
}

Update # 2

2015-04-28 08:20:02.612 ohio[90547:2154845] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'This query has an outstanding network connection. You have to wait until it done.'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010b840c65 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x000000010bc5dbb7 objc_exception_throw + 45
    2   CoreFoundation                      0x000000010b840b9d +[NSException raise:format:] + 205
    3   ohio                                0x0000000107facb1b -[PFQuery checkIfCommandIsRunning] + 77
    4   ohio                                0x0000000107facb71 -[PFQuery markAsRunning:] + 46
    5   ohio                                0x0000000107fad105 -[PFQuery _findObjectsAsync:after:] + 234
    6   ohio                                0x0000000107faf0a0 -[PFQuery findObjectsInBackgroundWithBlock:] + 288
    7   ohio                                0x0000000107d9532d _TFFE4ohioCSo7PFQuery15rac_findObjectsFS0_FT_CSo9RACSignalU_FGSQPSo13RACSubscriber__GSQCSo13RACDisposable_ + 205
    8   ohio                                0x0000000107d6639e _TTRXFo_oGSQPSo13RACSubscriber___oGSQCSo13RACDisposable__XFo_iGSQPS____iGSQS0___ + 30
    9   ohio                                0x0000000107d944c1 _TPA__TTRXFo_oGSQPSo13RACSubscriber___oGSQCSo13RACDisposable__XFo_iGSQPS____iGSQS0___ + 81
    10  ohio                                0x0000000107d663d4 _TTRXFo_iGSQPSo13RACSubscriber___iGSQCSo13RACDisposable__XFo_oGSQPS____oGSQS0___ + 36
    11  ohio                                0x0000000107d66418 _TTRXFo_oGSQPSo13RACSubscriber___oGSQCSo13RACDisposable__XFdCb_dGSQPS____aGSQS0___ + 56
    12  ohio                                0x0000000107eeacca __30-[RACDynamicSignal subscribe:]_block_invoke + 74
    13  ohio                                0x0000000107f35b8e -[RACSubscriptionScheduler schedule:] + 478
    14  ohio                                0x0000000107eeab9d -[RACDynamicSignal subscribe:] + 765
    15  ohio                                0x0000000107f28f1d -[RACSignal(Subscription) subscribeNext:error:completed:] + 1133
    16  ohio                                0x0000000107f004cc __32-[RACSignal(Operations) doNext:]_block_invoke + 396
    17  ohio                                0x0000000107eeacca __30-[RACDynamicSignal subscribe:]_block_invoke + 74
    18  ohio                                0x0000000107f35b8e -[RACSubscriptionScheduler schedule:] + 478
    19  ohio                                0x0000000107eeab9d -[RACDynamicSignal subscribe:] + 765
    20  ohio                                0x0000000107f2999e -[RACSignal(Subscription) subscribeError:completed:] + 766
    21  ohio                                0x0000000107dc5fdb _TFC4ohio26BlockedTableViewController8loadDatafS0_FCS_4UserT_ + 3083
    22  ohio                                0x0000000107dc6775 _TFC4ohio26BlockedTableViewController11viewDidLoadfS0_FT_T_ + 501
    23  ohio                                0x0000000107dc7702 _TToFC4ohio26BlockedTableViewController11viewDidLoadfS0_FT_T_ + 34
    24  UIKit                               0x000000010a142210 -[UIViewController loadViewIfRequired] + 738
    25  UIKit                               0x000000010a14240e -[UIViewController view] + 27
    26  UIKit                               0x000000010a167297 -[UINavigationController _startCustomTransition:] + 633
    27  UIKit                               0x000000010a1733bf -[UINavigationController _startDeferredTransitionIfNeeded:] + 386
    28  UIKit                               0x000000010a173f0e -[UINavigationController __viewWillLayoutSubviews] + 43
    29  UIKit                               0x000000010a2be715 -[UILayoutContainerView layoutSubviews] + 202
    30  UIKit                               0x000000011915093e -[UILayoutContainerViewAccessibility layoutSubviews] + 43
    31  UIKit                               0x000000010a091a2b -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 536
    32  QuartzCore                          0x0000000109d12ec2 -[CALayer layoutSublayers] + 146
    33  QuartzCore                          0x0000000109d076d6 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
    34  QuartzCore                          0x0000000109d07546 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
    35  QuartzCore                          0x0000000109c73886 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 242
    36  QuartzCore                          0x0000000109c74a3a _ZN2CA11Transaction6commitEv + 462
    37  QuartzCore                          0x0000000109c750eb _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 89
    38  CoreFoundation                      0x000000010b773ca7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
    39  CoreFoundation                      0x000000010b773c00 __CFRunLoopDoObservers + 368
    40  CoreFoundation                      0x000000010b769a33 __CFRunLoopRun + 1123
    41  CoreFoundation                      0x000000010b769366 CFRunLoopRunSpecific + 470
    42  GraphicsServices                    0x000000010cfc8a3e GSEventRunModal + 161
    43  UIKit                               0x000000010a011900 UIApplicationMain + 1282
    44  ohio                                0x0000000107d86df7 main + 135
    45  libdyld.dylib                       0x000000010c3c1145 start + 1
    46  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
+4
1

rac_findObjects() . , , - , ( ) . , PFQuery , .

load, setKeyPath . , , , .

GitHub, RACMulticastConnection, , ( ) , . :

let load = dataSource.load(currentUser).publish().autoconnect()
+1

All Articles