iOS help: math.h? Where is this? - ios

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.

Related

How to find iOS header files

in Xcode, given a type or a method name, how can I determine the header file(s) to use? For example, if I add either of these lines to my Xcode project
1. AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
2. AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
the compiler says "Unknown type name AVCaptureDevice" or "Use of undeclared identifier 'kSystemSoundID_Vibrate'". (That second one needs #import <AudioToolbox/AudioToolbox.h>.) The header files are not listed in Xcode's documentation files for iOS. Sometimes I get lucky and a code snippet on Stack Overflow will show the header files, but usually the import and include lines are not shown. I always #import <UIKit/UIKit.h>.
How can I find the correct header file(s) to import for a line in Xcode?
There are several approaches, but probably the most fool-proof here would be to lookup AVCaptureDevice in the Xcode docs (Cmd-Shift-0) or at developer.apple.com:
https://developer.apple.com/search/?q=avcapturedevice
This will take you to the main page:
https://developer.apple.com/documentation/avfoundation/avcapturedevice/
And that will show you the correct framework: AVFoundation (observe the path to this file, also visible in the Xcode docs). So you want #import AVFoundation.
From your description, it seems you already found "Audio Toolbox" in the docs. That will pretty reliably be #import AudioToolbox (i.e. just remove the space). I can't think of any cases where existing docs don't match the name of the framework. (There are important cases where the Xcode docs are missing entirely, like CommonCrypto, but I can't think of any where they give the wrong name.)
Note that the vast majority of Apple headers are now modular, so you can and should use the #import syntax with just the name of the framework, rather than the #import syntax with the path to the header.
You could also often option-click (for the docs) or command-click (for this header) AVCaptureDevice in the code. This sometimes requires already importing the correct file, but sometimes it doesn't.
Some things are more obscure, and might not have an obvious documentation page, and Xcode may have trouble finding it if you don't know where to look. In that case, you can search the SDK directly.
Go to the SDK directory you want:
cd $(xcrun --sdk iphoneos --show-sdk-path)/System/Library/Frameworks
You can than search for all references to the symbol you want. This may not immediately give you the correct framework, but it's a quick way to narrow things down:
find . -name '*.h' | xargs grep AVCaptureDevice
Or you might choose to use something like ack or ag to search a bit more nicely.
The Open Quickly command searches all identifiers and filenames in your project and the SDK. You can find Open Quickly in the File menu, but you'll probably want to use a keyboard shortcut, which by default is ⌘⇧O. (That's command shift letter-O, which is different than the command shift zero shortcut for the documentation window that #RobNapier mentions in his answer).
So for example if I start Open Quickly and type ksystemsound, I see this:
This tells me that the symbol is defined in the AudioToolbox framework, so I can import it using either the modern #import directive
// Objective-C
#import AudioToolbox; // <- must end with a semicolon!
or the older #import directive
// Objective-C
#import <AudioToolbox/AudioToolbox.h>
and in Swift I would use the import statement
// Swift
import AudioToolbox

libnl on macOS and iOS

I'm trying to migrate a Linux/Android C app to macOS/iOS.
I have this problem, this app uses libnl library some times, in the source code you can see includes like:
#include <linux/netlink.h>
#include <linux/rtnetlink.h>
#include <linux/if_tun.h>
These files are from libnl library, you can find information about this library here:
https://www.infradead.org/~tgr/libnl/doc/core.html#_introduction
I don't know what it's the equivalent in macOS and iOS. Maybe is the same but in another path?
Also I tried to download libnl library and add it to /usr/local/include but it have other dependencies, this is why that I think that I'm in the wrong way...
I found this guide https://developer.apple.com/library/content/documentation/Darwin/Conceptual/NKEConceptual/intro/intro.html#//apple_ref/doc/uid/TP40001858-CH225-SW1
But this means that I need to rewrite all parts of the code that uses libnl?
Any ideas?
Thanks in advance!
You will probably need to do some changes to code. A quick glance at the libnl docs shows that you might be able to use GDAsyncSocket.
https://github.com/robbiehanson/CocoaAsyncSocket
But without seeing your code, it's not possible to be sure.

iOS panoramic app: PanoramaView porting on swift

I need to show some 360 degree spherical photos and was trying to use the RobbyCraft's Panorama repository on Github. I'm able to get the Obj-C project running well, but I don't understand on how use the swift example described by Fabien here.
(By the way I know that I can also use the Google Maps API to render panoramic photos, but I'm afraid that it's a more complicated approach for my needs...)
I made a swift app with a GLKitViewController. Obviously I get "Use of unresolved identifier 'panoramaView'...
Must I use the "Bridging-Header.h" declaration ? (I mean #import "PanoramaView.h")?
I tried to do so, but then I'll get many errors on PanoramaView.h itself.
(PS. I added the needed frameworks to my project, too)
In the Bridging-Header.h file add the following line on top
#import "PanoramaView.m"
In PanoramaView.h, at the top add
#import <GLKit/GLKit.h>
I had same problem and this solved it

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.

Theos preference loader + tweak error

I am making a cydia tweak with a preference bundle using theos in my iPhone
But I'm getting this error!
This is the code I have in:
PSListController
(I have no idea where is the error in my code. The code is too long to paste here. I made a link to my codes)
http://pastebin.com/gQvYvB89
How do I solve this problem?
This isn't an answer but it won't allow me to comment.
A good alternative to IOSOpenDev is Theos, this is more like you are used to as it works the same as on your iphone. You use the make command and have templates.
Installation is fairly involved but here is a good guide.
http://brandontreb.com/beginning-jailbroken-ios-development-getting-the-tools
You should add #import <UIKit/UIKit.h> at the beginning of the header file (this is a common thing: if you encounter a system defined class or protocol - basically every class that starts with NS or UI and some others - you should remove the header generated by class-dump and import the system header, this will save you a lot of headaches).
By the way, you should really NOT compile stuff on device because the GCC that there's on Cydia is very outdated (I think it's from the iOS 3.x days) and using Theos is a pain in the ass anyway: there is another framework that'll help you building preference bundles (and tweaks, siri extensions, toggles for SBSettings, ...), it's called iOSOpenDev and it lets you use Xcode for these projects, which is a MAJOR improvement over compiling on device from the command line (so without code completion, syntax highlighting and all those great improvements Xcode can give you).
PS: if you choose to move to iOSOpenDev feel free to ask for explanations, I have some experience with it ;)

Resources