Found 208 Articles for IOS

How add 1 day to Date in swift?

Rishi Rathor
Updated on 30-Jul-2019 22:30:24

10K+ Views

To 1 day to a date in swift we need to create a date first. Once that date is created we have to add specific days to it. In this example we’ll see how we can achieve the same.Let’s create a date first, let it be today, let today = Date()Now to modify this date we’ll use the add function with negative value, let modifiedDate = Calendar.current.date(byAdding: .day, value: 1, to: today)!Now to see the difference between both the dates, let’s add print statement for both of these. Our complete code should now look like this.let today = Date() print(today) ... Read More

How to download a video using a URL and save it in an photo album using Swift?

Jennifer Nicholas
Updated on 29-Jun-2020 14:07:25

2K+ Views

To download a video from a URL in swift we need to perform a few steps while keeping a few things in mind.Points to be noted here are, We’ll be making use of internet to download video, hence we need to allow permissions for App transport security in our Info.plistWe’ll need to save the downloaded video to Photos app, hence photos permission is required.Video should always be downloaded in background as it may prevent us from using the app if downloaded on foreground.Now, we’ll use the below code to save a video from a random link in our Device. You’ll ... Read More

How to Add Live Camera Preview to UIView in Swift?

Anvi Jain
Updated on 30-Jul-2019 22:30:24

633 Views

To add a live camera preview to our default UIView in swift we can either use AVFoundation framework of iOS SDK or native UIImagePickerController(). In this example we’ll be using ImagePicker as our aim is to present camera preview on the UIView and Imagepicker is suitable for that task. AVFoundation can be used when we need a lot of customization on our camera or different types of custom actions.To show a camera preview on the UIView we need to perform the following steps.Create a UIImagePickerController object.Conform our class to UIImagePickerControllerDelegate and UINavigationControllerDelegate.Assign delegates to the object we created in step ... Read More

What is embedded bitcode and what does ENABLE_BITCODE do in xcode?

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:24

317 Views

Bitcode – Bitcode is an intermediate reperesentation of how the code looks. This code can not be used by us or can’t be installed on a device. When we upload our application to the app store It is uploaded as an bitcode and later converted to app binary by itunes/Apple.When the Intermediate code is created an uploaded to the App store or run on the device, a program called LLMV takes over the control and converts the Intermediate code to a Binary file which is x86 32Bit or x86 64 bit for the simulator and ARM for the actual iOS handheld ... Read More

What is "Processing Symbol Files" message in Xcode?

Rishi Rathor
Updated on 30-Jul-2019 22:30:24

177 Views

Processing symbol files is a message displayed on xcode when we create a project’s build. When this message appears, in background Xcode downloads files and symbol files for specific device and a specific processor on which build shall be installed.The symbol files contains debug symbols which are used to debug on specific processor and iOS version and when some crash or error occurs, those symbols are used to create crash reports. Once processing symbols is done a new folder with device symbols is created in the library, usually under “~/Library/Developer/Xcode/iOS DeviceSupport/ “.Sometimes our system might get stuck on this step ... Read More

How to get the current version of my iOS project in code?

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:24

152 Views

When we build an iOS application, by default it get a version 1.0 and build 0. Whenever we upload a new build to the app store, we need to change the version number. We can update the build number for testing builds. The version and build number are stored in the info.plist file in our project.Sometimes we might need to access the build or the version number in our application to perform some custom action.To get the version number we can use the following code and assign it to a variable or constant.Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as! StringTo get the build number ... Read More

Detect current device with UIUserInterfaceIdiom in Swift

Anvi Jain
Updated on 30-Jul-2019 22:30:24

2K+ Views

To detect current device with iOS/Swift we can use UserInterfaceIdiom. It is an enum in swift, which tells which device is being used.The interface idiom provides multiple values in it’s enum which are.case unspecified @available(iOS 3.2, *) case phone // iPhone and iPod touch style UI @available(iOS 3.2, *) case pad // iPad style UI @available(iOS 9.0, *) case tv // Apple TV style UI @available(iOS 9.0, *) case carPlay // CarPlay style UIIn swift interfaceIdiom can be used in the following way:print(UIDevice.current.userInterfaceIdiom) if UIDevice.current.userInterfaceIdiom == .phone { print("running on iPhone") }When we run the above code ... Read More

How to navigate from one view controller to another in iOS?

Vrundesha Joshi
Updated on 29-Jun-2020 14:02:43

5K+ Views

To navigate from one view Controller to another view Controller in iOS, we need to use Navigation controller. Navigation controller manages a stack of View controller when we go from one view to another view.Navigation from one view controller to another view controller can be done like mentioned below.Step 1 − Create a View controller object.let vc = self.storyboard?.instantiateViewController(withIdentifier: "VC2ViewController") as! VC2ViewControllerIn this step we initialize an object of the type of our another view controller, to which we want to navigate. The identifier variable should be same as the identifier of our second view controller.Step 2 − Navigating to ... Read More

Check if string contains special characters in Swift

Anvi Jain
Updated on 29-Jun-2020 14:04:33

3K+ Views

To check if a string contains a special character in swift we can use conditionals like if else or switch but that would need a lot of conditions to be executed, making programming as well as execution time consuming. So in this example we’ll see how to do the same task with regular expressions and another method that swift provides to check if some character exists in a character set.Method 1 − Using regular expressionLet’s create an extension of String and add the following code into thatextension String {    var containsSpecialCharacter: Bool {       let regex = ... Read More

Email & Phone Validation in Swift

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:24

1K+ Views

To validate email and phone in swift language we can use multiple conditional statements like if conditions, but that’s a long process and may contain 50-100s of if statements to validate email.So instead of conditionals we’ll use Regular expression. Swift provides NSPredicates which we can use to evaluate a regular expression and test them.Let’s see how we can use regular expressions to do the same.We’ll create a function which we can use as extension of String class or UIViewController to use through out the project.Add the following code to any class in your Project, or create a separate swift class ... Read More

Advertisements