All Questions
            9,958
            questions
        
        
            550
            votes
        
        
            32
            answers
        
        
            411k
            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 property named UIDevice.currentDevice().model but it only returns device type (iPod touch,...
            
        
       
    
            324
            votes
        
        
            18
            answers
        
        
            203k
            views
        
    Detect current device with UI_USER_INTERFACE_IDIOM() in Swift
                What is the equivalent of UI_USER_INTERFACE_IDIOM() in Swift to detect between iPhone and iPad?
I get an Use of unresolved identifier error when compiling in Swift.
            
        
       
    
            237
            votes
        
        
            16
            answers
        
        
            346k
            views
        
    Get User's Current Location / Coordinates
                How can I store the user's current location and also show the location on a map?
I am able to show pre-defined coordinates on a map, I just don't know how to receive information from the device.
...
            
        
       
    
            237
            votes
        
        
            12
            answers
        
        
            302k
            views
        
    How do you create a Swift Date object?
                How do you create a date object from a date in swift xcode.
eg in javascript you would do:
    var day = new Date('2014-05-20');
            
        
       
    
            231
            votes
        
        
            24
            answers
        
        
            412k
            views
        
    How to call gesture tap on UIView programmatically in swift
                I have a UIView and and I have added tap gesture to it: 
let tap = UITapGestureRecognizer(target: self, action: Selector("handleTap:"))
tap.delegate = self
myView.addGesture(tap)
I am trying to call ...
            
        
       
    
            217
            votes
        
        
            27
            answers
        
        
            176k
            views
        
    How do I hide the status bar in a Swift iOS app?
                I'd like to remove the status bar at the top of the screen.
This does not work:
func application
(application: UIApplication,
didFinishLaunchingWithOptions launchOptions: NSDictionary?)
-> Bool
{
...
            
        
       
    
            213
            votes
        
        
            4
            answers
        
        
            112k
            views
        
    Swift - Convert to absolute value
                is there any way to get absolute value from an integer?
for example   
-8  
to  
 8
I already tried to use UInt() assuming it will convert the Int to unsigned value but it didn't work.
            
        
       
    
            206
            votes
        
        
            12
            answers
        
        
            268k
            views
        
    How to segue programmatically in iOS using Swift
                I'm creating an app that uses the Facebook SDK to authenticate users. I'm trying to consolidate the facebook logic in a separate class. Here is the code (stripped for simplicity):
import Foundation
...
            
        
       
    
            190
            votes
        
        
            12
            answers
        
        
            147k
            views
        
    How can I scan barcodes on iOS? [closed]
                How can I simply scan barcodes on iPhone and/or iPad?
            
        
       
    
            183
            votes
        
        
            8
            answers
        
        
            117k
            views
        
    ViewDidAppear is not called when opening app from background
                I have a View Controller in which my value is 0 (label) and when I open that View Controller from another ViewController I have set viewDidAppear to set value 20 on label.  It works fine but when I ...
            
        
       
    
            167
            votes
        
        
            9
            answers
        
        
            70k
            views
        
    Obscure a UITextField password
                I am doing a login page. I have UITextField for password.
Obviously, I do not want the password to be seen; instead, I want circles to show when typing.
How do you set the field for this to happen?
            
        
       
    
            163
            votes
        
        
            8
            answers
        
        
            74k
            views
        
    How do I get the current version of my iOS project in code?
                I would like to be able to get the current version of my iOS project/app as an NSString object without having to define a constant in a file somewhere. I don't want to change my version value in 2 ...
            
        
       
    
            158
            votes
        
        
            29
            answers
        
        
            113k
            views
        
    How to remove border of the navigationBar in swift?
                i've been trying to remove the navigationBars border without luck. I've researched and people seem to tell to set shadowImage and BackgroundImage to nil, but this does not work in my case.
My code
  ...
            
        
       
    
            152
            votes
        
        
            29
            answers
        
        
            180k
            views
        
    unable to dequeue a cell with identifier Cell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard
                My UITableViewController is causing a crash with the following error message:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with ...
            
        
       
    
            151
            votes
        
        
            23
            answers
        
        
            217k
            views
        
    Transparent iOS navigation bar
                I'm creating an app and i've browsed on the internet and i'm wondering how they make this transparent UINavigationBar like this:
I've added following like in my appdelegate:
UINavigationBar....
            
        
       
    
            151
            votes
        
        
            12
            answers
        
        
            109k
            views
        
    How to make iPhone vibrate using Swift?
                I need to make the iPhone vibrate, but I don't know how to do that in Swift. I know that in Objective-C, you just write:
import AudioToolbox
AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);
But ...
            
        
       
    
            128
            votes
        
        
            12
            answers
        
        
            119k
            views
        
    How to get the filename from the filepath in swift
                How to get the filename from the given file path string?
For example if I have a filepath string as
file:///Users/DeveloperTeam/Library/Developer/CoreSimulator/Devices/F33222DF-D8F0-448B-A127-...
            
        
       
    
            123
            votes
        
        
            27
            answers
        
        
            51k
            views
        
    SourceKitService Consumes CPU and Grinds Xcode to a Halt
                This is NOT a Beta issue.  I am on Xcode 6.0.1, production release. The issue I am having is that when I try to do a Build or Run the code I am working on, Xcode becomes unresponsive for large periods ...
            
        
       
    
            119
            votes
        
        
            20
            answers
        
        
            162k
            views
        
    How to get the indexpath.row when an element is activated?
                I have a tableview with buttons and I want to use the indexpath.row when one of them is tapped.
This is what I currently have, but it always is 0
var point = Int()
func buttonPressed(sender: ...
            
        
       
    
            113
            votes
        
        
            12
            answers
        
        
            74k
            views
        
    The app delegate must implement the window property if it wants to use a main storyboard file swift
                I have just developed an app, but when running in the simulator the debugger console says:
  The app delegate must implement the window property if it wants to use
      a main storyboard file.
I ...
            
        
       
    
            113
            votes
        
        
            17
            answers
        
        
            197k
            views
        
    Simple and clean way to convert JSON string to Object in Swift
                I have been searching for days to convert a fairly simple JSON string to an object type in Swift but with no avail. 
Here is the code for web service call:
func GetAllBusiness() {
        Alamofire....
            
        
       
    
            109
            votes
        
        
            10
            answers
        
        
            85k
            views
        
    Can I change the size of UIActivityIndicator?
                Whatever size i give to it while allocation, it shows fixed size only. Is it possible to increase it? 
Code:
activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:
                     ...
            
        
       
    
            105
            votes
        
        
            17
            answers
        
        
            92k
            views
        
    How to detect when AVPlayer video ends playing?
                I'am using AVPlayer for playing local video file (mp4) in Swift.
Does anyone know how to detect when video finish with playing?
Thanks
            
        
       
    
            100
            votes
        
        
            5
            answers
        
        
            97k
            views
        
    how to add an action on UITextField return key?
                I have a button and text textfield in my view. when i click on the textfield a keyboard appears and i can write on the textfield and i also able to dismiss the keyboard by clicking on the button by ...
            
        
       
    
            96
            votes
        
        
            8
            answers
        
        
            78k
            views
        
    Location Services not working in iOS 11
                I just rebuilt my app with the iOS 11 SDK in an attempt to remove the blue banner that is now always appearing. I thought - "Brilliant, that worked", only to discover that location services are now ...
            
        
       
    
            95
            votes
        
        
            37
            answers
        
        
            147k
            views
        
    How to restrict UITextField to take only numbers in Swift?
                I want the user to only enter numeric values in a UITextField. On iPhone we can show the numeric keyboard, but on iPad the user can switch to any keyboard.
Is there  any way to restrict user to enter ...
            
        
       
    
            92
            votes
        
        
            7
            answers
        
        
            29k
            views
        
    @IBInspectable with enum?
                I'd like to create @IBInspectable element as you see at the picture below : 
my idea is to use something like enum as type for @IBInspectable, but it looks like it's not the case, any ideas how to ...
            
        
       
    
            90
            votes
        
        
            12
            answers
        
        
            10k
            views
        
    Swift default AlertViewController breaking constraints
                I am trying to use a default AlertViewController with style .actionSheet. For some reason, the alert causes a constraint error. As long as the alertController is not triggered (displayed) through a ...
            
        
       
    
            87
            votes
        
        
            7
            answers
        
        
            75k
            views
        
    Sending SMS in iOS with Swift
                First of all, I'm really surprised that this is not a duplicate, because there are TONS of stackoverflow questions that solve this in Objective-C, but I have yet to see a good answer that used Swift.
...
            
        
       
    
            86
            votes
        
        
            10
            answers
        
        
            198k
            views
        
    How to set textColor of UILabel in Swift
                When I try setting the color of a UILabel to the color of another UILabel using the code 
myLabel.textColor = otherLabel.textColor
It doesn't change the color. When I use this code, however,
...
            
        
       
    
            83
            votes
        
        
            13
            answers
        
        
            68k
            views
        
    Save images in NSUserDefaults?
                Is it possible to save images into NSUserDefaults as an object and then retrieve for further use?
            
        
       
    
            83
            votes
        
        
            14
            answers
        
        
            61k
            views
        
    safeAreaInsets in UIView is 0 on an iPhone X
                I am updating my app to adapt it for iPhone X. All views work fine by now except one. I have a view controller that presents a custom UIView that covers the whole screen. Before I was using UIScreen....
            
        
       
    
            82
            votes
        
        
            6
            answers
        
        
            114k
            views
        
    How to get the iPhone's screen width in SwiftUI?
                I want to resize an Image frame to be a square that takes the same width of the iPhone's screen and consequently the same value (screen width) for height.
The following code don't work cause it gives ...
            
        
       
    
            80
            votes
        
        
            5
            answers
        
        
            157k
            views
        
    How to insert new cell into UITableView in Swift
                I'm working on a project where I have two UITableViews and two UITextFields, when the user presses the button the data in the first textField should go into the tableView and the second go into the ...
            
        
       
    
            76
            votes
        
        
            3
            answers
        
        
            113k
            views
        
    Pass data through segue
                I'm doing simple iOS application with tableview controller and detailView. All I want is to pass data through segue.
this is how it looks.
All I want is that u click on "Markíza" it will open URL ...
            
        
       
    
            70
            votes
        
        
            12
            answers
        
        
            98k
            views
        
    How to set target and action for UIBarButtonItem at runtime
                Tried this but only works for UIButton:
[btn setTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
            
        
       
    
            69
            votes
        
        
            8
            answers
        
        
            81k
            views
        
    Change a UIButton's text (padding) programmatically in Swift
                Still learning Swift and don't know Objective-C. I saw that in order to changing a button's text programmatically requires the use of titleEdgeInsets but I am not really sure how to use it.
I would ...
            
        
       
    
            69
            votes
        
        
            8
            answers
        
        
            104k
            views
        
    How to programmatically add a UISegmentedControl to a container view
                How would I define the frame for a UISegmentedControl? 
I would like the segmented control to appear at the bottom of a container view i.e UIView.
            
        
       
    
            69
            votes
        
        
            15
            answers
        
        
            63k
            views
        
    How to convert UIColor to HEX and display in NSLog
                I have checked several links on how to convert UIColor codes to HEX however I am not sure on how to  call to the method to display them in NSLog. I haven't got the reputation to comment so posting as ...
            
        
       
    
            67
            votes
        
        
            14
            answers
        
        
            146k
            views
        
    Open PDF file using swift
                How can I add a PDF file for an app , where you click on a button to view the file & when you're done you get back to screen you were at?
            
        
       
    
            67
            votes
        
        
            10
            answers
        
        
            35k
            views
        
    Front facing camera in UIImagePickerController
                I am developing the front facing camera app in iPad2 by using the UIImagePickerController.
When I capture the image it's shows as flipped from left to right.
How do I correct this?
if ([...
            
        
       
    
            66
            votes
        
        
            9
            answers
        
        
            53k
            views
        
    Remove Specific Array Element, Equal to String - Swift
                Is there no easy way to remove a specific element from an array, if it is equal to a given string? The workarounds are to find the index of the element of the array you wish to remove, and then ...
            
        
       
    
            65
            votes
        
        
            21
            answers
        
        
            144k
            views
        
    Email & Phone Validation in Swift
                i am using the following code for phone number validation. But i am getting the following error. I cant able to proceed further. Help us to take it forward.
class PhoneNumberValidation: Validation {
 ...
            
        
       
    
            64
            votes
        
        
            4
            answers
        
        
            74k
            views
        
    Change 'Return' button function to 'Done' in swift in UITextView
                I would like to get rid of the "return" function of the keyboard while the user is typing, so there are no new lines, so instead I would like the 'return' key to function as 'Done' so it would hide ...
            
        
       
    
            63
            votes
        
        
            8
            answers
        
        
            35k
            views
        
    Swift UIAlertController -> ActionSheet iPad iOS8 Crashes
                currently i'm running into big trouble with my ActionSheet. On iPhone it works great, but on iPad it only crashes
I create a new project with only one button
import UIKit
extension ViewController : ...
            
        
       
    
            63
            votes
        
        
            12
            answers
        
        
            154k
            views
        
    Change button background color using swift language
                I am new to the swift language. Can someone tell me how to change the background color of a button using the swift language?
            
        
       
    
            57
            votes
        
        
            12
            answers
        
        
            37k
            views
        
    Show iPhone cut copy paste menu on UILabel
                Can we enable the cut copy paste menu for a UILabel as it is for a UITextField?
If not, and I need to convert my UILabel to UITextField, how can I enable the cut copy paste menu and not allow the ...
            
        
       
    
            56
            votes
        
        
            10
            answers
        
        
            52k
            views
        
    Creating thumbnail from local video in swift
                How to create thumbnail in swift from a local video file ? 
For example if the video file path is located here :
file:///Users/Dev/Library/Developer/CoreSimulator/Devices/F33222DF-D8F0-448B-A127-...
            
        
       
    
            55
            votes
        
        
            15
            answers
        
        
            47k
            views
        
    How to get 1 hour ago from a date in iOS swift?
                I have been researching, but I couldnt find exact solution for my problem. I have been trying to get 1 hour ago from a date. How can I achieve this in swift?
            
        
       
    
            55
            votes
        
        
            7
            answers
        
        
            57k
            views
        
    Detect iOS app entering background
                I'm working on a game for iOS coded in Swift. I've tried to find a way to detect when the app enters background mode or is interrupted for other reasons, for example a phone call but can't find ...