Unable to hide code from a Playground Page - swift

I tried hiding code from my Playground page by following Apple's doc: https://developer.apple.com/documentation/swift_playgrounds/hiding_code_from_a_playground_page
However, the following doesn't seem to work when rendering the documentation/playground page. Am I missing something here?
//#-hidden-code
import Foundation
import PlaygroundSupport
//#-end-hidden-code
Tested on:
Xcode 12.0
Xcode 11.5

Related

How to use UIDocumentPickerViewController to import files in iOS 16

I was trying to use the UIDocumentPickerViewController to import some pdf files in my Swift UIKit App. I'm not able to properly use the UIDocumentPickerViewController to display the files app and import the files from there.
The initialiser UIDocumentPickerViewController(documentTypes: [String], in: UIDocumentPickerMode) was deprecated in iOS 14.0. I can still use it but is there a better way to do the same thing which is not deprecated and is used in the latest version of iOS?
Importing "UniformTypeIdentifiers" seems to enable the "init(forOpeningContentTypes: [UTType])" initializer.

No such module Error "NotificationCenter" WatchOS, Swift

I'm getting an module error in two of my controllers who tries to import the NotificationCenter framework. I have added the framework in "linked frameworks and libraries" but I'm still getting the error.
I even tried cmd + shift + k, but it did not do any good for me.
I also tried to set the framework search path to $(SRCROOT), but still same error.
I have two controllers with the import.
Linked frameworks and libraries
Added notificationCenter
TimeController
import WatchKit
import Foundation
import NotificationCenter error: "No such module 'NotificationCenter'"
SwipeController
import WatchKit
import Foundation
import NotificationCenter error: "No such module 'NotificationCenter'"
Any help would be much appreciated!
I agree with #David's comment, There are three targets for a single watchOS project.
You need to try these steps for each Target:
Select each target and go to -> Build Phases
Click on the right arrow. and click on the +
Finally, search for NotificationCenter and add the framework.
You need to try these steps for each target.

Linking pages in Swift Playgrounds [Xcode]

I am new to swift playgrounds and ran into some problems while making a swift playground in Xcode.
This is my main Playground page
import UIKit
import PlaygroundSupport
import SpriteKit
let secondScene = Index()
let master = FirstScene()
let root = UINavigationController(rootViewController: master)
PlaygroundPage.current.liveView = root
But when I tried adding Next Topic in both the source class in Swift and the playground page itself the link does not appear.
NOTE: I am using Swift Playgrounds in Xcode not a Playgroundbook on an iPad.
Also, inside sources folder of my main page I declared all classes as public, is that the right way to use the helper swift files in source?
I tried creating a new playground and added pages which have default links but still no output.
Looking at your screenshot, you've got the code right. The syntax to link to the next page is [Next Page!](#next). All you need to do now is:
- In the Xcode menu bar, click Editor
- Click 'Show Rendered Markup'
That's it. You can place markup wherever you like. Remember to replace spaces with %20 when linking to a playground page, e.g. [My Page #2](My%20Other%20Page)
You would benefit from reading Apple's Markup Formatting Reference.
To create a link to another page you will do the same thing that I did above to create a link to that reference in Markdown:
[Next Topic](Pretend%20Topic%20Name)
You can actually do something like this as well:
[Next Topic](#next)

Playground Xcode never stops running, any ideas?

I have been learning Swift and had a recurring problem throughout. The playground, when run, doesn't finish running the code, even the default MyPlayground file. I get no output whatsoever.
I have searched online and others have the same problem as me but no answer. This happens for the default and built up files I have created previously.
I spoke to Apple on 3 separate occasions and got nothing and referred to the Developer forums and they haven't got an answer either.
Any ideas guys?
For example,
//: Playground - noun: a place where people can play
import Cocoa
var str = "Hello, playground"
print(str)
This is the default and when run, I don't get the output of str or anything in the Utilities view, it just says running MyPlayground at the top.
Thanks
What are you building for? iOS, macOS, or tvOS?
The default file for macOS is as you say:
import Cocoa
var str = "Hello, playground"
Which runs perfectly, with no errors.
But when I run your code built for iOS, Xcode throws an error:
Swift Compiler Warning: No such module `Cocoa`.
Either way, you cannot import Cocoa in playgrounds built for iOS, so don't import Cocoa, import UIKit instead. Besides, import UIKit is the default file when building for iOS. So I suspect you're running the default macOS file in an iOS build of playgrounds.
There is another question here which addresses the issue of importing Cocoa in Playgrounds.
Since you're having what looks like a null pointer exception, based on your comment, likely from the project trying to load a non-existent object, here are some troubleshooting steps:
Erase import Cocoa.
Type in import (Notice the space at the end.)
Type in C
If C doesn't come up with an autocomplete list with Cocoa in it, then it's not part of the build.
And this would explain the null pointer exception (EXC_BAD_ACCESS at 0x0.)
Next, in the same playground:
Erase the import Cocoa line
Type in import (space at the end.)
Type in UI and wait for an autocomplete list
If UI has the autocomplete option for UIKit, then Cocoa isn't part of the playground.
Which is why there is a null pointer error.

Symbol not found: NSHTTPCookieStorage

I'm new to IOS programming and now experimenting with Swift. Everything was working fine until I tried to use facebook SDK. I added a new bridging header to import facebooksdk, and in my view controller I have
var fbl: FBLoginView = FBLoginView()
But this line gives me an error when deploying the app to my phone, and it crashes with app launch. The error code I get is:
dyld: Symbol not found: _OBJC_CLASS_$_NSHTTPCookieStorage
When using the simulator tho, everything works fine. What would be the reason for this error?
Did you import foundation?
import Foundation