Skip to content

Commit

Permalink
convert to literals + subscripting
Browse files Browse the repository at this point in the history
  • Loading branch information
steipete committed Jun 13, 2012
1 parent c8e01d2 commit 8789b2a
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 43 deletions.
6 changes: 3 additions & 3 deletions Examples/PSPDFKitExample/AppDelegate.m
Expand Up @@ -40,10 +40,10 @@ - (void)addCustomLocalization {
// prepare the dictionary structure (here, we only add en, which is the fallback)
NSMutableDictionary *localizationDict = [NSMutableDictionary dictionaryWithCapacity:1];
NSMutableDictionary *enLocalizationDict = [NSMutableDictionary dictionaryWithCapacity:1];
[localizationDict setObject:enLocalizationDict forKey:@"en"];
localizationDict[@"en"] = enLocalizationDict;

// add localization content
[enLocalizationDict setObject:@"Magazines" forKey:@"Documents"];
enLocalizationDict[@"Documents"] = @"Magazines";
PSPDFSetLocalizationDictionary(localizationDict);
}

Expand Down Expand Up @@ -90,7 +90,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
window_.rootViewController = navigationController_;
[window_ makeKeyAndVisible];

NSString *cacheFolder = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *cacheFolder = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)[0];
PSELog(@"CacheDir: %@", cacheFolder);

