• Skip to main content
  • Skip to primary sidebar

Ravi Shankar

Tweaking Apps

  • Swift
  • Tech Tips

iPad

Reset and Erase content on iPad

August 25, 2015 By Ravi Shankar Leave a Comment

In this tutorial we will be covering about the Reset and Erase content feature available on iPad 2. Press the Home button on your iPad and tap the settings icon available on the Home screen.

In the Settings page, navigate to Reset option. This would display the following list of options.

If you are planning to sell your iPad then don’t forget to remove all your personal photos, documents and other files from your iPad. You can do this by tapping on the Erase All Content and Settings option.

And If you are facing problems with your iPad then probably you can the Reset All Settings option to see if that resolves the problem.

The Reset feature also provides users with the option for resetting only the Network Settings or Keyboard Dictionary or Home Screen Layout or Location Warnings. Depending upon the need you can choose these options. For example if you have problems in reconnecting to an already established network then you can reset the network settings and try again connecting with the network.

 

Filed Under: Apple, iPad Tagged With: Erase, Home Screen, iPad 2, Keyboard, Layout, network, Remove, reset, Settings

How to hide or unhide photos in iPhone or iPad

June 26, 2015 By Ravi Shankar Leave a Comment

iPhone and iPad users can temporarily hide photos from the albums. This is quite useful when you do not want other users to inadvertently view private photos from Albums. Listed below are the steps to hide and unhide photos from Albums in iPhone or iPad

Step 1: Navigate to Photos on your device.

Step 2: Navigate to Albums and select and long press the photos that you want to hide.

Step 3: Now select hide from the menu option.

And to unhide the photos, navigate to Albums and select Hidden. This shoud list you the hidden photos. Again long press the photo and select unhide option.

Filed Under: iPad, iPhone Tagged With: hide photos, unhide photos

Prevent installing or uninstalling apps on iPad or iPhone

June 25, 2015 By Ravi Shankar 1 Comment

Prevent

In this tutorial we will be see the steps required to prevent any users from installing or uninstalling any apps on iPad or iPhone. This is a useful tip if you are sharing your iPad with other people especially kids and do not want them accidentally uninstall and install any Apps.

To prevent users from removing or installing apps, press the menu button on your iPad and tap the Settings icon.

image

In the General Settings, tap the Restriction option and enable restrictions by setting a passcode. In the Restrictions screen, navigate to Installing Apps and Deleting Apps Option.

image

By tapping them and changing the value to Off would prevent users from removing or installing any apps on iPhone or iPad.

Filed Under: Apple, iPad Tagged With: apps, Install, iPad 2, prevent, Remove, Uninstall

Memory management in Swift

June 7, 2015 By Ravi Shankar Leave a Comment

Memory management in Swift is done by Automatic Reference Counting or ARC. Whenever a variables holds an instance of a object the memory count for that object increases by 1. And when variable become out of scope or set to nil, the memory count decreases 1.

[code language=”swift”]class Teacher {
var name: String?
var course: String?

init (name: String, course: String) {
self.name = name
self.course = course
println("Reference count increased by 1")
}

deinit{
println("Reference count decreased by 1")
}
}

let teacher1 = Teacher(name: "Ravi", course: "Swift")

func createTeacher() {
let teacher2 = Teacher(name: "John", course: "Java")
}

createTeacher()[/code]

 

In the above example, we are creating two instances of Teacher class and storing it in variables teacher1 and teacher2. Since teacher2 variable is created within the function, it becomes out of scope after the function call. You should be able to observe the two init messages and one deinit (teacher2) message in console log. This should give you some idea on how reference counting works in Swift.

Increasing and decreasing of reference count are automatically handled by ARC but problem occurs when we have a strong reference cycle. A strong reference cycle refers to cyclic relationship between the objects.

[code language=”swift”]class Teacher {
var name:String?
var course:String?
var student: Student?

init(name: String, course:String) {
self.name = name
self.course = course

println("Reference count of Teacher increases by 1")
}

deinit {
println("Reference count of Teacher decreases by 1")
}
}

class Student {
var name:String?
var mentor: Teacher?

init(name: String, course:String) {
self.name = name

println("Reference count of Student increases by 1")
}

deinit {
println("Reference count of Student decreases by 1")
}
}

func createInstance() {
let teacher = Teacher(name: "Jason", course: "Swift")
let student = Student(name: "Adam", course: "Swift")
teacher.student = student
student.mentor = teacher
}

createInstance()[/code]

