Obj-C to swift in xcode [closed] - swift

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am a swift newbie. I have an old app in obj-c, I would like to translate it to swift. Despite what I read, I am not quite sure how to use the convert to swift feature in Xcode. Can some one give me some guidances? Thanks. I am mainly confused about how the .h and .m on the obj-c side merge into one .swift file. In the .h file, I have a lot of variables and IBOutlets and IBActions declared. How does these all translate to the swift side. Thanks

AFAIK there is no convert Objective C to swift code feature in Xcode. There is only a convert from Swift X to newer Swift Y features.
That said. The .h file is the header file of your objective c. These are the methods and properties that other objects in your code can call on that specific class.
Swift has a similar feature but its all in the Swift file. If you mark a function as private then its roughly equivalent to a method being in the .m file but NOT in the .h file.
However, when you're just getting started with swift, don't sweat it too much. Use the default func declaration in place of -( declaration in objective c and just forget about the .h file for now. This will expose all functions and properties as if they were in the .h file in Objective C. But while you're getting started, thats the easier, more permissive way. Once you get more experienced you can start marking functions and methods as private and then they will no longer be exposed to other parts of your code.

Related

Swift : Using multiple swift files or not with only one viewController? Keeping it clean

I'm pretty new in programming in swift. Right now I'm halfway through a course and really loving it. Right now I'm a musician and before I started this course, I already had an idea of what app to make. So I started making this Music Play along app and am pretty happy already with how it's coming together. On to my question :
I've been coding all of my functions, variables and outlets into the main ViewController.swift file. It's becoming a pretty long read and I was thinking if it would be better to separate some functions in different swift files. Now as I understand it, different .swift files come into play if you create classes that aren't directly related to each other, but so far all of my code is related to this single ViewController aka the main screen. Disregarding the efficiency that probably could be better in my coding, should I keep on going in this single file, or should I start differentiating some parts of my code and put them in their own swift files?
Alright thanks in advance and also, thank you SO much for all the invaluable information on this website. This is a pretty amazing community.
-Patrick
First of all, I structure my code like this: the ViewController is divided into 3 files, in the first there is the declaration and also the override methods and obj-C methods, in the second file I put the delegate, on extension for each delegate and in the first there is a unique extension where I put all the helper methods.
If the application contains only one ViewController you can leave all inside the main, but if the app will be a more complicated and structured, it's better you create a second viewController presented by the parent ViewController where you perform all what you need to do.

Video editing frameworks for Swift

I am in the process of trying to create an app that focuses on editing video in Swift. I was wondering if there are any video editing frameworks out there for Swift with documentation somewhere? I know that, in Objective-C, there is AVFoundation, but is there an equivalent for Swift?
You just need to add the import statement to the top of your Swift file to use it (the same for all frameworks) in this case:
import AVFoundation

Where should I create the Core Data Stack [duplicate]

This question already has answers here:
Where to place the "Core Data Stack" in a Cocoa/Cocoa Touch application
(6 answers)
Closed 9 years ago.
I want to add core data to my app. should i need to add the core data methods in app delegate .h and .m files after adding the framework. please help
I prefer to create the core data stack later on in a view controller.
The examples and the templates create it for you in the AppDelegate. If you don't know how to do it, just create a dummy project with Core data and copy the boilerplate over.

How can we implement singleten design pattern in iphone code [duplicate]

This question already has answers here:
What should my Objective-C singleton look like? [closed]
(26 answers)
Closed 8 years ago.
I want to implement singleten design pattern in iphone code
I have one array. I want it to retain its value between function calls of from single class function.
How Can I use singleten design pattern to do above task?
Thanks.
better you can initialize it in appdelegate of your project.
then you can access this array anywhere in your project.
#define UIAppDelegate ((yourAppDelegate *)[UIApplication sharedApplication].delegate)
include this in your your appDelegate, then you can access your array any where you want.
UIAppDelegate.yourArray
Matt Gallagher has a pretty good writeup, with a very simple to use preprocessor macro to set create a singleton for class:
http://cocoawithlove.com/2008/11/singletons-appdelegates-and-top-level.html

What technique should i use to replicate the Compose email view in an iphone App? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
So I have an Application that involves sending emails through an API. What I would like is that to have the same or similar to compose email interface available on the phone already.
Unfortunately in all apples Goodness there is no view that just does that.
[AppleComposeMailViewController alloc];
Would do the trick nicely.
So I have started down the strategy of using a UItableViewController. I have had sucess until i try and Add a dynamically expanding cell on the end for Content.
Should I keep down this path or try implementing from the UIScrollView Base?
If the Table view is the way to go how would i go about getting a TextView into the Last cell that expands as a user types.
IF I go UIScrollView, what are some strategies i can use to make implementing the top table like views easier.
In App Email is available in iPhone OS 3.0 and should do just what you describe. Check out MessageUI.
check out the great 'e-mail' composer in the Three20 framework (screenshot)