0

Is adding Framework in Xcode necessary?

For using MultipeerConnectivity.

I only add #import header file, on the .h or .m file,

instead of adding MultipeerConnectivity.framework in Link Binary With Libraries or

adding the framework in project.

Is there any drawback about my behavior?

Thank you for precious time on my question.

Best,

August
  • 12,410
  • 3
  • 35
  • 51
willSapgreen
  • 1,365
  • 2
  • 17
  • 27

2 Answers2

1

If all you need from the framework header is a #defined constant, then you might not need to link to a framework. Otherwise, it is necessary to tell Xcode what framework to use so the linker can complete its job.

Also, There may be more than one framework that provides the same symbols, but provides different implementations of them. So it is necessary to specify which framework to use.

Walt Sellers
  • 3,806
  • 30
  • 35
1

You don't need to explicitly link and bundle Apple frameworks since they're already included on the device. Typically when including frameworks you #import what's known as an "umbrella header". This is basically a header file that contains #import statements for all of the framework header files.

For example, MultipeerConnectivity/MultipeerConnectivity.h looks like this:

//
//  MultipeerConnectivity.h
//  MultipeerConnectivity
//
//  Copyright 2013 Apple Inc. All rights reserved.
//

// MultipeerConnectivity headers
#import <MultipeerConnectivity/MCError.h>
#import <MultipeerConnectivity/MCPeerID.h>
#import <MultipeerConnectivity/MCNearbyServiceAdvertiser.h>
#import <MultipeerConnectivity/MCNearbyServiceBrowser.h>
#import <MultipeerConnectivity/MCSession.h>
#import <MultipeerConnectivity/MCBrowserViewController.h>
#import <MultipeerConnectivity/MCAdvertiserAssistant.h>

As part of learning more about this topic you should also check out information about weak linking.

Community
  • 1
  • 1
Kai Schaller
  • 443
  • 3
  • 9