Parse Swift Documentation? - ios

I see that there are swift code examples in the iOS guide, however, when I'm looking in the official documentation, I cannot find a Swift version (i.e. method signatures are given in obj-c). Where is it located? or is it simply not available yet?
P.S. I use dash (by kapeli) it would be great to have such added to their docset as well.

just take objC and apply it 1:1 to swift ... only the syntax of the language changed -- EVERYTHING is identical (types, concepts) -- if you use those frameworks like parse or uikit or Facebook or whatever. they didn't miraculously change :)

Related

macOS, iOS & tvOS documentation missing imports?

I'm looking into iOS/tvOS docs for GCKeyboard & GCMouse types.
However Apple docs seem to be missing basic info such as what I import to use a type. For example C# docs always show what libraries are needed on MS websites for types. So do Googles Android docs. I'm not seeing this on Apples docs here: https://developer.apple.com/documentation/gamecontroller/gckeyboard
Is there an easy way in ObjC or Swift to check where a type is from?
Does Apple provide any way to lookup what source file I should import for a type? How do people normally go about these lacking docs with xCode dev work?
Apple do indicate on its doc on which framework the class/object that the document referred to is relevant. See my picture for details. Its has a documentation hierarchy from the framework down to the objects and apis within it.
Specifically for GameController framework you’d use the following import
import GameController
A nice anecdote:
In older class and objects it is also customary to add the initials of the framework/library as a prefix for the name. In this case GC(i.e game contoller)Keyboard. Or UI(UIKit)ViewController. With newer libraries like SwiftUI and Combine they have stopped using the prefix.
The prefix was used due to legacy Objetive-C limitation for namespace.

Swift framework for Swift and Objective C projects

I am building a new framework. The project is to be coded into Swift language, however the clients using this framework have the freedom of using either swift or Objective-C framework.
The question is how do I start. There could be numerous issues like
using structs in swift code but it cannot be made available in
objective C framework.
optionals are missing objective c
Even if I
write different set of files for Swift and Objective C, how will I
map them onto different frameworks under the same project.
Enums with other than Int as rawValue can't be used.
Tuples would not work
I know there have been a few questions around this but none have any satisfactory answer.
PS - Any link to a tutorial or blog would be super helpful too
I did this and got some unexpected results: I have trouble integrating the framework in Swift application. Objective-C works just fine.
You mentioned some of the caveats here.
I suggest doing this iteratively while writing test application in Objective-C which uses all the features. This way if there is some feature that does not cross Swift to Objective-C boundary well, it will be discovered as early as possible.
Your remarks about issues are generally correct with one small exception: optionals are not missing from Objective-C, they appear as nullable/nonnull modifiers on variables and method parameters. Although this does not replace optionals fully, it helps detecting issues early in the process.
Here is a random list of some other issues I discovered:
Bridging between Swift Error and NSError used in Objective-C. The conversion is not always as smooth at it could be, so better use NSError in exported code.
If you mix Objective-C and Swift in your framework, you cannot use bridging header, instead using modulemap files which tend to turn pretty large and complex.
Since you cannot embed frameworks inside a framework, you have to make sure that the application sets ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES flag for its target. This has to be clearly indicated in the documentation. Also, when creating fat library for your framework, you have to strip these files from the distributed SDK.
And, as I said in the beginning, I still have no success using the resulting mixed language framework in Swift application.
Hope, this will add to your list of things to take into account when developing the library.

UML class diagrams for Xcode (Swift programming)

