335,525
questions
1502
votes
44
answers
526k
views
Passing data between view controllers
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 ...
1140
votes
17
answers
382k
views
How do I call Objective-C code from Swift?
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 ...
1090
votes
61
answers
675k
views
How to change Status Bar text color in iOS
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 ...
1020
votes
20
answers
256k
views
#pragma mark in Swift?
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, ...
988
votes
9
answers
119k
views
Swift Beta performance: sorting arrays
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 ...
968
votes
20
answers
686k
views
How to iterate a loop with index and element in Swift
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):
...
886
votes
19
answers
355k
views
#ifdef replacement in the Swift language
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
...
845
votes
41
answers
542k
views
Get the length of a 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.
839
votes
41
answers
811k
views
Split a String into an array in Swift?
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 = // ...
752
votes
19
answers
308k
views
How do I see which version of Swift I'm using?
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?
699
votes
24
answers
357k
views
@selector() in Swift?
I'm trying to create an NSTimer in Swift but I'm having some trouble.
NSTimer(timeInterval: 1, target: self, selector: test(), userInfo: nil, repeats: true)
test() is a function in the same class.
...
687
votes
43
answers
188k
views
iOS 8 UITableView separator inset 0 not working
I have an app where the UITableView's separator inset is set to custom values - Right 0, Left 0. This works perfectly in iOS 7.x, however in iOS 8.0 I see that the separator inset is set to the ...
676
votes
23
answers
759k
views
Convert Int to String in Swift
I'm trying to work out how to cast an Int into a String in Swift.
I figure out a workaround, using NSNumber but I'd love to figure out how to do it all in Swift.
let x : Int = 45
let xNSNumber = x ...
673
votes
34
answers
366k
views
iOS app with framework crashed on device, dyld: Library not loaded, Xcode 6 Beta
This crash has been a blocking issue I used the following steps to reproduce the issue:
Create a Cocoa Touch Framework project
Add a swift file and a class Dog
Build a framework for device
Create a ...
660
votes
27
answers
609k
views
How do I check if a string contains another string in Swift?
In Objective-C the code to check for a substring in an NSString is:
NSString *string = @"hello Swift";
NSRange textRange =[string rangeOfString:@"Swift"];
if(textRange.location != NSNotFound)
{
...