OC 언어 day08-09 가변 사전 NSMutable Dictionary

3364 단어
pragma mark NSMutableDictionary
pragmamark 개념
/**

   : 《                             》
 
 NSMutableDictionary
 @" ":@" "
 @"lyh":@"name"
 //        (name)        (lyh)
 
 1.   (dictionary)
 
 2.   (setObject:  forKey: )
          (setValuesForKeysWithDictionary:  )
 
 3.   (objectForKey: )
        dict[@" "];
 
 4.  
         (removeObjectForKey)
         (removeObjectsForKeys)
 
 5.   (setObject:  forKey: ) //      key      
 
 ⚠️    
1.     @{}          
2.         ,   key    
         ,       key,     key          
          ,      
 
 #pragma mark   (NSDictionary)   (NSArray)    
 NSArray     
 NSDictionary     
 
 NSArray          
 NSDictionary    key    
 
#pragma mark        
 array
   
 @[@"lyh",@"lys"]; (           )
   
 id a = array[1];
   
 array[1] = @"lyh";
 
 dict
   
 @{@"name":@"lyh",@"age":@"22"};
   
 id a = dict[@"name"];
   
 dict[@"name"] = @"lyh";

 */

pragmamark 코드
#import 
#pragma mark  

#pragma mark main  
int main(int argc, const char * argv[])
{
#pragma mark NSMutableDictionary
    
#warning 1.  
    NSMutableDictionary *dictM = [NSMutableDictionary dictionary];
    NSLog(@"dic %@",dictM);
#warning 2.    
    [dictM setObject:@"lyh" forKey:@"name"];
    NSLog(@"dic %@",dictM);
    //     
    [dictM setValuesForKeysWithDictionary:@{@"age":@"20",@"height":@"1.71"}];
    NSLog(@"dic %@",dictM);
    
#warning 3.    
//    NSLog(@"dic %@",[dictM objectForKey:@"name"]);
    NSLog(@"dic %@",dictM[@"name"]);

    
#warning 4.    
    //     
    [dictM removeObjectForKey:@"name"];
    NSLog(@"dic %@",dictM);
    //     
//    [dictM removeObjectsForKeys:@[@"age",@"height"]];
//    NSLog(@"dic %@",dictM);


#warning 5.    
    //     setObject       key  ,         
    
    [dictM setObject:@"180" forKey:@"age"];
    NSLog(@"dic %@",dictM);
    

#warning ⚠️   
    // 1.     @{}          
//    NSMutableDictionary *dictM2 = @{@"name":@"lyh"};
//    [dictM2 setObject:@"20" forKey:@"age"];
    
    // 2.         ,   key    
    //          ,       key,     key          
    //           ,      

    NSDictionary *dictM3 = @{@"name":@"lyh",@"name":@"lys"};
    NSLog(@"dictM3 %@",dictM3);

    
    //       
    NSMutableDictionary *dictM4 = [NSMutableDictionary dictionaryWithObjects:@[@"lyh",@"lys"] forKeys:@[@"name",@"name"]];
    NSLog(@"dictM4 %@",dictM4);

    
#pragma mark   (NSDictionary)   (NSArray)    
    /**
     NSArray      
     NSDictionary     
     
     NSArray          
     NSDictionary    key    
     
     */
#pragma mark        
    /**
     array 
       
     @[@"lyh",@"lys"]; (           )
       
     id a = array[1];
       
     array[1] = @"lyh";
     
     dict
       
     @{@"name":@"lyh",@"age":@"22"};
       
     id a = dict[@"name"];
       
     dict[@"name"] = @"lyh";
     */
    return 0;
}


좋은 웹페이지 즐겨찾기