Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to get Common Values from two Arrays

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 227
    Comment on it

    This is a simple method to compare two arrays and get all the common objects from these arrays.

    Take two arrays(say firstArray & secondArray)

    NSMutableSet* arraySet1 = [NSMutableSet setWithArray:firstArray];  //create NSMutableSet for firstArray
    NSMutableSet* arraySet2 = [NSMutableSet setWithArray:secondArray];  //create NSMutableSet for secondArray
    
    [arraySet1 intersectSet:arraySet2];     //this will assign all common(intersecting) values of two sets to arrayset1
    
    
    NSArray* arrayResult = [arraySet1 allObjects]; // assign all the object of arraySet1 to arrayResult
    

    For Example:

    firstArray=(
        abc,
        pqr
    )
    
    secondArray=(
        abc,
        pqr
    )
    
    arrayResult is=(
        pqr
    )
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: