Sometimes I have an issue with Xcode 6.0.1 where the error "SourceKitService Crashed Crashlog generated in ~/Library/Logs/DiagnosticReports" is popping up and all syntax highlighting is gone in Swift. How can I fix this?
Have this problem with Xcode 6.1 (release, not GM).
There a few "magic" solutions that works temporarily, but require a restart. There is quick fix that seems to hold (and does not require a complete restart).
Delete the content of: DerivedData/ModuleCache
(Full path: ~/Library/Developer/Xcode/DerivedData/ModuleCache)
This is a bug in Xcode and you cannot do much about it.
Update to Xcode 6.2 Beta 1 or higher if you want as the situation improved there. Still happening occasionally though.
Try emptying the ~/Library/Developer/Xcode/DerivedData folder. That should fix the problem.
My project started crashing SKS several times per minute recently, and none of the voodoo was working anymore.
My workaround—which is not going to last into later, more-complex phases—is to create a dummy project target within my current project (and select it as active). I add the file I'm working on to the dummy target, REMOVING the file from its proper targets temporarily.
Entails a lot of fiddling with target membership, but I am NOT nostalgic for the days of writing tons of code with a text editor.
I have faced such an issue. Source kit service was using 10 gb of usage. Swift process in activity monitor reaches over 6 GB usage. I was using following code:
var details : [String : Any] = ["1":1, "2":2, "3":3, "4":4, "5":5, "6":6, "7":7, "8":8, "9":9, "10":10, "11":11, "12":12, "13":13, "14":14, "15":15, "16":16]
I have changed code to following to solve this issue:
var details : [String : Any] = [:]
details["1"] = 1
details["2"] = 2
details["3"] = 3
details["4"] = 4
details["5"] = 5
details["6"] = 6
details["7"] = 7
details["8"] = 8
details["9"] = 9
details["10"] = 10
details["11"] = 11
details["12"] = 12
details["13"] = 13
details["14"] = 14
details["15"] = 15
details["16"] = 16
Related
My project consists of ~350 Swift files and ~40 cocoa pod dependencies.
As soon as the entire project was migrated to Swift 3, build times have been INCREDIBLY slow and took a little over 3 minutes to completely compile.
I've noticed that if I rebuild after not changing any files, it builds within a reasonable amount of time. However, if I add a new function, it takes the 3+ minutes.
Cocoapods does not seem to be causing the problem as it delays on Compiling Swift source files state.
I followed this to investigate:
Added the -Xfrontend -debug-time-function-bodies flag to my Other Swift Flags in my target's build settings
Build the project
Copied this into terminal and ran pbpaste | egrep '\.[0-9]ms' | sort -t "." -k 1 -n | tail -100
However, I didn't see anything of concern. The file that took the longest to compile was only 250ms. The next closest was 100ms, even if all 350 files took 250ms to compile, that would only be a total of 73 seconds which is way off from the 3+ minute builds I am seeing.
What could be causing these long compile times?
It was never as slow before updating to Xcode 8 and Swift 3.
Update 1:
I created a new project without running the Swift 3 conversion, imported my Swift 3 files, but the build time remains the same.
Update 2:
I've tried SWIFT_WHOLE_MODULE_OPTIMIZATION = YES, but as soon as you make changes to more than 1 file, the incremental build fails and it triggers a re-build which lasts for more than 4-5 minutes.
Update 3:
I've now re-written my entire code base from Swift 3 to Swift 2.3. It didn't make any difference, the problem lies with the Xcode 8 compiler.
Update 4:
I can confirm that unchecking these two
will alleviate the pain for a while, the Xcode 8 bug does seem to be tied to how it checks dependencies between files.
Update 5:
I've converted my code base to Swift 3 from Swift 2.3 since Xcode 8.2 beta requires it, the beta should include a fix for "Xcode will not rebuild an entire target when only small changes have occurred. (28892475)". Sad to say, they haven't fixed the bug and my compile times are exactly the same with Xcode 8.2 Beta.
Original post:
I don't have enough reputation to comment, but I still wanted to share some resources. I've been stuck in this misery for days, upgrading to Swift 3 has been a complete disaster.
I'm using this to track slow files, even though just like you, that's not my problem. Something else in xcode is taking literally 4 minutes to complete:
https://github.com/irskep/swift_compile_times_parser
https://github.com/RobertGummesson/BuildTimeAnalyzer-for-Xcode
I've also made sure I don't have any lazy vars or closures that swift doesn't like. Don't use the + operator when concatenating strings, etc.
see this.
I'll update this answer if I find anything, it's just about impossible to be productive with Swift 3 ATM.
I'm using Xcode 8.1 My issue was with Dictionary which uses Nil-Coalescing Operator
this is my code when it takes 10 minutes to build:
let params: [String:String] = [
"email": email ?? self.email,
"clave": password,
"tipo_documento": documentType?.rawValue ?? self.typeDocument.rawValue,
"documento": number ?? self.documentNumber,
"nombre": name ?? self.name,
"apellidos": lastName ?? self.lastName,
"fecha_nacimiento": birth?.parse() ?? self.birthDate.parse(),
"genero": genre?.rawValue ?? self.genre.rawValue,
"telefono_movil": cel ?? self.cel,
"direccion": address ?? self.address
]
I don't know why but it advertise me that the Dictionary take a long time to compile.
Then I change it to:
var params: [String:String] = [:]
params["email"] = email ?? self.email
params["clave"] = password
params["tipo_documento"] = documentType?.rawValue ?? self.typeDocument.rawValue
params["documento"] = number ?? self.documentNumber
params["nombre"] = name ?? self.name
params["apellidos"] = lastName ?? self.lastName
params["fecha_nacimiento"] = birth?.parse() ?? self.birthDate.parse()
params["genero"] = genre?.rawValue ?? self.genre.rawValue
params["telefono_movil"] = cel ?? self.cel
params["direccion"] = address ?? self.address
Hope it could help some of you.
Also string concatenation seems to be incredible slow in Swift3/XCode8:
item.text = item.text + " " + pickerText + " " + (attribute?.Prefix ?? "") + inputText + (attribute?.Suffix ?? "")
~ took 8-10 seconds to compile
item.text = "\(item.text) \(pickerText) \(attribute?.Prefix ?? "")\(inputText)\(attribute?.Suffix ?? "")"
~ took 1,6 seconds to compile
item.text = [item.text, " ", pickerText, " ", (attribute?.Prefix ?? ""), inputText, (attribute?.Suffix ?? "")].joined();
~ took 0,001 second to compile
SWIFT_WHOLE_MODULE_OPTIMIZATION = YES
Xcode version: 8.1 GM
To add choose your target, then go to Editor > Add Build Setting > Add User-Defined Setting, and add the above.
My clean build time dropped from 35 mins (Ahem, excuse me) to 8 mins with a project file count of 800.
Note: Tried this on Xcode 8.0 first, but didn't work.
I found a couple of coding styles that take a lot of time compiling in Swift (2.3, not tested on 3):
a += b
Should be
a = a + b
Also adding array together:
var a = [1,3,4]
var b = [5,6,7,8]
var c = [8,4,3,5]
var d = a + b + c
Should be
var a = [1,3,4]
var b = [5,6,7,8]
var c = [8,4,3,5]
var d : [Int] = []
d.appendContentsOf(a)
d.appendContentsOf(b)
d.appendContentsOf(c)
The last optimization took the compilation time for 1 method from 9800ms to 5.5ms...
I migrated a Swift 2x project of 17 files to Swift 3 and had 28 warnings and 55 errors across all files. Compile time was 4-5 minutes.
Disabling
Find Implicit Dependancies
in scheme and
SWIFT_WHOLE_MODULE_OPTIMIZATION = YES
made only minor improvements.
As I eventually cleared the warnings and errors in each file, the compile time reduced and is now in the seconds. The IDE is back behaving as it should - detecting errors in near real time and compiling quickly.
Firstly, it looks like the compiler is recompiling (or at least cross checking) every file with any error or warning - even if you haven't edited that file since the last compile.
Secondly, if there are too many dependant errors/warnings across files, the compiler bottlenecks and slows right down.
Whenever you face slow compilation issue, closly looks the the third party SDKs you included in your app and also try to find your coding techniques.
I face this issue twice in my app and I felt like harrassed by Swift 3 😡. Both the times reasons were different.
First time I found that I added a library in my app named AASignatureView. Since this lib was added, my compilation time increased like hell. It started taking near 12-15 Mins in running the app on simulator. The issue was resolved after I removed this lib from my code and added VMSignatureView and my compilation time went into normal state.
Second time I faced this issue after making a code of appending several Strings. Both of these below methods turned app's compilation time to hell
a = a + b
and
a += b
Then I changed my code to below way and the problem was solved.
a = "a\(strSometihng),\(strAnother)"
Concatenating several Strings also can cause increasing compiling times, for example in my case, my compilation times where very high because of this line:
let fecha = post.dia + " " + post.num_dia + " " + post.mes + " - " + post.hora
When i changed the code to this, it satart compiling in seconds:
var fecha = post.dia!
fecha = fecha + " "
fecha = fecha + post.num_dia!
fecha = fecha + " "
fecha = fecha + post.mes!
fecha = fecha + " - "
fecha = fecha + post.hora!
When using the Xcode 8+ and creating a new blank project, the following logs appear when running the application:
2016-06-13 16:33:34.406093 TestiOS10[8209:100611] bundleid: com.appc.TestiOS10, enable_level: 0, persist_level: 0, propagate_with_activity: 0
2016-06-13 16:33:34.406323 TestiOS10[8209:100607] Created DB, header sequence number = 248
2016-06-13 16:33:34.409564 TestiOS10[8209:100611] subsystem: com.apple.UIKit, category: HIDEvents, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 0, privacy_setting: 0
2016-06-13 16:33:34.504117 TestiOS10[8209:100607] Created DB, header sequence number = 248
2016-06-13 16:33:34.548023 TestiOS10[8209:100607] subsystem: com.apple.BaseBoard, category: MachPort, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 0, privacy_setting: 0
2016-06-13 16:33:34.568458 TestiOS10[8209:100608] subsystem: com.apple.FrontBoard, category: Common, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 0, privacy_setting: 0
Maybe someone already found a configuration for this to handle?
Try this:
1 - From Xcode menu open: Product > Scheme > Edit Scheme
2 - On your Environment Variables set OS_ACTIVITY_MODE = disable
Building on the original tweet from #rustyshelf, and illustrated answer from iDevzilla, here's a solution that silences the noise from the simulator without disabling NSLog output from the device.
Under Product > Scheme > Edit Scheme... > Run (Debug), set the OS_ACTIVITY_MODE environment variable to ${DEBUG_ACTIVITY_MODE} so it looks like this:
Go to your project build settings, and click + to add a User-Defined Setting named DEBUG_ACTIVITY_MODE. Expand this setting and Click the + next to Debug to add a platform-specific value. Select the dropdown and change it to "Any iOS Simulator". Then set its value to "disable" so it looks like this:
OS_ACTIVITY_MODE didn't work for me (it may have been because I typo'd disable as disabled, but isn't that more natural?!?), or at least didn't prevent a great deal of messages. So here's the real deal with the environment variables.
https://llvm.org/svn/llvm-project/lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
lldb_private::Error
PlatformDarwin::LaunchProcess(lldb_private::ProcessLaunchInfo &launch_info) {
// Starting in Fall 2016 OSes, NSLog messages only get mirrored to stderr
// if the OS_ACTIVITY_DT_MODE environment variable is set. (It doesn't
// require any specific value; rather, it just needs to exist).
// We will set it here as long as the IDE_DISABLED_OS_ACTIVITY_DT_MODE flag
// is not set. Xcode makes use of IDE_DISABLED_OS_ACTIVITY_DT_MODE to tell
// LLDB *not* to muck with the OS_ACTIVITY_DT_MODE flag when they
// specifically want it unset.
const char *disable_env_var = "IDE_DISABLED_OS_ACTIVITY_DT_MODE";
auto &env_vars = launch_info.GetEnvironmentEntries();
if (!env_vars.ContainsEnvironmentVariable(disable_env_var)) {
// We want to make sure that OS_ACTIVITY_DT_MODE is set so that
// we get os_log and NSLog messages mirrored to the target process
// stderr.
if (!env_vars.ContainsEnvironmentVariable("OS_ACTIVITY_DT_MODE"))
env_vars.AppendArgument(llvm::StringRef("OS_ACTIVITY_DT_MODE=enable"));
}
// Let our parent class do the real launching.
return PlatformPOSIX::LaunchProcess(launch_info);
}
So setting OS_ACTIVITY_DT_MODE to "NO" in the environment variables (GUI method explained in Schemes screenshot in main answer) makes it work for me.
As far as NSLog being the dumping ground for system messages, errors, and your own debugging: a real logging approach is probably called for anyway, e.g. https://github.com/fpillet/NSLogger .
OR
Drink the new Kool-Aid: http://asciiwwdc.com/2016/sessions/721 https://developer.apple.com/videos/play/wwdc2016/721/
It's not surprising that there are some hitches after overhauling the entire logging API.
ADDENDUM
Anyway, NSLog is just a shim:
https://developer.apple.com/library/content/releasenotes/Miscellaneous/RN-Foundation-OSX10.12/
NSLog / CFLog
NSLog is now just a shim to os_log in most circumstances.
Only makes sense now to quote the source for the other env variable. Quite a disparate place, this time from Apple internals. Not sure why they are overlapping. [Incorrect comment about NSLog removed]
[Edited 22 Sep]: I wonder what "release" and "stream" do differently than "debug". Not enough source.
https://github.com/macosforge/libdispatch/blob/8e63547ea4e5abbfe55c0c3064181c4950a791d3/src/voucher.c
e = getenv("OS_ACTIVITY_MODE");
if (e) {
if (strcmp(e, "release") == 0) {
mode = voucher_activity_mode_release;
} else if (strcmp(e, "debug") == 0) {
mode = voucher_activity_mode_debug;
} else if (strcmp(e, "stream") == 0) {
mode = voucher_activity_mode_stream;
} else if (strcmp(e, "disable") == 0) {
mode = voucher_activity_mode_disable;
}
}
A tweet had the answer for me - https://twitter.com/rustyshelf/status/775505191160328194
To stop the Xcode 8 iOS Simulator from logging like crazy, set an environment variable OS_ACTIVITY_MODE = disable in your debug scheme.
It worked.
Please find the below steps.
Select Product => Scheme => Edit Scheme or use shortcut : CMD + <
Select the Run option from left side.
On Environment Variables section, add the variable OS_ACTIVITY_MODE = disable
For more information please find the below GIF representation.
This is still not fixed in Xcode Version 8.0 beta 2 (8S162m) for me and extra logs are also appearing in the Xcode console
** EDIT 8/1/16: This has been acknowledged in the release notes for Xcode 8 Beta 4 (8S188o) as an issues still persisting.
Known Issues in Xcode 8 beta 4 – IDE
Debugging
• Xcode Debug Console shows extra logging from system frameworks when
debugging applications in the Simulator. (27331147, 26652255)
Presumably this will be resolved by the GM release. Until then patience and although not ideal but a workaround I'm using is below...
Similar to the previous answer I am having to:
prefix my print logs with some kind of special character (eg * or ^ or ! etc etc)
Then use the search box on the bottom right of the console pane to filter my console logs by inputing my chosen special character to get the console to display my print logs as intended
My solution is to use the debugger command and/or Log Message in breakpoints.
And change the output of console from All Output to Debugger Output like
Alright. There seems to be a lot of commotion about this one, so I'll give y'all a way to persist it without using that scheme trick. I'll address the iOS Simulator specifically, but this also might need to be applied for the TV Sim as well which is located in a different dir.
The problem that is causing all of this stuff are plists located within the Xcode directory. There is a process that gets launched called configd_sim when the Sim starts that reads the plists in and prints debugging information if the plists specify they should be logged.
The plists are located here:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/Preferences/Logging/Subsystems
If you are playing around with a beta, take note that the dir will be different.
You will see numerous plists in this directory. Now, build and run your application and observe the logs. You are looking for the content immediately followed by the subsystem: part. It is the name immediately following this that represents the corresponding problematic plist.
From there, either modify the plist to knock out the debugging [Level] key/value which is a dictionary containing the "Enable" => "Default" key/value... or just simply delete the plist. Note, that you will need to be root to do either of these since they're located in the Xcode application.
the plutil -p command might be of use to you as well. i.e.
plutil -p /Applications/Xcode.app/Contents/Developer/Platforms/AppleTVSimulator.platform/Developer/SDKs/AppleTVSimulator.sdk/System/Library/Preferences/Logging/Subsystems/com.apple.BackBoardServices.fence.plist
This gave me one of the problematic plists which contained:
{ "DEFAULT-OPTIONS" => { "Level" => { "Enable" => "Default" }}}
Good luck :]
This is related to a known issue with logging found in the Xcode 8 Beta Release Notes (also asked an engineer at WWDC).
When debugging WatchOS applications in the Watch simulator, the OS may produce an excessive
amount of unhelpful logging. (26652255)
There is currently no workaround available, you must wait for a new version of Xcode.
EDIT 7/5/16: This is supposedly fixed as of Xcode 8 Beta 2:
Resolved in Xcode 8 beta 2 – IDE
Debugging
When debugging an app on the Simulator, logs are visible. (26457535)
Xcode 8 Beta 2 Release Notes
This is no longer an issue in xcode 8.1 (tested Version 8.1 beta (8T46g)). You can remove the OS_ACTIVITY_MODE environment variable from your scheme.
https://developer.apple.com/go/?id=xcode-8.1-beta-rn
Debugging
• Xcode Debug Console no longer shows extra logging from system
frameworks when debugging applications in the Simulator. (26652255,
27331147)
In Xcode 10 the OS_ACTIVITY_MODE variable with disable (or default) value also turns off the NSLog no matter what.
So if you want to get rid of the console noise but not of your own logs, you could try the good old printf("") instead of the NSLog since it is not affected by the OS_ACTIVITY_MODE = disable.
But better check out the new os_log API here.
Please note that for iOS 14 Simulator, the OS_ACTIVITY_MODE=disable will not show any logs using the new Swift Logger. You will have to remove or enable it.
I read all solutions, nothing worked so far, I am using XCODE 12.5 at the time of writing this response, it's the most annoying thing to see in a debugger with such a heap/flood of unwanted messages.
The solution I did was a lot simpler than most complex ones out there, here is what I did to solve this annoying issue:
No need to use any environment variables etc, otherwise using these as suggested by the previous posts would disable NSLOG output which isn't what you want in such case.
I made sure that all my NSLOG would contain a String that I would monitor later on, example:
Previously I used to do:
NSLog(#"Hello World");
Now, I do:
NSLog(#"[Admin]: Hello World");
Whereas "[Admin]" is the name of my program (or whatever string you like other than [Admin]"
(Optional Step) or (Easier), I wrote a function to channel (well; proxy) NSLog into another global function "Log" whereas all my logged would go to that function, and then the Log function would append the "[Admin]" string to the original logging string and also add logging-time and other items I needed etc (similar to WebLogic or any other JAVA logging), this ensure that all logs would follow one standard.
... Here is the million dollar nuclear weapon:
Now, go into your Debugger window, at the bottom you will see a "search" window whereas it says "Filter", enter your string (example; "[Admin]"), press ENTER, and job done.
This way, you will only see the lines you like to see,
Also useful when you like to filter out other components, example, for network communication I use more strings that I can filter later on.
In other words, the annoying lines of logs that has nothing to do with your app will always be there, but you choose not to see them using the above command which I hope solves the issue.
Hopefully a good day to all.
H
This solution has been working for me:
Run the app in the simulator
Open the system log (⌘ + /)
This will dump out all of the debug data and also your NSLogs.
To filter just your NSLog statements:
Prefix each with a symbol, for example: NSLog(#"^ Test Log")
Filter the results using the search box on the top right, "^" in the case above
This is what you should get:
I am just starting out in Xcode6 and using Playground to test out some Swift commands. I test a simple var a = 10, var b = 15 and var total = a+b
So far so good. But when I change value of a from 10 to 20, it doesn't seem to be updated. The calc. still reflects 10+15 vs. 20+15. This sounds silly but how come variable values aren't updated? Should I be using different variables or doing something else? I would have expected the 'right panel' to update instantly with my changes. Thanks!
So im studying, and i need to run Ozcar debugger including on Mozart, i go to Oz menu and first i pick feed buffer, after that i pick Start Debugger, the compiler show me the next message:
local A B in
A = 5
B = 6
{Browse A+B}
end
% -------------------- accepted
\localSwitches
\switch +threadedqueries -verbose -expression -runwithdebugger
{Ozcar.open}
% -------------------- accepted
And then it suppose that a auxiliary windows should appears but nothing happens!!!! I need help pls!!!
Also the Oz emulator show me this:
%********************** Error: module manager *******************
%**
%** Could not link module
%**
%** Could not load functor at URL: x-oz://system/Ozcar.ozf
%**--------------------------------------------------------------
I think that the packagge of Ozcar is missing, where i can find it or how i can solve this???
You should use Mozart 1.4.0, the latest version of the 1.x Mozart branch.
Even if this question is more than 3 years old, the development of Mozart 2 is really slow and there still are a lot of features missing.
I've got the following problem:
I've written my first Swift App (for iOS7) and it worked fine.
After changing some minor detail (adding a string somewhere) it wouldn't compile anymore, even if I changed everything back how it was before.
There is no error message or anything like it, it says that it's building the project (Compiling Swift Source Files) but it's not progressing at all, even after hours of "building".
I've tried it with Xcode 6 b1 and b2 and with both it's the same: all the other projects are compiling without any problems, this one get's stuck.
Does anyone have a clue what might be the problem and how to solve it?
Debug the code manually works for me.
Finally I find the root cause of my problem is too many string concatenation in one line.
Bug code:
var string = string1 + string2 + string3 + string4 + string5 + string6 + string7 + string8
Fixed code:
var string = string1
string += string2
string += string3
string += string4
string += string5
string += string6
string += string7
string += string8
Xcode 6 Beta sometimes does not show any error but there will be some errors in your code. Because of that it does not compile.
Try to comment different parts of code and then try to compile. You have to find out the error manually.
I had this issue because I had some errors in my code but it was not showing.
Debug it manually. All the best.
Xcode 6 Beta 5 went into a tailspin for me immediately after I wrote out an expression to concatenate 3 strings and an NSDate object with the "+" operator.
Wouldn't compile and got stuck indexing.
Search your code for long string concats and remove for now. This is clearly a bug.
Several things you can try:
Clean the project: Product -> Clean
Go to Product try other options such as Analyze or Profile, see if it still stuck on build.
Restart xcode
Reboot System
Open system console and try to trace the problem.
Last but most importantly, really, because they are beta version, there will be some unexpected bugs. If it still cannot be solved, please report it to Apple and expect it to be fixed in beta 3.
Based on your comment, go to Terminal and type in: defaults write com.apple.dt.XCode IDEIndexDisable 1
This bug will relate to our project state and source code.
I rolled back some commits of my project, xcode succeeded indexing my project.
In my case, xcode failed to index, when my project has a declaration of large dictionary.
(I succeed indexing after removing it.)