외규장각 도서 환수 모금 캠페인

'2014/05'에 해당되는 글 2건

  1. 2014.05.23 연결된 SSID 알아오기
  2. 2014.05.07 Core data로 sqlite 만들때 사용하는 소스
'Reachability.h',
'Reachability.m' 
파일을 인터넷에 찾아 참고 하시고 참고하시고

>>> SSID -> 아래 코드 참고하세요.

    NSArray * ifs = (__bridge_transfer id)CNCopySupportedInterfaces();
    
    for (NSString * item in ifs)
    {
        NSDictionary * info = (__bridge_transfer id)CNCopyCurrentNetworkInfo((__bridge CFStringRef)item);
        
        // kCNNetworkInfoKeySSID
        // kCNNetworkInfoKeyBSSID
        // kCNNetworkInfoKeySSIDData
        NSString * SSID = info[(NSString *)kCNNetworkInfoKeySSID];
       NSLog(@"SSID : %@", SSID);
    }


Posted by 닉네임영역
,

static NSManagedObjectModel *managedObjectModel()

{

    static NSManagedObjectModel *model = nil;

    if (model != nil) {

        return model;

    }

    

    NSString *path = @"CoreDataTutorial";

    path = [path stringByDeletingPathExtension];

    NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"coredatatest" withExtension:@"mom"];

    

    model = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];

    

    return model;

}


static NSManagedObjectContext *managedObjectContext()

{

    static NSManagedObjectContext *context = nil;

    if (context != nil) {

        return context;

    }


    @autoreleasepool {

        context = [[NSManagedObjectContext alloc] init];

        

        NSPersistentStoreCoordinator *coordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:managedObjectModel()];

        [context setPersistentStoreCoordinator:coordinator];

        

        NSString *STORE_TYPE = NSSQLiteStoreType;

        

        NSString *path = @"coredatatest";

        NSURL *url = [NSURL fileURLWithPath:[path stringByAppendingPathExtension:@"sqlite"]];

        

        NSError *error;

        NSPersistentStore *newStore = [coordinator addPersistentStoreWithType:STORE_TYPE configuration:nil URL:url options:nil error:&error];

        

        if (newStore == nil) {

            NSLog(@"Store Configuration Failure %@", ([error localizedDescription] != nil) ? [error localizedDescription] : @"Unknown Error");

        }

    }

    return context;

}


int main(int argc, const char * argv[])

{


    @autoreleasepool {

        // Create the managed object context

        NSManagedObjectContext *context = managedObjectContext();

        

        // Custom code here...

        // Save the managed object context

        NSError *error = nil;

        if (![context save:&error]) {

            NSLog(@"Error while saving %@", ([error localizedDescription] != nil) ? [error localizedDescription] : @"Unknown Error");

            exit(1);

        }

        

        NSString *dataPath = [[NSBundle mainBundle] pathForResource:@"Banks" ofType:@"json"];

        NSArray *Banks = [NSJSONSerialization JSONObjectWithData:[NSData dataWithContentsOfFile:dataPath] options:kNilOptions error:&error];

        NSLog(@"Imported Banks : %@", Banks);

        

        [Banks enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {

            FailedBankInfo *failedBankInfo = [NSEntityDescription insertNewObjectForEntityForName:@"FailedBankInfo" inManagedObjectContext:context];

            failedBankInfo.name = [obj objectForKey:@"name"];

            failedBankInfo.city = [obj objectForKey:@"city"];

            failedBankInfo.state = [obj objectForKey:@"state"];

            

            FailedBankDetails *failedBankDetails = [NSEntityDescription insertNewObjectForEntityForName:@"FailedBankDetails" inManagedObjectContext:context];

            failedBankDetails.closeDate = [NSDate dateWithString:[obj objectForKey:@"closeDate"]];

            failedBankDetails.updateDate = [NSDate date];

            failedBankDetails.zip = [obj objectForKey:@"zip"];

            

            failedBankDetails.info = failedBankInfo;

            failedBankInfo.details = failedBankDetails;

            

            NSError *error = nil;

            if (![context save:&error]) {

                NSLog(@"Whoops, couldn't save: %@", [error localizedDescription]);

            }

        }];

        // Test listing all FailedBankInfos from the store

        NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];

        NSEntityDescription *entity = [NSEntityDescription entityForName:@"FailedBankInfo" inManagedObjectContext:context];

        [fetchRequest setEntity:entity];

        

        NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest error:&error];

        

        for (FailedBankInfo *info in fetchedObjects) {

            NSLog(@"Name: %@", info.name);

            FailedBankDetails *details = info.details;

            NSLog(@"Zip: %@", details.zip);

        }

    }

    return 0;

}


참조 : http://www.raywenderlich.com

Posted by 닉네임영역
,


사랑합니다. 편안히 잠드소서