I have created an iOS mobile application. Is there a way to generate a UML class diagram for the Swift programming language?
I have tried Omni Graffle, but it keeps saying that the project doesn't contain Objective-C interfaces. And Omni Graffle only does this for Objective-C.
I remember looking at this question a while ago and was disappointed that there wasn't any tool like this so I created one myself with the help of a colleague. It's free, it's open source, it's looking for contributors...
https://github.com/yoshimkd/swift-auto-diagram
And here's a tutorial on how to use it (don't worry it's very simple):
https://martinmitrevski.com/2016/10/12/swift-class-diagrams-and-more/
Happy diagraming :)
The answer unfortunately is: you can't do it. At least not automatically. Swift as compiler itself has enough flaws left. Leave alone some tool will be able to swallow any Swift code. Your only alternative is the good old manual way.
I know that Enterprise Architect has a possibility to define a language syntax based on BNF. But Swift is (again unfortunately) not context free. (In fact it's so context sensitive that it often swallows its own rear.) So that won't work either.
P.S.: Now that Swift is open source someone might take the opportunity to tap the compiler's output for the class interfaces. I guess that should not be too difficult, but it's a lot of work still.
Inspired by swift-auto-diagram and similar open-source tools I started to work on such utility with the goal to write it in Swift (to make contribution easier by Swift developers) and to integrate it in Xcode and the Swift ecosystem.
Xcode extension: https://github.com/MarcoEidinger/SwiftPlantUML-Xcode-Extension
You are able to generate a class diagram from selected lines of code or from a whole file displayed in Xcode. The class diagram will then be opened in your browser. There you can modify the diagram with PlantUML notation
To generate a class diagram from multiple source files you can use the underlying CLI tool and Swift Package: https://github.com/MarcoEidinger/SwiftPlantUML
There is a size limitation to the visible diagram content (but you can delete content in the browser with PlantUML notation)

How to implement AVCam for Swift

Hello I have found two links about AVCam
Apple: https://developer.apple.com/library/ios/samplecode/AVCam/History/History.html
alex-chan/AVCamSwift: https://github.com/alex-chan/AVCamSwift
The first link has demo files that work perfectly, but its in Object-C - can someone show me documentation on converting Object-C to Swift?
The second link I have downloaded the files but it will not run in my 4s - can someone tell me why?
I would like to have a swift version so I can easily adopt it into my swift build + thanks again SO!
if you have a working objc version why not just import it with a bridging header? there is no one document about converting obj-c to swift, if you really want to convert it you are going to need to do it line by line.
also what exactly are you trying to do? get a live camera feed displayed? these docs have been ported to swift and would suit that purpose but you would need to get the input port first.
https://developer.apple.com/library/mac/documentation/AVFoundation/Reference/AVCaptureVideoPreviewLayer_Class/index.html#//apple_ref/occ/clm/AVCaptureVideoPreviewLayer/layerWithSession:
Update: how to import obj-c headers, a newer way to create them that isnt quite as talked about yet is to just create any normal .m file or objective c file then select yes to creating a briding header, it configures everything for you.
That being said it may be worth while to play around with the basics a bit more and maybe follow a few guides before attempting to implement this type of feature if you are having issues with following the links.
Here is a random application creation guide http://www.ioscreator.com/tutorials/calculator-tutorial-in-ios8-with-swift that should teach you alot. i would recommend following and reading through stuff like this until you have a bit more of a footing and can come up with more of an exact question. no one here is going to rewrite the apple program for you and your questions are extremely broad.

Howto use Twitter-OAuth-iPhone with iOS5 and ARC

I am trying to use Ben Gottliebs Twitter-OAuth-iPhone within an iOS5 app that uses ARC.
I already flagged the files with -fno-objc-arc. But now I get a lot of errors. I don't know where to start. Without ARC the framework seems to work just fine. Any help would be appreciated.
Edit: it seems that is has something to do with SecKeychainItemRef
I can not find the answer here: https://stackoverflow.com/questions/3675522/how-to-use-mgtwitterengine-for-iphone
I hope is not considered bad etiquette to recommend my own project, but I believe it's relevant to this question, so...
I just published a new OAuth library to GitHub that's fully ARC compatible. It comes with a working demo that implements the whole Twitter OAuth flow and allows you to post a tweet. You can find it here: RSOAuthEngine.
You might want to consider using the official Twitter API that's available with iOS 5. Here's a post on how to use it: http://www.peterfriese.de/the-accounts-and-twitter-framework-on-ios-5/
You could just tell the compiler not to use ARC on the files included in that library.
ios5 ARC what is the compiler flag to exclude a file from ARC?

Resources