CoreAnimation uncommitted CATranaction NSComboBox

1.6k views Asked by At

I am populating an NSComboBox with some data from the function below. After it is populated and I try to scroll through the items I get the CATransaction warning. Can anyone shed some light on why this is happening and what I can do to fix it? I have figured out that it may have something to do with changing the UI of the combobox on a thread other than the main thread but after that I am stuck.

func getAllRecords()
{
    CATransaction.begin()
    let url = NSURL(string: "http://URL.php")
    let task = NSURLSession.sharedSession().dataTaskWithURL(url!)
        {
            (data, response, error) in
            var d = NSString(data: data, encoding: NSUTF8StringEncoding)
            var arr = d!.componentsSeparatedByString("<") // spliting the incoming string from "<" operator because before that operator is our required data and storing in array
            var dataWeNeed:NSString = arr[0] as! NSString // arr[0] is the data before "<" operator and arr[1] is actually no use for us
            if let data = NSJSONSerialization.JSONObjectWithData(dataWeNeed.dataUsingEncoding(NSUTF8StringEncoding)!, options: NSJSONReadingOptions.MutableContainers, error: nil) as? NSArray
                {
                    for dd in data
                        {
                            var name : String = dd["Name"]! as! String
                            var email : String = dd["Email"]! as! String
                            //println("Name: \(name)")
                            //println("Email: \(email)")
                            self.userComboBox.addItemsWithObjectValues([name])
                        }
                }
        }
    task.resume()
    CATransaction.commit()
}

Here is the warning I am getting from the debug area.

2015-06-14 13:54:04.756 Green Time Clock[2150:738395] Unexpected        outstanding background CATransaction
CoreAnimation: warning, encountered thread with uncommitted     CATransaction; created by:
0   QuartzCore                          0x00007fff9ab4d6c2     _ZN2CA11Transaction4pushEv + 312
1   QuartzCore                          0x00007fff9ab689a8   _ZN2CA11Transaction15ensure_implicitEv + 276
2   QuartzCore                          0x00007fff9ab4d842 _ZN2CA11Transaction9set_valueEj12_CAValueTypePKv + 40
3   QuartzCore                          0x00007fff9ab4f452 +[CATransaction setDisableActions:] + 38
4   AppKit                              0x00007fff921a1b8c -[NSView(NSInternal) _updateLayerGeometryFromView] + 389
5   AppKit                              0x00007fff921c7d09 -[NSView setFrameSize:] + 1129
6   AppKit                              0x00007fff921c789a -[NSControl setFrameSize:] + 77
7   AppKit                              0x00007fff922e3891 -[NSTableView setFrameSize:] + 256
8   AppKit                              0x00007fff922e35f9 -[NSTableView _tileAndRedisplayAll] + 180
9   Green Time Clock                    0x00000001000042d6 _TFFC16Green_Time_Clock14ViewController13getAllRecordsFS0_FT_T_U_FTGSQCSo6NSData_GSQCSo13NSURLResponse_GSQCSo7NSError__T_ + 2886
10  Green Time Clock                    0x0000000100004463 _TTRXFo_oGSQCSo6NSData_oGSQCSo13NSURLResponse_oGSQCSo7NSError__dT__XFo_iTGSQS__GSQS0__GSQS1____iT__ + 51
11  Green Time Clock                    0x0000000100001e31 _TPA__TTRXFo_oGSQCSo6NSData_oGSQCSo13NSURLResponse_oGSQCSo7NSError__dT__XFo_iTGSQS__GSQS0__GSQS1____iT__ + 81
12  Green Time Clock                    0x0000000100004493 _TTRXFo_iTGSQCSo6NSData_GSQCSo13NSURLResponse_GSQCSo7NSError___iT__XFo_oGSQS__oGSQS0__oGSQS1___dT__ + 35
13  Green Time Clock                    0x00000001000044fa _TTRXFo_oGSQCSo6NSData_oGSQCSo13NSURLResponse_oGSQCSo7NSError__dT__XFdCb_dGSQS__dGSQS0__dGSQS1___dT__ + 90
14  CFNetwork                           0x00007fff8c09cba2 __49-[__NSCFLocalSessionTask _task_onqueue_didFinish]_block_invoke + 157
15  Foundation                          0x00007fff9a75f7e8 __NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__ + 7
1

There are 1 answers

1
Itachi On

Not sure what root issue is, I found that warning when updating string value to a NSTextView object and resolved it with following code just now.

Just make sure the updating process is handled in main thread.

// Link: NSTextStorage limitation on size and frequency of updates

dispatch_block_t block = ^ {
    NSAttributedString *attributeString = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@\n", strLog]];

    NSTextStorage* store = [_textViewOutputLog textStorage];
    [store beginEditing];
    [store appendAttributedString:attributeString];
    [store endEditing];
    [_textViewOutputLog scrollRangeToVisible:NSMakeRange([[_textViewOutputLog string] length], 0)];
};

if ([NSThread isMainThread]) {
    block();
} else {
    dispatch_async(dispatch_get_main_queue(), block);
}