swift2 Questions
2
Solved
Is it possible to use guard outside of a function?
The following throws an error that return or break needs to be used but that isn't possible in this case.
var var1 = String?()
guard let validVa...
Minny asked 29/9, 2015 at 4:10
8
Solved
I am looking for some up to date help/hints on how to draw simple single line strings around the edge of a circle using Swift2 for iOS9. I see quite dated examples involving old ObjC fragments, and...
4
Solved
I have some problem asking user for permission about camera. The authorizationStatus is always NotDetermined. When I tried to ask user for permission, AVCaptureDevice.requestAccessForMediaType neve...
11
Solved
Let's say there are two arrays...
var array1 = ["a", "b", "c"]
var array2 = ["b", "c", "a"]
I'd like the result of the comparison of these two arrays to be true, and the following...
var array1...
8
Solved
How should I handle if there is an error occurs when there is no internet connection in Alamofire. I tried checking if data is nil or not but it does not work.
Below is how I use Alamofire
Alamof...
3
Solved
I am trying to use an Optional Int in Realm and am getting an old error I think.
Code
dynamic var reps: Int? = nil
Error
'Property cannot be marked dynamic because its type cannot be represen...
Guthrie asked 26/10, 2015 at 21:58
10
Solved
I need to get a UIImage only instead of loading a normal UIImageView with Kingfisher library
To realize it I implemented a workaround with UIImageView:
let imageView = UIImageView()
imageView.k...
Lucilius asked 4/2, 2016 at 15:10
3
Solved
I've run into this silly behaviour in swift where force-unwrapping an optional does not propagate.
From the documentation:
Trying to use ! to access a non-existent optional value triggers a run...
3
I can't seem to figure out how to grab a users "My Card" from contacts. I am developing a native Mac application using swift.
6
Solved
I want to remove a key-value pair from a dictionary like in the example.
var dict: Dictionary<String,String> = [:]
//Assuming dictionary is added some data.
var willRemoveKey = "SomeKey&...
Hautbois asked 29/9, 2015 at 14:41
15
Solved
I'm trying to write a function to present thousands and millions into K's and M's
For instance:
1000 = 1k
1100 = 1.1k
15000 = 15k
115000 = 115k
1000000 = 1m
Here is where I got so far:
func for...
6
I have been implementing the home kit app in objective-c . I have converted all the swift code but stoped at one line called
guard let metadata = metadata else { return false }
Could any one ple...
Eastereasterday asked 13/11, 2015 at 4:14
11
Solved
I have been reading about Optionals in Swift, and I have seen examples where if let is used to check if an Optional holds a value, and in case it does – do something with the unwrapped value.
Howe...
Oversubscribe asked 27/8, 2015 at 18:23
8
Solved
Until Swift 2 I used this extension to remove multiple whitespaces:
func condenseWhitespace() -> String {
let components = self.componentsSeparatedByCharactersInSet(NSCharacterSet.whitespaceAn...
Napery asked 10/10, 2015 at 20:31
4
Solved
class SomeClass {
var someProperty: Int {
throw Err("SNAFU")
}
}
For code like the above, the swift binary complains 'error is not handled because the enclosing function is not declared 'throw...
13
Solved
So I can do this:
var stringNumb: NSString = "1357"
var someNumb: CInt = stringNumb.intValue
But I can't find the way to do it w/ a String. I'd like to do something like:
var stringNumb: Strin...
2
Now that we've reached Swift 2.0, I've decided to convert my, as yet unfinished, OS X app to Swift. Making progress but I've run into some issues with using termios and could use some clarification...
9
Solved
In a swift 2 command line tool (main.swift), I have the following:
import Foundation
print("yay")
var request = HTTPTask()
request.GET("http://www.stackoverflow.com", parameters: nil, completionH...
Renfrow asked 11/8, 2015 at 14:4
5
I'm confused about the internal and private access modifier.
The docs says:
“Internal access enables entities to be used within any source file
from their defining module, but not in any sour...
2
Solved
I'm applying a map to a dictionary that has a try in it. I'd like to skip the iteration if the mapped item is invalid.
For example:
func doSomething<T: MyType>() -> [T]
dictionaries.map...
4
Solved
When I declare static parameter in extension of class then I have to write @nonobjc before variable like:
@nonobjc static let test = "test"
and sometimes I have to write @objc before met...
Uppish asked 8/12, 2016 at 9:34
7
Solved
I have a Label which takes dynamicaly some data from database.
These data are strings which can sometimes be 3-4-5 rows etc.
So this labe is inside a UIView.
--UIView
--Label
How can i make the...
13
Solved
I am attempting to build an anagram checker for swift. This is my code. In case you don't know an anagram checker checks if two strings have the same characters in them but, order does not matter.
...
2
This is kind of a weird and un-Swift-thonic question, so bear with me.
I want to do in Swift something like the same thing I'm currently doing in Objective-C/C++, so I'll start by describing that.
...
Dullish asked 26/12, 2015 at 4:26
2
Solved
Is there an equivalent shortcut for a "Make Documentation Comment" like the one for regular comments - So it makes /// instead of //
1 Next >
© 2022 - 2024 — McMap. All rights reserved.