Skip to content

Add Xcode 7 lightweight generics to make Swift use easier - #54

Merged
jasperblues merged 1 commit into
appsquickly:masterfrom
iosdevzone:Xcode7
Sep 23, 2015
Merged

jasperblues merged 1 commit into
appsquickly:masterfrom
iosdevzone:Xcode7

Conversation

@iosdevzone

Copy link
Copy Markdown
Contributor

This PR adds Xcode 7 lightweight generic annotations to various .h files. This makes the library much more pleasant to use in Swift and also adds some compiler checking (during the process I discovered that -[XCProject configurationWithName] had an incorrect return type!)

I did not propagate the annotated types to the .m files since it appears the compiler ignores them (e.g. you can add a different annotation in the .m file and the compiler and static analyzer do not complain).

Since these annotations are only available in Xcode 7 perhaps they should not be merged onto master? It would break builds for folks still on Xcode 6.

@jasperblues

Copy link
Copy Markdown
Member

Hello @iosdevzone

Are these backward compatible? (I haven't tried OC generics yet - super happy when they were announced though)

Is this backward backward compatible? If not, I want to tag a new .x version and push that to cocoapods as the final, and start a new major version.

Thanks so much for this 🍻

@iosdevzone

Copy link
Copy Markdown
Contributor Author

Hi Jasper,
Code containing lightweight generics is only compilable with Xcode 7, but they do not require runtime support, so you can set your deployment target to earlier versions of the OS. So they are not backward compatible at compile time but are a runtime.
If you wanted to keep the codebase compilable with older versions of Xcode we could do something like this.

#if __has_feature(objc_generics)
#define NSARRAY_OF(x) NSArray<x>
#define NSDICTIONARY_OF(x,y) NSDictionary<x,y>
#else
#define NSARRAY_OF(x) NSArray
#define NSDICTIONARY_OF(x,y) NSDictionary
#endif

Then in the object interfaces use something like:

@interface ViewController : UIViewController

@property (nonatomic) NSARRAY_OF(NSString*) *objects;
@property (nonatomic) NSDICTIONARY_OF(NSString*,NSString*) *stringToString;
@end

This approach might simplify fixing bugs in the future (i.e. you would not need to back port them). You probably have a better idea what users of the library want or need so I will defer to your judgement on this.

Cheer,
Danny

@jasperblues

Copy link
Copy Markdown
Member

OK, let's just tell folks on older versions to use either a static library, or the last .x version. I'll tag the final .x now and merge this as a new version.

jasperblues added a commit that referenced this pull request Sep 23, 2015
Add Xcode 7 lightweight generics to make Swift use easier
@jasperblues
jasperblues merged commit 4a2c9b3 into appsquickly:master Sep 23, 2015
@jasperblues

Copy link
Copy Markdown
Member

Merged @iosdevzone - thanks so much. Sorry for the delay.

@iosdevzone

Copy link
Copy Markdown
Contributor Author

Thanks. I hope folks find the changes useful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants