All Questions

225
votes
6answers
166044 views

What does "fatal error: unexpectedly found nil while unwrapping an Optional value" mean?

My Swift program is crashing with EXC_BAD_INSTRUCTION and this error. What does it mean, and how do I fix it? fatal error: unexpectedly found nil while unwrapping an Optional value This post is ...
750
votes
12answers
221297 views

How to call Objective-C code from Swift

In the new Swift language from Apple, 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...
50
votes
1answers
9860 views

Speed up fetching posts for my social network app by using query instead of observing a single event repeatedly

I have an array of keys which lead to post objects for my social network like so /posts/id/(post info) When I load the posts I load /posts/0 and then /posts/1 etc using the observeSingleEventOfType(...
456
votes
15answers
194736 views

dispatch_after - GCD in swift?

I've gone through the iBook from Apple, and couldn't find any definition of it : Can someone explain the structure of dispatch_after? dispatch_after(<#when: dispatch_time_t#>, <#queue: disp...
220
votes
21answers
49842 views

How do I shuffle an array in Swift?

How do I randomize or shuffle the elements within an array in Swift? For example, if my array consists of 52 playing cards, I want to shuffle the array in order to shuffle the deck.
53
votes
3answers
3653 views

Protocol doesn't conform to itself?

Why doesn't this Swift code compile? protocol P { } struct S: P { } let arr:[P] = [ S() ] extension Array where Element : P { func test<T>() -> [T] { return [] } } let res...
507
votes
28answers
114203 views

Using a dispatch_once singleton model in Swift

I'm trying to work out an appropriate singleton model for usage in Swift. So far, I've been able to get a non-thread safe model working as: class var sharedInstance:TPScopeManager { get { ...
52
votes
3answers
6647 views

How to initialize properties that depend on each other

I want a picture to move to the bottom. If I press a button the pic should move down by 1. I added the picture and a button: var corX = 0 var corY = 0 var runter: UIButton = UIButton.buttonWithTyp...
559
votes
20answers
246803 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. ...
250
votes
19answers
266675 views

Loading/Downloading image from URL on Swift

I'd like to load an image from a URL in my application, so I first tried with Objective-C and it worked, however, with Swift, I've a compilation error: 'imageWithData' is unavailable: use object ...

Previous Next