Xcode 6 Beta / Swift - Playground not updating - swift

I was playing around with the Playground feature of Xcode 6's first beta - and I notice half the time the Playground doesn't update (simply doesn't display the result calculation or how many loop iterations are happening) simple code/loops/functions that are in there. Even the Swift Tour https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/GuidedTour.html
has several lines of code that don't show up in Playground. If you mess with the code sometimes it will show up, by moving the code around or placing it elsewhere. Anyone else? Any fixes? Is this just a beta problem?

Make sure you haven't inadvertently added an error to your Playground code. Unfortunately, there is no inline notification of an error, and after an error is created, nothing in the Playground will update.
To help with this, open up the Assistant Editor (File > View > Assistant Editor > Show Assistant Editor), which should include a Console Output box. If there are any errors in your Playground, they will show up there. Once corrected, your Playground should hopefully update once more.
That said, it can be a bit slow depending on the complexity of your Playground and its size.

This answer (Undeclared Type 'NSView' in Playground) did it for me (restarting Xcode and the machine didn't help):
rm -rf "$(getconf DARWIN_USER_CACHE_DIR)/org.llvm.clang/ModuleCache"

Had the same strange errors after upgrading to xcode 6 beta 6. For me the problem got fixed with a Product -> Clean. And if that does not fix the errors hold down option key and click again on Product in the Menubar then you will see in the dropdown menu Clean Build Folder... click on that. Or you could download Watchdog app from appstore. This little helper automatically cleans your xcode projects.

You have to be very careful with swift. the language is very case sensitive so while using playground make sure all things are spaced out.
The following code will NOT give you a syntax error but it will stop processing the rest of your code in playground :
for index in 1...5 {
if index %2 !=0{
continue
}
println(index)
}
The error in the code above is in line 2. The code has to be written
for index in 1...5 {
if index % 2 != 0 {
continue
}
println(index)
}
Hope that answers your question :)

Related

why is xcode console output sluggish after app launch in simulator?

During a marathon session yesterday (from 7 am until past midnight), I suddenly ran into an issue where, immediately after launching the app in the simulator, button taps with prints to the console and swipes on views wouldn't result in any change for about 15 seconds. Eventually (10 - 15 seconds) the console output appears, the views swipe and it seems normal again.
I am using Xcode version 12.5 (12E262) on Big Sur 11.2.3
I have looked at these, and countless others:
iPhone Simulator suddenly started running very slow
Xcode freezes on startup while loading project
I removed the project's folder from Derived Data, I confirmed "Slow Animations" is not checked. I did not remove "xcuserdata" folder. I just don't know where to turn to debug this issue. Has anyone seen this behavior? Did I stutter and hit a key combination (Triple tap on Shift and CMD-T both used to toggle slow animations I've learned)? I feel like I've added code that is triggering this, but I can't be sure. I had spent the entire day refactoring my project to reduce the Objective-C and UIKit code and make better use of Composable Architecture (TCA). If people suggest debug steps I could perform I'll try them out and report back. I just don't know how to continue debugging this issue.
Backups from before the day's changes do not exhibit this behavior. I copied the project to a new directory and replaced all source code with the backed up source code. And that works fine. So I can lose the work from 3 pm to midnight last night or suffer through this until I have disk space to install 12.5.1
Any insights would be most welcome
So I ran a timer profile -- see this awesome article:
https://www.avanderlee.com/debugging/xcode-instruments-time-profiler/
I came up with this:
Which led to this:
And I understood where I introduced the problem:
var selectedNibIndex: Int = 0 {
didSet {
brush = WDBrush.from(index: selectedNibIndex)!
cameoImage = BrushStrokeImageView(paintBrush: brush)
dictionary = brush.wdPropertiesDictionary() as! [String: WDProperty]
}
}
this is new code, and it is placed inside a struct which is constantly being rebuilt.
I will move it out of there.
**
I guess the answer to my question is to run the app under the time
profiler and let it tell you where the problem is.
**
And marathon sessions aren't always a good idea. I would have caught the problem sooner if I hadn't bitten off such a big task. There was a two hour period where it wouldn't compile and I shouldn't have let that happen. By the time I got it to compile after some changes I had changed so many things I could no longer see the forest for the trees.
I hope this can help others, thanks for reading!

swiftc failed with exit code 1

extension SlideInAnimator: UIViewControllerAnimatedTransitioning {
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
// This works
UIView.animate(withDuration: 0.3, animations: { }) { transitionContext.completeTransition($0) }
// transitionContext.completeTransition causes the error
UIView.animate(withDuration: 0.3, animations: { }, completion: transitionContext.completeTransition)
}
}
Xcode isn't showing any errors but while compiling, it causes the error shown in the title (even after cleaning). Whenever I comment out the second animation, the error won't show up. Is this a bug or I'm just not allowed to use it like the second animation?
The swiftc failed with exit code 1 message indicates that the compiler crashed due to an internal problem. In my experience, that may or may not indicate that there's some type of syntax error with your code (although what you posted looks fine to me), but either way, the compiler can't handle it as you have it written.
The Swift toolchain is still very buggy unfortunately, and sometimes you have to "help it out" by trying a different syntax for whatever you're doing.
You may want to check https://bugs.swift.org and see if there's a bug already reported for it, and add one if not.
Simple Solution For This With xcode 8.2 and swift 3.0
Click top left of the project navigator (your project name ) and clean project with (cmd+shft+k).
Quite Xcode completely from tray too.
Open project again.
wait and let xcode done indexing of files.
Run project and thats it.
Enjoy Happy Coding!!!
I've just spent a couple of hours trying to identify the cause of a swiftc exit code 1.
After reading several posts, cleaning the project & restarting xcode several times, commenting out new chunks of code etc., I gave up and started to create a fresh project.
When I copied the first .swift file from old to new project I noticed that I had two .swift files with the same name in different folders. I tidied up my files and the project compiled OK.
In summary, as has been stated in other posts, Exit code 1 seems to be a catchall for when the compiler finds something weird & unexpected that it doesn't handle properly.

Playground is not showing result on right bar

I waited long time but my playground project is not showing result on right side bar
I am using right code but still right bar is not updating i don't know what is the problem i tried lot of time.
here is my code
var str = "Hello, playground"
var str1 = "this is my first program"
let kermit = "kermit"
let msPiggy = "ms. piggy"
let string1 = msPiggy + " and " + kermit + ", sitting in a tree"
let string2 = "\(msPiggy) and \(kermit), sittting in a tree "
let string3 = " kermit has \(5*2) fingers"
let chr1:Character = "💿"
As of Xcode 8, unless you are print-ing out things, results in the playground could take a little bit more work to show.
In this screenshot, I show two things you can click on. #1 is the the "Show Debug Area" button, the middle button in the top right of the toolbar (i.e. which toggles the lower pane that slides up and down in the Xcode window). Results from print end up there.
Also, the second set of (multiple) circles shows that you can click on to show results. You can slide the gray bar space wider to make things show.
Lastly, where you see the "Play" triangle in the lower toolbar, try clicking on that to force the Playground to execute your code again.
In my case, I had to close Xcode 9.2 and close all simulators, then restart playground file, then it worked.
I am also facing this problem as shown in below image
There is no log on the right bar
So what we do :
We just Quit Xcode and again open playground project
and it works fine
also, there is one more button through which you can set automatically and manually run
If you have M1 chip MacBook Pro, you have to uncheck Rosetta to get the Playground working.
My result area was somehow too narrow to show the results. Try dragging it larger.
It's not the assistant editor that should be enabled. It's the little grey bar to the right that is too narrow. If you hover your mouse pointer just next to an expected result, you will see the familiar little eye and radio button icon. Then drag the bar out and it'll show.
Hope it works!
I had the same issue, and discovered that if I held down the Play icon above the debug area (revealed at the bottom of the playground), it had an option, 'Automatically Run'.
I selected that, and all is well!
Cheers.
add import PlaygroundSupport to the top of your code! i had the same issue and it worked perfectly.
In Xcode 10.1 I changed build system to Legacy Build System from file > Playground Setting. It fixed my problem
In my case I have two Xcode versions installed on my mac. (v8.2.1 and v7.3.1)
The two Xcode is running simultaneously, and then when I decided to open a playground on v8.2.1 and printed out some codes. Playground should run it automatically but it is stuck in Running my file.
What I did is I restarted both of my Xcode applications and then Playground succesfully printed my codes.
https://forums.developer.apple.com/thread/3672
playground will not show results if any of your previous lines has error, you will have to remove those errors and all the results would immediately start showing up on right side bar.
In my case for Xcode 9.2, output started appearing when I clicked File/New/Tab. So, Playground seems missing some refresh option and new tab did that.
oftentimes, I need to close my playground and Xcode and relaunch it again to see the results.
Also had this problem. "Editor › Run Playground" worked for me.
In my case i ensured i set the right Command Line Tool version by tapping Xcode>Preferences>Locations and it worked.
i made a checklist to resolve this issue
First of all make sure your 'result area' is not hidden, There
should be some grey (result area) on right side, if whole
screen is white then try to pull it from right-edge of screen.
Make sure there is no code error, you can check code error in 'debug
area'.
If both point are resolve though you can not see result then try to
print('hello world') at last.
In my case, I was saving my playground somewhere else than the default path and it didn't show the result. Saving it on the default path made it work.
In my case,
ios: macOS Catalina Version 10.15.7
Xcode
Version 12.1 (12A7403)
1.First Go to Editor then click run playgound
2.Then it will show the running results on the right side.
With Xcode 12+, please uncheck Open using Rosetta.
I saved my playground to the folder of my choosing, all the solutions to save it in default location are simply silly...
I did have enabled the right-hand side area and console-output on the bottom.
Whether running from Edit->Run Playground or using Cmd+Return didn't help, still no output was shown. Even though my code was solid and I could see Build Succeed in the top notificaiton area...
After checking Preferences->Locations I could see there are no Command Line Tools seleceted, so I choosed only one available option (Xcode 13.2.1) and... still no output...
Then I closed XCode with Cmd+Q and started it again...
Finally it worked and output was shown...

nslog stopped working in xcode

I have a strange issue and possibly a bug. My NSLog statements have stopped working completely, they do not print even in view did load, application didfinishlaunching etc. The have all turned a brown colour (the same colour as a pragma mark in xcode) and they all have a warning saying 'expression result unused'. Has anyone ever seen this before or know what to do? Am i running in some kind of weird mode? Im running xcode 4.0.2.
Many thanks
Jules
for completeness, I had the same problem and the answer was different, hope it helps someone else who bumps into this post:
I had a framework (an Amazon one) redefining NSLog, went there (Cmd+Click on the Brown NSLog) and commented out the redefinition...
The actual problem was the release_build set to 1. So it wasn't recognizing nslog, as you said it was set for a release build.
I had the same issue :
what worked for me is given below:
Remove the derived data folder
After removing derived data perform the clean action (You can see this option in the product menu)
Quit the Xcode and start it again.
And this did the trick all my NSLog were working fine.
Hoep this helps
Ensure that scheme chosen corresponds to Debug mode because sometimes the pch file might have some definitions such that logging is done only in the debug mode
(Scheme is on to the left of the place where you select iPhone Simulator / iOS Device)
In the view select Debug Area
(There are 3 view buttons, on the top right hand corner of Xcode, press the center button)
Select "Show variables view and the console"
(In the debug area (bottom) there are ther 3 buttons, press the center button)
I had the same issue and the problem was that I was building an Ad Hoc version (schema was for Ad Hoc build). The warnings disappeared when I built for debug.
Try changing the dropdown menu at the bottom of the console to 'All Output'.
if you are using libraries like 'KScan' or 'iKEA' or 'kdc-scan', so it can happens that, they will call methods like this one 'redirectNSLogToDocuments'.
in my case the object of 'iKEA' call the method 'CheckIfDeviceConnected' and this one redirect all nslog outputs to documents. after commenting out, all nslogs works again :)
hope this will be useful for some one.
some steps :-
1) "Clean all targets" or delete your build and rebuild again.
2) If step 1 doesnt work , reinstall xcode

Xcode 4 is no longer showing me where my warnings are?

Xcode 4 has stopped showing me the locations of build warnings that I have. How can i get it to start showing me them again?
Make sure you're looking in the right place. On the left-hand side of Xcode (4), look for the little error symbol. Click it and enjoy your errors in all their glory.
If you click on the errors and it doesn't take you to the location in code, I think something must be messed up with your Xcode install. I remember you had another question earlier about Xcode problems, so it wouldn't hurt to uninstall & reinstall.
In Xcode 4.3.1. I have one project that doesn't show any warnings, but others do.
So it's not an Xcode issue I guess.
In the Issue Navigator (⌘4) be sure to clear the filter at the bottom left of the screen:
Just click on the x at the right, at the filter will be removed -- worked for me!
Check the below SO post
(iphone) Is there a way to see compile output of xcode4?
press command + 4 for issue navigator. (there are two filter here "By File" and "By Type")