Unrelated XCUIElement warning and cast from AnyObject? to "any other type" that fails only in test target

Originator:dareglia
Number:rdar://22836823 Date Originated:24-Sep-2015 01:33 PM
Status:Open Resolved:
Product:XCode Product Version:Xcode 7 (7A220)
Classification:Serious Bug Reproducible:Always
 
Summary:
The warning "Cast from 'XCUIElement!' to unrelated type 'String' always fails" appears for lines of code where casting from "AnyObject?" to "something else" are performed. The main issue is that the casting fails (returns nil) in the Test Target but works correctly in the App Target. 

Due to this problem all the tests that are related to those lines of code fail.
 
NOTE: If I redefine the "AnyObject?" declaration with a more precise declaration like "[String:AnyObject]?" I don't encounter this bug. The attached projects are meant to show this difference. 
- XCIssue_BUG:  uses AnyObject? -> the bug is observed
- XCIssue_IT_WORKS:  uses [String:AnyObject]? -> the bug is not observed

ATTACHMENT: https://www.dropbox.com/s/3d8wms9njkelhcp/radar_22836823.zip?dl=0 

Steps to Reproduce:
The source code attached to this report contains two mini-projects to show the bug. 
- The XCIssue_BUG contains the bug that I'm reporting 
- The XCIssue_IT_WORKS shows that just changing the type from AnyObject? to [String:AnyObject]? the bug is not observed. 

1. Launch the project in XCIssue_BUG.zip archive with Xcode 7 
2. Run tests 
3. All tests fail and the warning is presented in file Client.swift at rows 74, 79 and 86

Expected Results:
The warnings should't be presented and the casts should return the information stored in the Dictionary while running the Test Target.

Actual Results:
The unrelated warnings are presented and the cast returns nil only in the Test Target. While the casts work correctly in the Application Target. 

Version:
Xcode 7.0 (7A220) 
OSX 10.10.5 
MacBook Pro (retina, 15-inch, Mid 2014) 
Processor 2,2 ghz Intel Core i7

Notes:
- I've provided two different projects to show which is the exact place where bug is observed. Please refer to XCIssue_BUG archive to observe the bug and to XCIssue_IT_WORKS archive to see where bug is not observed. 

- The code contains some uppercase comments that are addressed to the reviewer attention.

Comments

Project Attachment

ATTACHMENT: https://www.dropbox.com/s/3d8wms9njkelhcp/radar_22836823.zip?dl=0


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!