Strange behaviour with Xcode 4.3 - xcode

I have a lot of classes on my project, my Source Editor displays the class names, iVar names ect correctly in all the class except one. In one of my classes all the input(mean, code) is displayed in white font and none of the class methods work. For example i have declared properties for NSMutableArray but i can't get the class method objectAtIndex:.. What can i do can anyone help please?

Go to Menue->Product-Clean and clean your project.
Delete your app in simulator, restart xcode,
restart operating system, check your project so you have no errors in your class,
and finally compile it again.
Sometimes i am getting this same behaviour, too. Dont know why.
Is the whole class without syntax highlighting? If no, check at the point where the syntax highlight ends, there could be a syntax error or something different.
Hope it helps.

Restart your Xcode.It may be helpful

There must be an error somewhere in your code. Unfortunately, sometimes xcode cannot show errors properly. As for me, somtimes I can't see errors at all.
If restart don't work for you. Try repairing permissions in Disk Utility (that worked for me).

Related

luma.gl Reference error: window is not defined

One of the tasks for my current project is trying to find the source of the following console error:
I have looked through all the references to the window object as well as the luma.gl library but can't seem to find where the issue is originating. It doesn't seem to break anything but is more of an annoyance when debugging as it pops up over 20 times in a row whenever the page is refreshed. Here are the versions of Deck.gl and Luma.gl from package.json:
Just want to know if anyone has encountered this before and how you might have fixed it. Thank you.
I have eliminated all calls to the window object within the project to no avail and have looked through polyfill-context.js inside the #luma.gl library with no luck either.

Class PLBuildVersion is implemented in both frameworks