In the above code snippet, Teacher and Sudent classes have a strong reference cycle and both student and teacher instances remain in memory even after the end of function call. A strong reference cycle can be avoided by declaring any one of the instance as weak or unowned

[code language=”swift”]weak var student: Student?
[/code]

You can also unown the reference when you know the reference cannot be nil

[code language=”swift”]unowned var mentor: Teacher[/code]

Download playground file from gitHub (Memory Management)

Filed Under: ios, iPad, iPhone, Xcode Tagged With: ARC, iPad, Memory Management, Xcode

SplitViewController example in Swift

April 1, 2015 By Ravi Shankar 4 Comments

This is a beginners tutorial on SplitViewController using Interface builder with programming language as Swift. There are also some good articles available on SplitViewController, check them out as well – nhipster and whoisryannystrom.

Create a new Single View Application.

201503290525.jpg

Choose Language option as Swift and provide a product name.

201504011302.jpg

Navigate to Main.Storyboard and select default View Controller and delete it.

201504011304.jpg

Add a Split View Controller from the object library to the interface builder.

201504011305.jpg

Using Attributes Inspector make Split View Controller as the Initial View Controller

201504011307.jpg
Select View Controller in the Interface builder then click Editor menu and select Navigation Controller under Embed In menu option.

201504011308.jpg

Rename ViewController.swift to DetailViewController.swift and change the class name as well.

201504011317.jpg

Navigate to Interface builder and set the class name for ViewController scene to DetailViewController

201504011321.jpg

Now Control + drag and drop TablevIew Prototype cell to NavigationController (DetailViewController) and select segue as show detail. Also set the identifier for the Storyboard Segue as “ShowDetailIdentifier“

201504011323.jpg

201504011326.jpg

Navigate to RootViewController (TableViewController) Provide the Identifier as CellIdentifier for the Prototype Cells.

201504011325.jpg

Right click on the Project Navigator, select New File and Choose the template as Cocoa Touch Class

201504011331.jpg

In the next screen, select subclass as UIViewController and provide a name as SplitViewController

201504011332.jpg

After creating the file, edit SplitViewController subclass to UISplitViewController. Then add the following line to the viewDidLoad method.

  splitViewController?.preferredDisplayMode = .PrimaryOverlay

The above line is to keep the PrimaryViewController (TableViewController) on top of SecondaryViewController (DetailViewController). You can change this behaviour by setting other types, check the documentation for more details.

201504011407.jpg

Now add the PrimaryViewController (TableViewController) by right clicking and selecting New File. Select Cocoa Touch class and in the subclass field pick UITableViewController. Provide the the name for the TableViewController ListTableViewController.

201504011409.jpg

Set the class name for the RootViewController (TableViewController) to the newly created class, ListTableViewController.

201504011424.jpg

Navigate to DetailViewController in the Interface builder, add a label and make it horizontally and vertically centred.

201504011524.jpg

Then add a new IBOutlet in DetailViewController and connect the Outlet to the label in interface builder.

  @IBOutlet var numberLabel:UILabel?

Also add property of type Int and the value for this property will be set during the segue transition.

var selectedIndex:Int = 1

Make changes to the viewDidLoad method, to set the value for the label and to add back button to the navigation bar.

override func viewDidLoad() {

super.viewDidLoad()

  

numberLabel?.text = “\(selectedIndex)“

  

// add back button to the navigation bar.

  

if splitViewController?.respondsToSelector(“displayModeButtonItem”) == true {

navigationItem.leftBarButtonItem = splitViewController?.displayModeButtonItem()

navigationItem.leftItemsSupplementBackButton = true

}

}

In the ListTableViewController, add the following code that sets the datasource.

  let names = [“One”,“Two”,“Three”,“Four”,“Five”,“Six”,“Seven”,“Eight”,“Nine”,“Ten”] (class level declaration)

  // MARK: – Table view data source

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {

return 1

}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

return names.count

}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

let cell = tableView.dequeueReusableCellWithIdentifier(“CellIdentifier”, forIndexPath: indexPath) as UITableViewCell

   cell.textLabel?.text = names[indexPath.row]

return cell

}

Then make changes to the prepareForSegue method to navigate to DetailViewController after setting the selectedIndex property

  override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

if (segue.identifier == “ShowDetailIdentifier”) {

var detail: DetailViewController

if let navigationController = segue.destinationViewController as? UINavigationController {

detail = navigationController.topViewController as DetailViewController

} else {

detail = segue.destinationViewController as DetailViewController

}

  

if let path = tableView.indexPathForSelectedRow() {

detail.selectedIndex = path.row + 1

}

}

}

201504011556.jpg

Download the source from here.

