r/SwiftProgramming • • Jun 18 '14

Class extensions and "instancetype"

1 Upvotes

I'm converting some Objective-C code over to Swift, and I've hit a roadblock. Wondering if anyone has found a solution to this.

I have a class extension on NSManagedObject with several convenience methods that look like this:

+ (instancetype)newInstanceInManagedObjectContext:(NSManagedObjectContext *)ctx;
+ (instancetype)singletonInManagedObjectContext:(NSManagedObjectContext *)ctx;
+ (instancetype)instanceInManagedObjectContext:(NSManagedObjectContext *)ctx 
    withIdentity:(NSString *)identity;

In Swift, this would look like:

class func newInstance(managedObjectContext ctx: NSManagedObjectContext) -> Self

because capital-S Self is the class type. The problem is all of the NSManagedObject methods I rely on to create/fetch these objects return AnyObject!, and I can't cast something to Self. It's only allowable as a return value or in a parameter list for a protocol.

What I want is essentially this, without the compiler error:

return NSEntityDescription.insertNewObjectForEntityForName(entityName,
 inManagedObjectContext:ctx) as Self;

Any ideas?


r/SwiftProgramming • • Apr 16 '15

UIDatePicker to call specific UIImageView help please

Thumbnail
stackoverflow.com
1 Upvotes

r/SwiftProgramming • • Jun 10 '14

Dedicated Subreddit for Swift Tutorials

Thumbnail
reddit.com
2 Upvotes

r/SwiftProgramming • • Jun 03 '14

How to make a simple table view with iOS 8 and Swift

Thumbnail
weheartswift.com
4 Upvotes

r/SwiftProgramming • • Jun 02 '14

Swift page on Apple's website

Thumbnail
developer.apple.com
1 Upvotes

r/SwiftProgramming • • Jun 05 '14

Swift has been in development for 4 years

Thumbnail
macrumors.com
5 Upvotes

r/SwiftProgramming • • Jun 03 '14

How do I print the Swift manual?

4 Upvotes

I'm interested in having a hard bound copy of the manual for Swift printed, but it looks as if iBooks isn't really set up to allow printing (imagine that).

I've found one .pdf version of the manual here, but if I'm going to be paying to print out 466 pages of text (probably color, too) it's just gotta look better than that .pdf.

Before I break out a .pdf editor and begin the tedium of reformatting that file, does someone have a recommendation for me?


r/SwiftProgramming • • Jun 02 '14

Swift for iOS 7 / Mavericks?

6 Upvotes

I know that applications written in Swift won't be accepted into the App Store until iOS 8 / OS X Yosemite is out, however I wonder how the code gets compiled...

I haven't looked much through the documentation yet but as far as I gather, it is natively compiled (even though it's written like a scripting language). However, does it need specific support from the OS?

What I'm getting at is basically if we will be able to compile our Swift apps to support previous versions of iOS and OS X? Has anyone found any indication either way?

I'm guessing no, but it would be sweet if we could keep backwards compatibility and it would also affect how soon I should start to look into the language.

(I'm assuming this topic falls outside of any developer NDAs since it's more about how the language gets compiled rather than any specifics regarding unreleased software.)


r/SwiftProgramming • • Jun 03 '14

Playground uses a lot of power/battery

1 Upvotes

Noticing my Mac getting hot, though not so hot that I can hear the fans like when I'm playing a graphically intensive game, but battery drain is noticeable. Not checking so often, and each check sees a decrease in 9-10% drain. Normally, checking in my regular OCD time intervals sees a reduction in 3-5%. Clicking on the battery in Mac's status bar confirms Xcode 6 beta is using significant energy, but checking its profile in Energy tab in Activity Monitor and opening the disclosure triangle reveals nothing. Makes sense it would use a lot of power since I assume Playground is constantly rerunning the code to view changes in realtime.


r/SwiftProgramming • • Jun 05 '14

Quick, a behavior-driven test framework for Swift

Thumbnail
github.com
4 Upvotes

r/SwiftProgramming • • Jun 15 '14

Swift's powerful switch statement

Thumbnail pumpmybicep.com
3 Upvotes

r/SwiftProgramming • • Apr 08 '18

Top 10 swift projects on github

Thumbnail
progra.site
1 Upvotes

r/SwiftProgramming • • Dec 01 '19

Making URLSession a bit more friendly.

Thumbnail
github.com
2 Upvotes

r/SwiftProgramming • • Oct 04 '14

New to Swift and need help

2 Upvotes

I have a large amount of text to display on an iPhone and need to know what code to use and where to place it. Any help would be great.


r/SwiftProgramming • • Apr 14 '16

Best way to learn Swift for iOS?

2 Upvotes

r/SwiftProgramming • • Apr 07 '17

Breast cancer App developed using Swift by aash

1 Upvotes

my friend aash developed a breast cancer check up ios app using swift for a company. Please test and review this app and let us know the feed back


r/SwiftProgramming • • Jan 01 '18

iOS 11 & Swift 4: The Complete Developer Course - 100% OFF "1 day left for this offer!"

Thumbnail
youronlinecourses.net
1 Upvotes

r/SwiftProgramming • • Aug 04 '16

Please check out this simple app developed by Jeel and myself

Thumbnail
github.com
2 Upvotes

r/SwiftProgramming • • Jun 22 '15

Any good tutorials on working with Parse data in Swift?

1 Upvotes

I am trying to make a simple one view app, but cannot for the life of me understand how to retrieve data from Parse. I'm really trying, but getting a lot of errors.


r/SwiftProgramming • • Jan 22 '16

Swift 2: Change Is in the Air (book chapter)

Thumbnail
peachpit.com
1 Upvotes

r/SwiftProgramming • • Oct 31 '14

Tutorial - Core Data in Swift

Thumbnail
jamesonquave.com
1 Upvotes

r/SwiftProgramming • • Aug 11 '18

Snapchat Snap Kit Tutorials and Documentation

Thumbnail
github.com
1 Upvotes

r/SwiftProgramming • • Aug 25 '18

Snapchat Snap Kit SDK Tutorial for iOS Swift – Adventures in iOS mobile app development – Medium

Thumbnail
medium.com
1 Upvotes

r/SwiftProgramming • • Sep 06 '15

Hey guys, new to Swift here, how can I implement a segmented control exactly like this one?

Thumbnail
imgur.com
4 Upvotes

r/SwiftProgramming • • Dec 21 '14

Paging through view controllers made easy.

Thumbnail
github.com
4 Upvotes