iOS 10 / Xcode 8 GM build getting the below, never had it before on Xcode 7. Any ideas?
objc[25161]: Class PLBuildVersion is implemented in both
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/AssetsLibraryServices.framework/AssetsLibraryServices
(0x12049a910) and
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/PhotoLibraryServices.framework/PhotoLibraryServices
(0x1202c4210). One of the two will be used. Which one is undefined.
(NOTE: Only seems to happen in simulator, does not appear on real device).
Main Idea
Main idea is simple:
If your app (or dependencies, such as Pods) uses framework, that uses explicit (or implicit) PhotoLibraryServices.framework or AssetsLibraryServices.framework as dependency, Xcode warns you (even if you are using only one of them). It might be Photos/PhotosUI.framework or AssetsLibrary.framework, or another (I don't have full list of dependencies, but it is possible).
What is the problem?
Class with name PLBuildVersion is defined in both PhotoLibraryServices.framework and AssetsLibraryServices.framework. Class name is unique in Objective-C (you can't define 2 classes with same name), so it is undefined which one will be used in runtime.
However, I think that it will not be a problem, because both classes have same methods and fields (checked this with disassembler) and I guess that both were compiled from the same source.
Radar is already sent.
As per answer from Apple employee on Apple's Developer Forum:
You don't control either of the class sources listed, so there isn't anything you can or should do – aside from Reporting a Bug.
I was unable to find a way to get rid of the warning, but if you want to prevent the app from crashing, you need to provide a description for why you are accessing the camera, photo library, etc. This is new in iOS10.
Input the following into your Info.plist file.
Photo
Key: Privacy - Photo Library Usage Description
Value: $(PRODUCT_NAME) photo use
Camera
Key: Privacy - Camera Usage Description
Value: $(PRODUCT_NAME) camera use
More info can be found here: https://iosdevcenters.blogspot.com/2016/09/infoplist-privacy-settings-in-ios-10.html
I find you can get this error merely by using a UIWebView. My solution was to replace my use of UIWebView with WKWebView.
I had this after adding Answers on Fabric to my project.
Deleting derived data did the trick for me. (shift alt command k in XCode)
Edit a year later:
After deleting derived data, always exit XCode and start it again.
In unrelated cases I have the impression that deleting derived data does not clear XCode’s in memory caches of the derived data.
Resetting the iOS simulator fixed this for me. Simulator -> Reset Content And Settings.
In my case this warning started to appear after opening a second xcode project and running the second app on the simulator. After changing back to the first app, the warning started to appear. I just quit the Simulator and Xcode and reopened my project. The warning disappeared after that. If that doesn't solve it, proceed with the other answers. Xcode can be really picky sometimes.

"Use of undeclared type" in Swift, even though type is internal, and exists in same module

I have a type in my module:
import Cocoa
class ColoredDotView : NSView {
...
}
It is used in a number of different classes with no issue:
class EditSubjectPopoverController : NSObject {
#IBOutlet internal var subjectColorDotView : ColoredDotView!
...
}
But for some reason, when I use it in one specific class, I have compilation errors on the type:
class EditTaskPopoverController : NSObject {
#IBOutlet internal var lowPriorityDotView : ColoredDotView! // Error here
#IBOutlet internal var medPriorityDotView : ColoredDotView! // And here...
#IBOutlet internal var highPriorityDotView : ColoredDotView! // And here...
...
}
The compilation error is:
EditTaskPopoverController.swift:15:49: Use of undeclared type
'ColoredDotView'
Which I don't understand. It's the first compilation error in the file, and the rest of the errors are all symptomatic of the first. Further, there are no other files with compilation errors. I don't understand why the type is undeclared, as the file is in the same module:
I have tried cleaning the project, cleaning the build folder, and restarting Xcode, to no avail. What potential missteps can cause an undeclared type compiler error in Swift?
For me, I encountered this error when my test target did not have some swift files that my app build target had in compile sources. It was very confusing because the 'undeclared type' was being used in so many other places with no problem, and the error seemed vague. So solution there was of course to add the file containing the 'undeclared type' to the test target.
This has already been answered by #Craig Otis, but the issue is caused when the classes in question do not belong to the same targets, usually the test target is missing. Just make sure the following check boxes are ticked.
Edit
To see the target membership. Select your file then open the file inspector (⌥ + ⌘ + 1) [option] + [command] + 1
Phew, finally diagnosed this. Somehow, the offending Swift file EditTaskPopoverController.swift was in two different build phases.
It was in Compile Sources properly, with all the other Swift files, but it was also, for some very strange reason, in the Copy Bundle Resources phase as well, along with all my XIB and image resources.
I have no idea how it got there, but removing it from the extra build phase resolved the issue.
In XCode menu Product->Clean and then Product->Build worked for me. I encountered this issue when added new ViewController to my project in new Group/Folder.
I had the exact same problem. Some of the files in my framework were not reachable from other classes within the same module.
For some reason the files that had been added to the framework in Xcode was not part of the Compile Sources. If your Swift file is not part of the compile sources you need to add them by tapping the + and selecting them in the popup.
Also make sure the file is part of the framework target. (The little box in the screenshot below should be checked)
The cause for me was a function name that began with same characters as a type:
#IBOutlet weak var tableView: CustomTableView!
and in the implementation I had a function beginning with CustomTableView
func CustomTableView(tableView: CustomTableView, dataForRow row: Int) -> NSData {...}
The fix was to change the function signature so that it didn't begin with the same characters as the type (CustomTableView), e.g.:
func dataForRow(row: Int, tableView: CustomTableView) -> NSData {...}
This was a very misleading error message for the actual cause in my case.
In case anyone encounters a similar problem but the Compile Sources fix does not solve the problem, restarting Xcode may (it worked for me). My version of Xcode is Version 6.1 (6A1052d).
Sometimes errors can be very silly
Before checking all the solutions up here , make sure you have
imported all the basic stuff
import Foundation
import UIKit
It is quite a possibility that when you import some files from outside
to your project, which may miss this basic things as I experienced
once .
In my app I have app delegate and other classes that need to be accessed by the tests as public. As outlined here, I then import my my app into my tests.
When I recently created two new classes ,their test targets were both the main and testing parts. Removing them from their membership from the tests solved the issue.
In my case, the TestTarget's compile sources were having files from the Main Target.
Ref:
Why this happens ?
This happens since we check the TestTarget association while creating
the file
Or manually checking this option from the inspector.
Ref:
How did i resolve ?
I removed the main target's files from compile source of Test Target
I tried many of the solutions offered here, but eventually deleted the file and created it again, and Xcode was mollified :/
This can also happen if you by accident capitalize the parameter name, and call it the same as the object.
class func didRecieveData(BlockItems: [BlockItems])
This might help someone.
I've created new test project with Core Data called "CoreData". Shortly I've got "Use of undeclared type" for NSManagedObjectContext and other Core Data classes. After several attempts of importing, adding to Build phases, etc. I've deleted project and started new one called "TestingCoreData" and it all worked well.
Don't name (test) Projects like name of the Classes
This can also happen if you have a function with the same name as an object type in your signature. For example:
class func Player(playerObj: Player)
will cause the compiler to get confused (and rightfully so) since the compiler will first look locally within the file before looking at other files. So it looks at "Player" in the signature and thinks, that's not an object in this scope, but a function, so something is wrong.
Perhaps this is a good reason why I shouldn't capitalize class functions. :)
I got this error message in Xcode 8 while refactoring code in to a framework, it comes out that I forgot to declare the class in the framework as public
Maybe you have added class with some "FirstNameClass" and after that manually rename to "ColoredDotView". Try to copy content of "ColoredDotView" class to clipboard, remove "ColoredDotView" from project and add agin.
This id fix similar problem from me.
In my case was a mistake made by me. I added a new file as "OS X>Source>Cocoa Class", instead of "iOS>Source>Cocoa Touch Class".
In my case, this was caused by a subclass name being used in the very next line as a variable name with a different type:
var binGlow: pipGlow = pipGlow(style: "Bin")
var pipGlow: PipGlowSprite = PipGlowSprite()
Notice that in line 1, pipGlow is the name of the subclass (of SKShapeNode), but in line two, I was using pipGlow as a variable name. This was not only bad coding style, but apparently an outright no-no as well! Once I change the second line to:
var binGlow: pipGlow = pipGlow(style: "Bin")
var pipGlowSprite: PipGlowSprite = PipGlowSprite()
I no longer received the error. I hope this helps someone!
When testing Swift code that belongs to the application, first make sure the test target is building the application as a dependency. Then, in your test, import the application as a module. For example:
#testable import MyApplication
This will make the Swift objects that are part of the application available to the test.
In my case, that was caused by swift files's Text Encoding.
One file showed 'No Explicit Encoding', and after convert that to 'UTF-8', problem solved.
And the reason why file's text encoding is not explicit is that I copied all code from other swift file.
No Explicit Encoding Screenshot
UTF-8 Screenshot
Cleaning the project solved my problem.
Steps:
Product -> Clean(or Shift + Cmd + K)
In my case I wanted to add a method with a custom swift object as a type parameter, and the name I gave to the variable in the parameter was exactly the same as the custom object class name
The problems was something like this:
func moveBlob(**blob** : blob){
...code
}
The part in bold characters was causing the error of undeclared type
as others mentioned well and in this thread
use of unneeded swift files in "copy bundle resources"
Like others, it was some unrelated code that was causing the #testable to malfunction.
In my test target there was an Objective-C header file that had
#import ModuleUnderTest;
I removed this line (because the import was actually unnecessary) and miraculously #testable starting working again.
I was only able to track this down but removing everything from my project and adding it back in bit by bit until it failed. Eventually I found the problem line of code.
if you are accessing it from different module or Target then you just need it to public it
In case someone makes the same silly mistake I did...
I was getting this error because in renaming my source file, I accidentally removed the. from the filename and so the compiler treated the file as a plain text file and not as source to compile.
so I meant to rename the file to
MyProtocol.swift
but accidently named it
MyProtocolswift
It's a simple mistake, but it was not readily obvious that this is what was going on.
Not adding the correct import delcaration can also be an obvious miss. For me, I had simply omitted to import PriorityUIKit.
My situation is that I drag a new file XXView.swift into the project. And declare a View type to be XXView then the error "use of undeclared type....".
I just try to add my XXView.swift to the test target which it solved the error.
But I didn't want my UI Class involved in the test target.
Finally, I found my ViewController already in the test target which should not happen. ( I think because I create the VC by an xctemplate therefore, it automatically be included in the test target)
I remove the view controller from the test target, and then my XXView is now no need to add to the test target.
Conclusion: make sure all your related files should also uncheck the test target.
After spending an hour on this error I found that the module file is duplicated. delete the extra file, and shift+cmd+k to clean and the error is gone.
In my case, the issue was with a new class not being recognized. I solved the issue by deleting the class and re-adding it but this time checking the Watch App Extension option when creating the new class.
Please note that I do have a Watch App Extension in my Application.

Webcore NSBeep()! when copy from uiwebview

I'm developing an epub reader with monocle (https://github.com/joseph/Monocle) which is launched in a uiwebview. My problem is that when I try to copy some text, like what we would do in any other uiwebview, it doesn't seems to do anything... well, I get Webcore NSBeep()! in output view.
any idea or approach?
Webcore NSBeep()! is a error notification, because when you try to copy text from UIWebview the text is not copied into your clipboard and the error notified using a beep (IMHO which is not wise way of notifying errorr by any platform, it would have been any visual indication)
And please note : NSBeep() is part of the ApplicationKit framework which doesn't exist on the iPhone.
I had the same strange issue, irritatingly enough everything worked for quite some time. Then with some changes, this error happened. Reverting the code did not help. After a whole day searching and thinking, I still don't know what caused this, but I know that it wasn't my code!
My theory is that either my git repository was somehow messed up or it was because I edited my project with a beta version of the IDE+SDK. Either way, you should probably look into recreating your webview in InterfaceBuilder. Or recreate your project (or at least partially to confirm that it might be a bug in the project itself). I think/hope that the error will go away then.

Cocoa, error when restoring document

When trying to restore a version of a document in my document based application, I get an error:
kCGErrorFailure: CGSDisplayID: App trying to enumerate [0 to CGSGetNumberOfDisplays()] instead of using CGSGetDisplayList(). Compensating...
kCGErrorFailure: Set a breakpoint # CGErrorBreakpoint() to catch errors as they are logged.
and the document remains unchanged. Also, when this happens, I get a message as soon as I start editing the document telling me:
The document [...] could not be autosaved. The file has been changed by another application.
I think these two problems may be related.
I don't know what to do or "check" because versions just works without any implementation needed; I'm actually confused, because Apple says that I just need to enable autosave in order to restore/revert using versions. Does anyone know what can be causing that error?
Thanks.
I've ran into all of your issues, causing me much pain.
I've gotten that error message regarding kCGErrorFailure... before as well when browsing versions. I've just ignored it mostly as it seems harmless to me. TextEdit seems to spit out this message as well. (Looks like an Apple bug)
For the "document remains unchanged", check here: Restoring from versions browser on OSX lion not working... ideas? (in short, your code for updating your document's UI is probably not being called for the document that is being reverted) (Looks undocumented to me)
For autosaving issues, check here: http://www.cocoabuilder.com/archive/cocoa/306217-how-to-implement-autosaving-browsing-versions-reverting-to-last-saved-in-lion.html (in short, use the file wrapper methods instead for reading and writing). (Looks like an Apple bug)
As well as returning YES to autosavesInPlace: your document needs to at least call updateChangeCount: passing NSChangeDone whenever it changes, so that it "knows" that there are changes to be autosaved.

Resources