// set white status bar style when not on ipad
Expand Down
Expand Up @@ -93,7 +93,7 @@ - (AMBlockToken *)addObserverForKeyPath:(NSString *)keyPath onQueue:(NSOperation
[dict release];
}
AMObserverTrampoline *trampoline = [[AMObserverTrampoline alloc] initObservingObject:self keyPath:keyPath onQueue:queue task:task];
[dict setObject:trampoline forKey:token];
dict[token] = trampoline;
[trampoline release];
});
return token;
Expand All @@ -102,7 +102,7 @@ - (AMBlockToken *)addObserverForKeyPath:(NSString *)keyPath onQueue:(NSOperation
- (void)removeObserverWithBlockToken:(AMBlockToken *)token {
dispatch_sync(AMObserverMutationQueueCreatingIfNecessary(), ^{
NSMutableDictionary *observationDictionary = objc_getAssociatedObject(self, AMObserverMapKey);
AMObserverTrampoline *trampoline = [observationDictionary objectForKey:token];
AMObserverTrampoline *trampoline = observationDictionary[token];
if (!trampoline)
{
NSLog(@"[NSObject(AMBlockObservation) removeObserverWithBlockToken]: Ignoring attempt to remove non-existent observer on %@ for token %@.", self, token);
Expand Down
2 changes: 1 addition & 1 deletion Examples/PSPDFKitExample/PSActionSheet.m
Expand Up @@ -86,7 +86,7 @@ - (void)showFromRect:(CGRect)rect inView:(UIView *)view animated:(BOOL)animated
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
// Run the button's block
if (buttonIndex >= 0 && buttonIndex < [blocks_ count]) {
id obj = [blocks_ objectAtIndex:buttonIndex];
id obj = blocks_[buttonIndex];
if (![obj isEqual:[NSNull null]]) {
((void (^)())obj)();
}
Expand Down
2 changes: 1 addition & 1 deletion Examples/PSPDFKitExample/PSPDFDownload.m
Expand Up @@ -157,7 +157,7 @@ - (void)startDownload {
[pdfRequest startAsynchronous];

self.request = pdfRequest; // save request
[[PSPDFStoreManager sharedPSPDFStoreManager] addMagazinesToStore:[NSArray arrayWithObject:self.magazine]];
[[PSPDFStoreManager sharedPSPDFStoreManager] addMagazinesToStore:@[self.magazine]];
}

- (void)cancelDownload {
Expand Down
14 changes: 7 additions & 7 deletions Examples/PSPDFKitExample/PSPDFExampleViewController.m
Expand Up @@ -32,7 +32,7 @@ - (void)optionsButtonPressed:(id)sender {
PSPDFSettingsController *cacheSettingsController = [[PSPDFSettingsController alloc] init];
if (PSIsIpad()) {
self.popoverController = [[UIPopoverController alloc] initWithContentViewController:cacheSettingsController];
self.popoverController.passthroughViews = [NSArray arrayWithObject:self.navigationController.navigationBar];
self.popoverController.passthroughViews = @[self.navigationController.navigationBar];
[self.popoverController presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}else {
[self presentModalViewController:cacheSettingsController withCloseButton:YES animated:YES];
Expand Down Expand Up @@ -66,7 +66,7 @@ - (void)globalVarChanged {
self.rightBarButtonItems = rightBarButtonItems;

// define additional buttons with an action icon
self.additionalRightBarButtonItems = [NSArray arrayWithObjects:self.printButtonItem, self.openInButtonItem, self.emailButtonItem, nil];
self.additionalRightBarButtonItems = @[self.printButtonItem, self.openInButtonItem, self.emailButtonItem];

NSUInteger page = [self landscapePage:self.page];
self.pageMode = [PSPDFSettingsController pageMode];
Expand Down Expand Up @@ -100,10 +100,10 @@ - (id)initWithDocument:(PSPDFDocument *)document {

// 1.10 feature: replaces printEnabled, openInEnabled
if (PSIsIpad()) {
self.additionalRightBarButtonItems = [NSArray arrayWithObjects:self.openInButtonItem, self.printButtonItem, self.emailButtonItem, nil];
self.additionalRightBarButtonItems = @[self.openInButtonItem, self.printButtonItem, self.emailButtonItem];
}else {
self.rightBarButtonItems = [NSArray arrayWithObjects:self.searchButtonItem, self.viewModeButtonItem, nil];
self.additionalRightBarButtonItems = [NSArray arrayWithObjects:self.openInButtonItem, self.printButtonItem, self.emailButtonItem, self.outlineButtonItem, nil];
self.rightBarButtonItems = @[self.searchButtonItem, self.viewModeButtonItem];
self.additionalRightBarButtonItems = @[self.openInButtonItem, self.printButtonItem, self.emailButtonItem, self.outlineButtonItem];
}

// don't clip pages that have a high aspect ration variance. (for pageCurl, optional but useful check)
Expand All @@ -115,8 +115,8 @@ - (id)initWithDocument:(PSPDFDocument *)document {
UIBarButtonItem *closeButtonItem = [[UIBarButtonItem alloc] initWithTitle:closeTitle style:UIBarButtonItemStyleBordered target:self action:@selector(close:)];
PSPDFSettingsBarButtonItem *settingsButtomItem = [[PSPDFSettingsBarButtonItem alloc] initWithPDFViewController:self];

self.leftBarButtonItems = [NSArray arrayWithObjects:closeButtonItem, settingsButtomItem, nil];
self.barButtonItemsAlwaysEnabled = [NSArray arrayWithObject:closeButtonItem];
self.leftBarButtonItems = @[closeButtonItem, settingsButtomItem];
self.barButtonItemsAlwaysEnabled = @[closeButtonItem];

// restore viewState
if ([self.document isValid]) {
Expand Down
16 changes: 8 additions & 8 deletions Examples/PSPDFKitExample/PSPDFGridController.m
Expand Up @@ -243,7 +243,7 @@ - (void)viewDidLoad {
action:@selector(optionsButtonPressed)];

// only show the option button if we're at root (else we hide the back button)
if ([self.navigationController.viewControllers objectAtIndex:0] == self) {
if ((self.navigationController.viewControllers)[0] == self) {
self.navigationItem.leftBarButtonItem = optionButton;
}else {
// iOS5 supports easy additional buttons next to a native back button
Expand Down Expand Up @@ -428,9 +428,9 @@ - (PSPDFGridViewCell *)PSPDFGridView:(PSPDFGridView *)gridView cellForItemAtInde
}

if (self.magazineFolder) {
cell.magazine = (PSPDFMagazine *)[self.magazineFolder.magazines objectAtIndex:cellIndex];
cell.magazine = (PSPDFMagazine *)(self.magazineFolder.magazines)[cellIndex];
}else {
cell.magazineFolder = [[PSPDFStoreManager sharedPSPDFStoreManager].magazineFolders objectAtIndex:cellIndex];
cell.magazineFolder = ([PSPDFStoreManager sharedPSPDFStoreManager].magazineFolders)[cellIndex];
}

return cell;
Expand All @@ -442,7 +442,7 @@ - (BOOL)PSPDFGridView:(PSPDFGridView *)gridView canDeleteItemAtIndex:(NSInteger)
NSArray *fixedMagazines = [self.magazineFolder.magazines filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"isDeletable = NO || isAvailable = NO || isDownloading = YES"]];
canDelete = [fixedMagazines count] == 0;
}else {
PSPDFMagazine *magazine = [self.magazineFolder.magazines objectAtIndex:index];
PSPDFMagazine *magazine = (self.magazineFolder.magazines)[index];
canDelete = magazine.isAvailable && !magazine.isDownloading && magazine.isDeletable;
}
return canDelete;
Expand All @@ -454,9 +454,9 @@ - (void)PSPDFGridView:(PSPDFGridView *)gridView processDeleteActionForItemAtInde

if (self.magazineFolder) {
folder = self.magazineFolder;
magazine = [self.magazineFolder.magazines objectAtIndex:index];
magazine = (self.magazineFolder.magazines)[index];
}else {
folder = [[PSPDFStoreManager sharedPSPDFStoreManager].magazineFolders objectAtIndex:index];
folder = ([PSPDFStoreManager sharedPSPDFStoreManager].magazineFolders)[index];
magazine = [folder firstMagazine];
}

Expand Down Expand Up @@ -513,9 +513,9 @@ - (void)PSPDFGridView:(PSPDFGridView *)gridView didTapOnItemAtIndex:(NSInteger)g

if (self.magazineFolder) {
folder = self.magazineFolder;
magazine = [self.magazineFolder.magazines objectAtIndex:gridIndex];
magazine = (self.magazineFolder.magazines)[gridIndex];
}else {
folder = [[PSPDFStoreManager sharedPSPDFStoreManager].magazineFolders objectAtIndex:gridIndex];
folder = ([PSPDFStoreManager sharedPSPDFStoreManager].magazineFolders)[gridIndex];
magazine = [folder firstMagazine];
}

Expand Down
4 changes: 2 additions & 2 deletions Examples/PSPDFKitExample/PSPDFMagazineFolder.m
Expand Up @@ -79,7 +79,7 @@ - (BOOL)isSingleMagazine {
}

- (PSPDFMagazine *)firstMagazine {
PSPDFMagazine *firstMagazine = [self.magazines count] ? [self.magazines objectAtIndex:0] : nil;
PSPDFMagazine *firstMagazine = [self.magazines count] ? (self.magazines)[0] : nil;
return firstMagazine;
}

Expand All @@ -96,7 +96,7 @@ - (void)removeMagazine:(PSPDFMagazine *)magazine {
}

- (void)sortMagazines {
[magazines_ sortUsingDescriptors:[NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"uid" ascending:NO]]];
[magazines_ sortUsingDescriptors:@[[NSSortDescriptor sortDescriptorWithKey:@"uid" ascending:NO]]];
}

- (void)setMagazines:(NSArray *)magazines {
Expand Down
16 changes: 8 additions & 8 deletions Examples/PSPDFKitExample/PSPDFSettingsController.m
Expand Up @@ -49,12 +49,12 @@ - (id)initWithStyle:(UITableViewStyle)style {
self.title = _(@"Options");

content_ = [[NSArray alloc] initWithObjects:
[NSArray arrayWithObjects:_(@"No Disk Cache"), _(@"Thumbnails & near Pages"), _(@"Cache everything"), nil],
[NSArray arrayWithObjects:_(@"Horizontal (Magazine style)"), _(@"Vertical (like UIWebView)"), _(@"PageCurl (like iBooks, iOS5)"), nil],
[NSArray arrayWithObjects:_(@"Single Page"), _(@"Double Pages"), _(@"Automatic on Rotation"), nil],
[NSArray arrayWithObjects:_(@"Single First Page (Cover)"), _(@"No Cover Page"), nil],
[NSArray arrayWithObjects:_(@"Zoom small files"), _(@"Zoom to width"), _(@"Scrobblebar"), nil], // @"Paging Enabled"
[NSArray arrayWithObjects:_(@"Search"), _(@"Outline"), _(@"Annotations"), _(@"AspectRatio Equal"), _(@"Two Step Rendering"), nil],
@[_(@"No Disk Cache"), _(@"Thumbnails & near Pages"), _(@"Cache everything")],
@[_(@"Horizontal (Magazine style)"), _(@"Vertical (like UIWebView)"), _(@"PageCurl (like iBooks, iOS5)")],
@[_(@"Single Page"), _(@"Double Pages"), _(@"Automatic on Rotation")],
@[_(@"Single First Page (Cover)"), _(@"No Cover Page")],
@[_(@"Zoom small files"), _(@"Zoom to width"), _(@"Scrobblebar")], // @"Paging Enabled"
@[_(@"Search"), _(@"Outline"), _(@"Annotations"), _(@"AspectRatio Equal"), _(@"Two Step Rendering")],
nil];
}
return self;
Expand Down Expand Up @@ -180,7 +180,7 @@ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [[content_ objectAtIndex:section] count];
return [content_[section] count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
Expand All @@ -191,7 +191,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}

cell.textLabel.text = [[content_ objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
cell.textLabel.text = content_[indexPath.section][indexPath.row];
switch (indexPath.section) {
case 0:
cell.accessoryType = (indexPath.row == [PSPDFCache sharedPSPDFCache].strategy) ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;
Expand Down
6 changes: 3 additions & 3 deletions Examples/PSPDFKitExample/PSPDFShadowView.m
Expand Up @@ -52,9 +52,9 @@ - (CAGradientLayer *)shadowAsInverse:(BOOL)inverse {
UIColor *darkColor = [UIColor colorWithRed:0.f green:0.f blue:0.f alpha:inverse ? (SHADOW_INVERSE_HEIGHT / SHADOW_HEIGHT) * 0.5f : 0.5f];

if (inverse) {
newShadow.colors = [NSArray arrayWithObjects:(__bridge id)lightColor.CGColor, (__bridge id)darkColor.CGColor, nil];
newShadow.colors = @[(__bridge id)lightColor.CGColor, (__bridge id)darkColor.CGColor];
}else {
newShadow.colors = [NSArray arrayWithObjects:(__bridge id)darkColor.CGColor, (__bridge id)lightColor.CGColor, nil];
newShadow.colors = @[(__bridge id)darkColor.CGColor, (__bridge id)lightColor.CGColor];
}
return newShadow;
}
Expand All @@ -68,7 +68,7 @@ - (void)layoutSubviews {
originShadow_ = [self shadowAsInverse:NO];
[self.layer insertSublayer:originShadow_ atIndex:9999];
}
else if (![[self.layer.sublayers objectAtIndex:0] isEqual:originShadow_]) {
else if (![(self.layer.sublayers)[0] isEqual:originShadow_]) {
[self.layer insertSublayer:originShadow_ atIndex:9999];
}

Expand Down
16 changes: 8 additions & 8 deletions Examples/PSPDFKitExample/PSPDFStoreManager.m
Expand Up @@ -114,7 +114,7 @@ - (NSMutableArray *)searchForMagazineFolders {
}

NSMutableArray *foldersCopy = [folders mutableCopy];
PSPDFMagazineFolder *firstFolder = [foldersCopy objectAtIndex:0];
PSPDFMagazineFolder *firstFolder = foldersCopy[0];
[foldersCopy removeObject:firstFolder];
NSMutableArray *magazineArray = [firstFolder.magazines mutableCopy];

Expand Down Expand Up @@ -152,7 +152,7 @@ - (PSPDFMagazine *)magazineForUid:(NSString *)uid {
- (PSPDFMagazine *)magazineForFileName:(NSString *)fileName {
for (PSPDFMagazineFolder *folder in self.magazineFolders) {
for (PSPDFMagazine *magazine in folder.magazines) {
if ([magazine.files count] && [[magazine.files objectAtIndex:0] isEqualToString:fileName]) {
if ([magazine.files count] && [(magazine.files)[0] isEqualToString:fileName]) {
return magazine;
}
}
Expand All @@ -171,9 +171,9 @@ - (void)loadMagazinesAvailableFromWeb {
PSELog(@"Error while parsing magazine JSON - Dictionary expected. Got this instead: %@", dlMagazine);
}else {
// create and fill PSPDFMagazine
NSString *title = [dlMagazine objectForKey:@"name"];
NSString *urlString = [dlMagazine objectForKey:@"url"];
NSString *imageURLString = [dlMagazine objectForKey:@"image"];
NSString *title = dlMagazine[@"name"];
NSString *urlString = dlMagazine[@"url"];
NSString *imageURLString = dlMagazine[@"image"];
if ([imageURLString length] == 0) {
// if no image key is set, try same location as the pdf, but with jpg ending.
imageURLString = [urlString stringByReplacingOccurrencesOfString:@".pdf" withString:@".jpg" options:NSCaseInsensitiveSearch | NSBackwardsSearch range:NSMakeRange(0, [urlString length])];
Expand Down Expand Up @@ -259,7 +259,7 @@ + (void)addSkipBackupAttributeToFile:(NSString *)filePath {
/// Returns the legacy storage path, used when the com.apple.MobileBackup file attribute is not available.
+ (NSString *)legacyStoragePath {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
return [paths objectAtIndex:0];
return paths[0];
}

/// Returns YES if system supports com.apple.MobileBackup file attribute, marks files/folders as not iCloud-backupable.
Expand Down Expand Up @@ -289,7 +289,7 @@ + (NSString *)storagePath {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
if ([self isBackupXAttributeAvailable]) {
storagePath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
storagePath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
}else {
storagePath = [self legacyStoragePath];
// mark that we use the legazy storage.
Expand Down Expand Up @@ -505,7 +505,7 @@ - (void)updateNewsstandIcon:(PSPDFMagazine *)magazine {

// if magazine doesn't exist anymore, choose the first magazine in the list
if (!magazine && [self.magazineFolders count]) {
magazine = [[self.magazineFolders objectAtIndex:0] firstMagazine];
magazine = [(self.magazineFolders)[0] firstMagazine];
}
}

Expand Down

0 comments on commit 8789b2a

Please sign in to comment.