Sample code for 30+ languages & platforms
Objective-C

Find a ZIP Entry by EntryID Using EntryById

See more Zip Examples

This example demonstrates how to use the EntryById method to retrieve a ZIP entry using its unique EntryID.

Each ZipEntry object has an EntryID property that uniquely identifies the entry within the currently open ZIP object.

This is useful when:

  • An application stores EntryID values for later use
  • ZIP entries need to be retrieved without searching by filename
  • Multiple entries may have similar names or paths

The example:

  • Opens a ZIP archive
  • Retrieves an entry using EntryAt
  • Saves the entry's EntryID
  • Uses EntryById to retrieve the same entry later

Chilkat Objective-C Downloads

Objective-C
#import <CkoZip.h>
#import <CkoZipEntry.h>

BOOL success = NO;

//  Open an existing ZIP archive.
CkoZip *zip = [[CkoZip alloc] init];

success = [zip OpenZip: @"example.zip"];
if (success == NO) {
    NSLog(@"%@",zip.LastErrorText);
    return;
}

//  Retrieve the first entry in the ZIP archive.
CkoZipEntry *entry = [[CkoZipEntry alloc] init];

success = [zip EntryAt: [NSNumber numberWithInt: 0] entry: entry];
if (success == NO) {
    NSLog(@"%@",zip.LastErrorText);
    return;
}

NSLog(@"%@",@"Original entry:");
NSLog(@"%@%@",@"  FileName: ",entry.FileName);
NSLog(@"%@%d",@"  EntryID: ",[entry.EntryID intValue]);
NSLog(@"%@",@"");

//  Save the EntryID for later use.
int entryId = [entry.EntryID intValue];

//  Create another ZipEntry object.
CkoZipEntry *entry2 = [[CkoZipEntry alloc] init];

//  Retrieve the same entry using EntryById.
success = [zip EntryById: [NSNumber numberWithInt: entryId] entry: entry2];
if (success == NO) {
    NSLog(@"%@",zip.LastErrorText);
    return;
}

NSLog(@"%@",@"Entry retrieved by EntryID:");
NSLog(@"%@%@",@"  FileName: ",entry2.FileName);
NSLog(@"%@%d",@"  EntryID: ",[entry2.EntryID intValue]);
NSLog(@"%@",@"");

//  The filenames and EntryID values should match.
[zip CloseZip];

NSLog(@"%@",@"Done.");