stack-overflow-swift-2026-06-03
Swift · · 2 min read
Top Voted #swift Questions
Passing data between view controllers ⭐1503 💬44
Tags: ios, objective-c, swift, model-view-controller, uiviewcontroller
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? ⭐1143 💬17
Tags: swift, objective-c
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 ⭐1096 💬61
Tags: ios, swift, ios7, statusbar, uistatusbar
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? ⭐1022 💬20
Tags: swift, documentation
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 ⭐990 💬9
Tags: swift, performance, sorting, xcode6, compiler-optimization
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 ⭐979 💬21
Tags: arrays, swift, enumeration
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 ⭐887 💬19
Tags: swift, xcode, preprocessor, preprocessor-directive
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 ⭐846 💬41
Tags: swift, string
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? ⭐844 💬41
Tags: arrays, swift, string, split
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? ⭐761 💬19
Tags: swift, xcode, terminal
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?...