Wednesday 7 February 2018

Find the index of object in array in swift 4



userList is array of objects [User]
userID is identity of object, which is use for find index. 



let userID = "1"

 let tempIndex = userList.index(where: { (user: User) -> Bool in
            user.userID == userID

        })


tempIndex is position of object in userList array. 

You may access the object like bellow
let objUser = userList[tempIndex]



Happy coding! 



Bhavesh Kumbhani
IOS Software Professional 

follow on

Filter array of objects in swift 4


userList is array of objects [User]
userID is identity of object, which is use for filter 

See bellow method, In this method filtered the userList array by userID. get all users which are having same userID.



func filtered(userID: String) -> [User] {
        if userList.count > 0{
            let filteredArray = userList.filter { (obj) -> Bool in
                obj.userID == userID
            }
            return filteredArray
        }
        return []
    }
 







Happy coding! 



Bhavesh Kumbhani
IOS Software Professional 

follow on

Unbalanced calls to begin/end appearance transitions for...

This type of error logs print when your presented view-controller is diapering while you trying to present another controller like..
  • UIAlertView
  • UIAlertController
  • Present Model View Controller...etc.


Solution is within a second.

Keep remember above all type of controller present after the disappear presented controller successful. 

  1. Set disappear delegate, in this callback you may present above types of controllers 
  2. Add 0.5 second timer to present above types of controllers 



Happy coding! 



Bhavesh Kumbhani
IOS Software Professional 

follow on
Facebook
LinkedIn