How to know what to import? - ios

I have always been confused in finding out what i need to import in order to use a feature.
For example, when i use MFMailComposeViewController I know from googling that i need to
#import <MessageUI/MFMailComposeViewController.h>
and add: MessageUI.framework
From the reference documentation, how do I know that i need these things?
http://developer.apple.com/library/ios/#documentation/MessageUI/Reference/MFMailComposeViewController_class/Reference/Reference.html
I want to learn how to better use the reference docs without relying on googling sample codes to find out what i need to import in the future, so can someone explain how to figure this out from documentation?

See how at the top it says it's declared in MFMailComposeViewController.h? The question then is what framework that's in. Here's one way to find out.
Start in an actual iOS project in Xcode. Press Shift-Command-O (File > Open Quickly) and paste or type MFMailComposeViewController into it. Open the listing for MFMailComposeViewController.h.
Now read the jump bar at the top of the editor. It says: ... > Frameworks > MessageUI.framework > ...
This lets you deduce that you need the MessageUI framework and that you need to import (not what you said, but) <MessageUI/MessageUI.h>.

This is how I do it and it might be useful to you too..
Have you notice the navigation bar on the top? if you click "MFMailComposeViewController class Reference" field then it will give you something like this..
then you can see the "Message UI Framework Reference" and this page tells you exactly what you need to import.. this is not perfect but it helps most of time...

Related

Auto fix implement of missing method of protocol with Xcode?

I am not very familiar with Xcode,
Since I think every decent IDE should have a shortcut for auto-fix a template of implemented protocol (such as interface in java) to save some effects of the programmers to just fill in the logic and don't have to type in the method name and parameter stuff.
Such as when we meet this:
And I googled around and some guy said that there should be a fix all in scope thing in the Editor, but seems I can't make that clickable :-(
So, how to do this with xcode? Thanks.
Unfortunately Xcode is fairly behind compared to other IDE's in features for refactoring and such.
The main Xcode version: 8.x, can't do what you wish for. But some of it will be/is available in beta Xcode 9
Xcode may suggest a fix for a compiler error. You can click the errors individually to see the suggested fix(es) and select one.
Alternatively the 'Fix All In Scope' allows you to tell Xcode to select suggested fixes of the current file.

Generic implementation of 3rd party Libraries and Frameworks in Swift

I see there’s many libraries, open source, like Cocos2d, ShareKit, FormatterKit, etc. that seems up to date. (Check GitHub).
But still, implementation, snippets, samples and manual are intended to be written in Objective-C.
But, a method is a method… I think… If I get an instance of any framework/library of these and I call the method in a full Swift enviroment, would I be affected behind the scenes?
After June WWDC Swift gonna get serious, Apple is pushing hard, I’m just getting ready for the move and I don’t want my Apps to implement a soon-to-be deprecated library implementation in Objective-C.
I do not understand your question so much that I will regard your question as "Is it possible to use the Objective-C&Swiftin the same project?"
Yes, Apple claimed that developers can use Bridging-Header to implement double languages development, whatever your main developing language is ObjC or Swift. The specific details and theories about it you shall check from there.
Next I want to tell you some errors occurred in my project when I used Bridging-Header.
I always meet this kind of problem like import 'file not found'. I think you can try to check your file&folder hierarchy. Such as you have a root folder named Project, as is often the case, there is another Project in your previous Project, the root folder.
And Checking the Objective-C Bridging Header in the Build Setting. Sometime error can occurred for Project/Project/Bridging-Header.h. And the error can be corrected by changing the definition as Project/Bridging-Header.h.
If the location of Bridging-Header.h is not matching with the definition in the Build Setting, the error like import file not found will occur.
I just tell your my solution for Bridging issue I already met, I hope it can help you.

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.

iOS calculator project free to include in apps?

I'm wondering if anyone knows of any existing calculator project or library that has a basic calculator view I can push into a navigation stack. So far I haven't found anything that doesn't look like junk.
You should find everything you need there :
http://code.google.com/p/hpcalc-iphone/
http://blog.itopchiyev.com/2008/10/09/hello-iphone/
http://chris-software.com/index.php/2009/04/25/simple-calculator/
https://github.com/rargulati/Simple-Obj-C-Calculator
http://code.google.com/p/obj-c-calculator/source/browse/?r=30#svn%2Fbranches%2FCalculator%20at%20Assignment%201%253Fstate%253Dclosed
http://www.iphonedevx.com/?p=694
You would probably have to adapt some of these in a final app. Check for copyrights, and if one get your heart but cannot be included in your project (do not hesitate to contact the authors, really), rewrite yours from scratch with that inspiration source.
Check out iPhoneCalculator on GitHub, or search for it by keyname.

iOS help: math.h? Where is this?

I am following a tutorial out of a book and in the .h file of where some of my code is, I have to type in: #import . Where is this file located? Is it part of some framework or do I have to download it somewhere? I've googled this and found a question about math.h on MacRumors, so I know that it has something to do with iOS programming and probably isn't specific to the book.
It's part of the SDK that you have already installed if you are doing iOS development. All you need to do is put the line
#import <math.h>
in your code. You don't need to download anything. You don't need to link against anything (the math library, libm, is part of libSystem on both iOS and OS X, and is linked by default).
Note that this has nothing to do with "iOS programming". <math.h> is part of the C standard library, not specific to any platform.
Have you tried this? Did you encounter a problem?
Well, it depends. In the tutorial you're following, if it imports that header like so:
#import "math.h"
That means it is in the user header search path. In other words, it's not a system library, but something the author created. If that is the case, you'll have to find it online, or maybe in the back of the book you're reading.
If the library instead appears like this:
#import <accelerate/math.h>
Then it's a system library(note the '< >' instead of quotes), in the accelerate framework (just an example, I don't know if there is a math.h in accelerate or not). The first part of the path of the import indicates the framework you'll find the header in.
If you change your question to include the full #import statement in the book, I can more accurately help you.

Resources