Swift

Swift is a general-purpose, open-source programming language developed by Apple Inc. for their platforms and Linux. Use the tag only for questions about language features, or requiring code in Swift. Use the tags [ios], [osx], [watch-os], [tvos], [cocoa-touch], and [cocoa] for (language-agnostic) questions about the platforms or frameworks.

57 votes
1 answers
2K views
How to use swift library in NativeScript?

I am trying to use this ios-charts library in NativeScript. This library is written in Swift and not in Object

avatar
Sydney
0 1 0 9
asked 07 September, 2021
62 votes
21 answers
1.9K views
Add bottom border line to UI TextField view in SwiftUI / Swift / Objective-C / Xamarin

I would like to keep the border at the bottom part only in UITextField. But I don't know how we can keep

avatar
Rudy
0 1 0 9
asked 07 September, 2021
57 votes
18 answers
344 views
Updating to latest version of CocoaPods?

I'm having some issues installing Alamofire 4.0 into my project. I've got the latest version of Xcod

avatar
Jeff
0 1 0 9
asked 07 September, 2021
53 votes
25 answers
1.1K views
How can I change image tintColor in iOS and WatchKit

I have an UIImageView called "theImageView", with UIImage in a single color (transparent background) just like

avatar
Don
0 1 0 9
asked 07 September, 2021
64 votes
14 answers
333 views
How do I concatenate or merge arrays in Swift?

If there are two arrays created in swift like this: var a:[CGFloat] = [1, 2, 3] var b:[CGFloat] = [4, 5, 6]

avatar
Benton
0 1 0 9
asked 07 September, 2021
58 votes
18 answers
351 views
How do I get a reference to the app delegate in Swift?

How do I get a reference to the app delegate in Swift? Ultimately, I want to use the reference to access the

avatar
Eddie
0 1 0 9
asked 07 September, 2021
60 votes
30 answers
2.7K views
Close iOS Keyboard by touching anywhere using Swift

I have been looking all over for this but I can't seem to find it. I know how to dismiss the keyboard us

avatar
Denese
0 1 0 9
asked 07 September, 2021
64 votes
12 answers
1.8K views
What does "Fatal error: Unexpectedly found nil while unwrapping an Optional value" mean?

My Swift program is crashing with EXC_BAD_INSTRUCTION and one of the following similar errors. What does this

avatar
Alba
0 1 0 9
asked 07 September, 2021
71 votes
9 answers
2K views
Static vs class functions/variables in Swift classes?

The following code compiles in Swift 1.2: class myClass { static func myMethod1() { } class func

avatar
Stacia
0 1 0 9
asked 07 September, 2021
58 votes
30 answers
1.6K views
Get nth character of a string in Swift programming language

How can I get the nth character of a string? I tried bracket([]) accessor with no luck. var string = "Hello,

avatar
Corrin
0 1 0 9
asked 07 September, 2021
55 votes
29 answers
801 views
How to determine the current iPhone/device model?

Is there a way to get the device model name (iPhone 4S, iPhone 5, iPhone 5S, etc) in Swift? I know there is a

avatar
Basil
0 1 0 9
asked 07 September, 2021
54 votes
12 answers
1.1K views
How do I write dispatch_after GCD in Swift 3, 4, and 5?

In Swift 2, I was able to use dispatch_after to delay an action using grand central dispatch: var dispatchTim

avatar
Benton
0 1 0 9
asked 07 September, 2021
61 votes
30 answers
712 views
How do I get the App version and build number using Swift?

I have an IOS app with an Azure back-end, and would like to log certain events, like logins and which versions

avatar
Dwain
0 1 0 9
asked 07 September, 2021
51 votes
30 answers
2.3K 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,

avatar
Lorenzo
0 1 0 9
asked 07 September, 2021
54 votes
25 answers
2.9K views
How does one generate a random number in Apple's Swift language?

I realize the Swift book provided an implementation of a random number generator. Is the best practice to cop

avatar
Adolfo
0 1 0 9
asked 07 September, 2021
58 votes
30 answers
1.6K views
How to hide UINavigationBar 1px bottom line

I have an app that sometimes needs its navigation bar to blend in with the content. Does anyone know how to

avatar
Corey
0 1 0 9
asked 07 September, 2021
61 votes
29 answers
1.6K views
Rounding a double value to x number of decimal places in swift

Can anyone tell me how to round a double value to x number of decimal places in Swift? I have: var totalWor

avatar
Ali
0 1 0 9
asked 07 September, 2021
53 votes
9 answers
2.2K views
Shall we always use [unowned self] inside closure in Swift

In WWDC 2014 session 403 Intermediate Swift and transcript, there was the following slide The speaker said

avatar
Serina
0 1 0 9
asked 07 September, 2021
54 votes
23 answers
2.1K views
How to find index of list item in Swift?

I am trying to find an item index by searching a list. Does anybody know how to do that? I see there is list

avatar
Kisha
0 1 0 9
asked 07 September, 2021
58 votes
12 answers
2K views
The use of Swift 3 @objc inference in Swift 4 mode is deprecated?

Briefly, while using Xcode 9 Beta, I have run into the following warning: The use of Swift 3 @objc inferen

avatar
Scot
0 1 0 9
asked 07 September, 2021