All Questions

Tagged with
Filter by
Sorted by
Tagged with
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,...
The Mach System's user avatar
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.
Berry Blue's user avatar
  • 15.8k
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. ...
Awais Hussain's user avatar
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');
code_cookies's user avatar
  • 3,990
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 ...
George's user avatar
  • 3,690
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 { ...
Jay's user avatar
  • 9,514
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.
Niko Adrianus Yuwono's user avatar
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 ...
Shlomi Schwartz's user avatar
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?
Stefan's user avatar
  • 28.9k
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 ...
Zohaib's user avatar
  • 2,855
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?
harsh_017's user avatar
  • 1,751
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 ...
Jovan's user avatar
  • 2,660
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 ...
Peter Pik's user avatar
  • 11.1k
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 ...
ShizukaNaHaji's user avatar
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....
Peter Pik's user avatar
  • 11.1k
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 ...
Nico Gutraich's user avatar
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-...
Ralph's user avatar
  • 2,085
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 ...
zeeple's user avatar
  • 5,579
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: ...
Vincent's user avatar
  • 1,645
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 ...
Ethan Marcus's user avatar
  • 1,296
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....
Hasan Nizamani's user avatar
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: ...
wolverine's user avatar
  • 2,987
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
Nik's user avatar
  • 1,547
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 ...
razibdeb's user avatar
  • 1,221
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 ...
William George's user avatar
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 ...
user avatar
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 ...
Vlad Z.'s user avatar
  • 3,421
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 ...
linus_hologram's user avatar
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. ...
johncorser's user avatar
  • 9,492
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, ...
kag359six's user avatar
  • 2,013
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?
Florik's user avatar
  • 1,260
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....
Joan Cardona's user avatar
  • 3,531
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 ...
Rubens Neto's user avatar
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 ...
code Horizons's user avatar
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 ...
patrikbelis's user avatar
  • 1,360
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];
Sharief's user avatar
  • 1,477
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 ...
KellysOnTop23's user avatar
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.
Alede's user avatar
  • 691
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 ...
App Dev Guy's user avatar
  • 5,486
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?
user3706773's user avatar
  • 3,019
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 ([...
dineshprasanna's user avatar
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 ...
TimWhiting's user avatar
  • 2,445
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 { ...
Saikumar's user avatar
  • 887
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 ...
Bruno Recillas's user avatar
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 : ...
Fabian Boulegue's user avatar
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?
kalim sayyad's user avatar
  • 1,076
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 ...
user avatar
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-...
Ralph's user avatar
  • 2,085
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?
saksut's user avatar
  • 673
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 ...
Johannes Flood's user avatar

1
2 3 4 5
200