Filed Under: ios, iPad, iPhone, Programming, Xcode Tagged With: Demo, iPad, UISplitViewController, Xcode

How disable the sound for keyboard clicks in iPad

February 13, 2015 By Ravi Shankar Leave a Comment

The sound heard for keyboard clicks in iPad can be disabled using the settings. To disable the sound

  • Tap the settings icon on the iPad home screen.
  • In the settings screen, navigate Sound settings.

image

And this would Turn off the sounds for the Keyboard clicks in iPad 2

image

Filed Under: iPad Tagged With: Disable, iPad 2, keyboard clicks, Sound, Turn Off

How to check the OS version of your iPad

January 22, 2015 By Ravi Shankar Leave a Comment

iPad allows users to check the version of OS installed using the settings menu. This would be useful when you are troubleshooting some problems in your iPad. To check the OS version

1. In the home screen, tap the settings menu.

2. In the settings screen, navigate to General settings.

20110422-122656.jpg

3. In the General Settings screen, tap the about the option and then navigate to version. This would display the version of OS installed on your iPad.

20110422-122815.jpg

20110422-123538.jpg

Filed Under: Apple, iPad Tagged With: Installed, iPad, iPad 2, OS, Version

Enum in Swift

January 13, 2015 By Ravi Shankar Leave a Comment

Enum group of related values to a single data type. Swift enum has lot of new features compared to its predecessor Objective-C. Let us see this with an example enum type for all Months in a year.

enum Months {

case January, February, March, April, May, June, July, August, September, October, November, December

}

 

enum Month {

case January, February, March, April, May, June, July, August, September, October, November, December

}

Now you can define a variable or a constant of type month as shown below.

let currentMonth = Month.May

And variable or constant is declared with the data type then you can use the short form.

let currentMonth:Month = .May

 

Enum with Raw Value

Enum in Swift can be assigned a RawValue when declaring and the value can be of any data type. Let us day you want to specify the String value of each Month

enum Month: String {

case January = “January”, February = “February”, March = “March”, April = “April”, May = “May”, June = “June”, July = “July”, August = “August”, September = “September”, October = “October”, November = “November”, December = “December”

}

The RawValue can be printed by accessing .rawValue on the enum variable or constant.

let currentMonth:Month = .May

currentMonth.rawValue

Enum with Associated Value

 

Same like RawValue, enum can also have associated value and of data type.

enum Month {

case January(String), February(String), March(String), April(String), May(String), June(String), July(String), August(String), September(String), October(String), November(String), December(String)

}

let currentMonth:Month = .May(“Summer Vacation”)

switch currentMonth {

case .May(let message):

println(message)

default:

println(“No Values”)

}

In the above example, Month enum values are declared with an associated value of data type String. And while assign the enum value the associated value is also provided to the currentMonth constant. Using the switch the associated value is retrieved.

Enum can have member function

 

Enum in Swift can also have member function. In the below example code, we have declared the Month enum with rawValue of type Int. Now add a member function to calculate the number of months left from the currently assigned value.

enum Month: Int {

case January = 1, February, March, April, May, June, July, August, September, October, November, December

func monthsLeftForYearEnd() -> Int {

   return Month.December.rawValue – self.rawValue

}

}

let month: Month = .May

month.monthsLeftForYearEnd()

Constant month is assigned a enum value of .May and you can find out the number of months left for the year end by accessing the monthsLeftForYearEnd.

Enum and Initialiser

 

Swift’s enum can have initialiser too where you can set the default enum value or do some initial processing. If you add init function as shown below, the default enum value will be set to July.

enum Month: Int {

case January = 1, February, March, April, May, June, July, August, September, October, November, December

init() {

self = .July

}

func monthsLeftForYearEnd() -> Int {

return Month.December.rawValue – self.rawValue

}

}

let month = Month()

month.monthsLeftForYearEnd()

 

Filed Under: Apple, Develop, ios, iPad, iPhone, Programming Tagged With: Apple, Enum, Initializer, iPad, Member Function, RawValue

  1. Pages:
  2. 1
  3. 2
  4. 3
  5. »
Next Page »

Primary Sidebar

TwitterLinkedin

Recent Posts

  • How to block keywords in Jio broadband
  • How to disable opening an app automatically at login in Mac
  • How to set preferred Wifi network on Mac
  • Attribute Unavailable: Estimated section warning before iOS 11.0
  • How to recover Firefox password from Time Machine backup

Pages

  • About
  • Privacy Policy
  • Terms and Conditions

Copyright 2022 © rshankar.com

Terms and Conditions - Privacy Policy