4

Does anyone know the legit first setting for learning code in Xcode? The data on the right side not showing inside an Array but only the type data inside it.

Currently learning it, usually I do code in VScode.

Result of the setting, like a guide.

Image of xcode preview

1
  • print(morenames) or print(copy). Commented Nov 1, 2023 at 4:32

1 Answer 1

3

In older versions of Xcode, the contents of arrays was indeed shown on the right sidebar. See the screenshot from this question.

In the Xcode 15 release notes, there was a whole section about Playgrounds, which mentioned:

The result sidebar in Xcode Playgrounds shows summaries for all expressions on the line, and a new control allows you to see a popover with details about each expression.

"Array of 3 string elements" indeed sounds like a "summary" for the expression, and you can indeed click on the eye button on the right to see a popover (or the bordered square button on the left to show an inline panel), containing a structured description.

enter image description here

Output:

enter image description here

This looks like it is intended this way. Each element is displayed in its own line, together with the element's index. If you find this hard to read, you can conform Array<String> to CustomPLaygroundDisplayConvertible, and return a string (or anything else that playgrounds support displaying) there.

For example, here I implemented it so that the array's elements are all joined together in a single String, with , separators.

extension Array: CustomPlaygroundDisplayConvertible where Element == String {
    public var playgroundDescription: Any {
        self.joined(separator: ", ")
    }
}

Now the display on the right is a lot easier to read.

enter image description here

Do be careful that doing this will affect the display of all Array<String> (or whatever type the extension is all).

Sign up to request clarification or add additional context in comments.

4 Comments

I understand it, but i want it to display without clicking of the result first. i thought there is some setting i need to do. and thought? i already knew about seeing the result on the right with clicking.
@Andre No I don't think that is possible.
@Andre Actually, now that I think about it, I remember being able to see array's elements in older versions of Xcode, though that might be the result of print showing on the right side bar. Since Xcode 15 changed a lot about playgrounds, "not displaying array contents inline anymore" might have been one of the changes (see the release notes).
thanks for the explanation sweeper. now that i understand. even for me it's quiet weird that they change something like this in different Xcode version

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.