Skip to content
archive

stack-overflow-swift-2026-06-02

Swift · · 2 min read

Stack Overflow — Top Swift Questions — 2026-06-02

Ingested at: 2026-06-02T08:08:23Z Source: Stack Exchange API (tagged: swift, sort: votes) Total questions: 10

Passing data between view controllers

Score: 1503 | Answers: 44 | Tags: ios, objective-c, swift, model-view-controller, uiviewcontroller Link

I'm new to iOS and Objective-C and the whole MVC paradigm and I'm stuck with the following: I have a view that acts as a data entry form and I want to give the user the option to select multiple products. The products are listed on another view with a UITableViewController and I have enabled multipl

How do I call Objective-C code from Swift?

Score: 1143 | Answers: 17 | Tags: swift, objective-c Link

In Swift, how does one call Objective-C code?

Apple mentioned that they could co-exist in one application, but does this mean that one could technically re-use old classes made in Objective-C whilst building new classes in Swift?

How to change Status Bar text color in iOS

Score: 1096 | Answers: 61 | Tags: ios, swift, ios7, statusbar, uistatusbar Link

My application has a dark background, but in iOS 7 the status bar became transparent. So I can't see anything there, only the green battery indicator in the corner. How can I change the status bar text color to white like it is on the home screen?

#pragma mark in Swift?

Score: 1022 | Answers: 20 | Tags: swift, documentation Link

In Objective C, I can use #pragma mark to mark sections of my code in the symbol navigator. Since this is a C preprocessor command, it's not available in Swift. Is there a stand-in for this in Swift, or do I have to use ugly comments?

Swift Beta performance: sorting arrays

Score: 990 | Answers: 9 | Tags: swift, performance, sorting, xcode6, compiler-optimization Link

I was implementing an algorithm in Swift Beta and noticed that the performance was very poor. After digging deeper I realized that one of the bottlenecks was something as simple as sorting arrays. The relevant part is here:

let n = 1000000 var x = [Int](repeating: 0, count: n) for i in 0..<n {

How to iterate a loop with index and element in Swift

Score: 979 | Answers: 21 | Tags: arrays, swift, enumeration Link

Is there a function that I can use to iterate over an array and have both index and element, like Python's enumerate? for index, element in enumerate(list): ...

#ifdef replacement in the Swift language

Score: 887 | Answers: 19 | Tags: swift, xcode, preprocessor, preprocessor-directive Link

In C/C++/Objective C you can define a macro using compiler preprocessors. Moreover, you can include/exclude some parts of code using compiler preprocessors. #ifdef DEBUG // Debug-only code #endif

Is there a similar solution in Swift?

Get the length of a String

Score: 846 | Answers: 41 | Tags: swift, string Link

How do you get the length of a String? For example, I have a variable defined like:

var test1: String = "Scott"

However, I can't seem to find a length method on the string.

Split a String into an array in Swift?

Score: 844 | Answers: 41 | Tags: arrays, swift, string, split Link

Say I have a string here: var fullName: String = "First Last"

I want to split the string based on whitespace and assign the values to their respective variables var fullNameArr = // something like: fullName.explode(" ")

var firstName: String = fullNameArr[0] var lastName: Stri

How do I see which version of Swift I'm using?

Score: 761 | Answers: 19 | Tags: swift, xcode, terminal Link

I just created a new Swift project within Xcode. I am wondering which version of Swift it's using.

How can I see, in Xcode or the terminal, what version of Swift I am using inside my project?