Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Small simplification of the code, no need for casting self to id #6

merged 1 commit into from

2 participants


I saw in your blog post that you did not want to expose that DTActionSheet conforms to UIActionSheetDelegate and therefore you cast self to id. However, it is possible to add protocol conformance in a class extension inside the .m file, which makes the code a bit easier to read and at the same time keeps the protocol hidden from the header file.

@Cocoanetics Cocoanetics merged commit 18e8d9a into Cocoanetics:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 9, 2012
  1. @hollance

    No need to cast self to id if we make the class extension privately c…

    hollance authored
    …onform to the UIActionSheetDelegate protocol.
This page is out of date. Refresh to see the latest.
Showing with 8 additions and 4 deletions.
  1. +8 −4 Core/Source/DTActionSheet.m
12 Core/Source/DTActionSheet.m
@@ -8,6 +8,10 @@
#import "DTActionSheet.h"
+@interface DTActionSheet () <UIActionSheetDelegate>
@implementation DTActionSheet
id <UIActionSheetDelegate> _externalDelegate;
@@ -27,7 +31,7 @@ @implementation DTActionSheet
- (id)initWithTitle:(NSString *)title
- self = [super initWithTitle:title delegate:(id)self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles: nil];
+ self = [super initWithTitle:title delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
if (self)
@@ -126,11 +130,11 @@ - (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSIn
return _externalDelegate;
-- (void)setDelegate:(id<UIActionSheetDelegate>)delegate
+- (void)setDelegate:(id <UIActionSheetDelegate>)delegate
- if (delegate == (id)self)
+ if (delegate == self)
- [super setDelegate:(id)self];
+ [super setDelegate:self];
else if (delegate == nil)
Something went wrong with that request. Please try again.