--- id: ios-native title: Set up your iOS app sidebar_label: iOS --- We support both Swift and Objective-C for Flipper with CocoaPods as build and distribution mechanism. ## CocoaPods The following configuration assumed CocoaPods 1.9+. ```ruby project 'MyApp.xcodeproj' flipperkit_version = '0.37.0' target 'MyApp' do platform :ios, '9.0' # use_framework! pod 'FlipperKit', '~>' + flipperkit_version pod 'FlipperKit/FlipperKitLayoutComponentKitSupport', '~>' + flipperkit_version pod 'FlipperKit/SKIOSNetworkPlugin', '~>' + flipperkit_version pod 'FlipperKit/FlipperKitUserDefaultsPlugin', '~>' + flipperkit_version # If you use `use_frameworks!` in your Podfile, # uncomment the below $static_framework array and also # the pre_install section. This will cause Flipper and # it's dependencies to be built as a static library and all other pods to # be dynamic. # $static_framework = ['FlipperKit', 'Flipper', 'Flipper-Folly', # 'CocoaAsyncSocket', 'ComponentKit', 'Flipper-DoubleConversion', # 'Flipper-Glog', 'Flipper-PeerTalk', 'Flipper-RSocket', 'Yoga', 'YogaKit', # 'CocoaLibEvent', 'OpenSSL-Universal', 'boost-for-react-native'] # # pre_install do |installer| # Pod::Installer::Xcode::TargetValidator.send(:define_method, :verify_no_static_framework_transitive_dependencies) {} # installer.pod_targets.each do |pod| # if $static_framework.include?(pod.name) # def pod.build_type; # Pod::BuildType.static_library # end # end # end # end # This post_install hook adds the -DFB_SONARKIT_ENABLED=1 flag to OTHER_CFLAGS, necessary to expose Flipper classes in the header files post_install do |installer| installer.pods_project.targets.each do |target| if target.name == 'YogaKit' target.build_configurations.each do |config| config.build_settings['SWIFT_VERSION'] = '4.1' end end end file_name = Dir.glob("*.xcodeproj")[0] app_project = Xcodeproj::Project.open(file_name) app_project.native_targets.each do |target| target.build_configurations.each do |config| cflags = config.build_settings['OTHER_CFLAGS'] || '$(inherited) ' unless cflags.include? '-DFB_SONARKIT_ENABLED=1' puts 'Adding -DFB_SONARKIT_ENABLED=1 in OTHER_CFLAGS...' cflags << '-DFB_SONARKIT_ENABLED=1' end config.build_settings['OTHER_CFLAGS'] = cflags end app_project.save end installer.pods_project.save end end ``` ```ruby project 'MyApp.xcodeproj' flipperkit_version = '0.37.0' target 'MyApp' do platform :ios, '9.0' pod 'FlipperKit', '~>' + flipperkit_version # Layout and network plugins are not yet supported for swift projects pod 'FlipperKit/FlipperKitLayoutComponentKitSupport', '~>' + flipperkit_version pod 'FlipperKit/SKIOSNetworkPlugin', '~>' + flipperkit_version pod 'FlipperKit/FlipperKitUserDefaultsPlugin', '~>' + flipperkit_version # If you use `use_frameworks!` in your Podfile, # uncomment the below $static_framework array and also # the pre_install section. This will cause Flipper and # it's dependencies to be built as a static library and all other pods to # be dynamic. # $static_framework = ['FlipperKit', 'Flipper', 'Flipper-Folly', # 'CocoaAsyncSocket', 'ComponentKit', 'Flipper-DoubleConversion', # 'Flipper-Glog', 'Flipper-PeerTalk', 'Flipper-RSocket', 'Yoga', 'YogaKit', # 'CocoaLibEvent', 'OpenSSL-Universal', 'boost-for-react-native'] # # pre_install do |installer| # Pod::Installer::Xcode::TargetValidator.send(:define_method, :verify_no_static_framework_transitive_dependencies) {} # installer.pod_targets.each do |pod| # if $static_framework.include?(pod.name) # def pod.build_type; # Pod::BuildType.static_library # end # end # end # end # This post_install hook adds the -DFB_SONARKIT_ENABLED flag to OTHER_SWIFT_FLAGS, necessary to build swift target post_install do |installer| installer.pods_project.targets.each do |target| if target.name == 'YogaKit' target.build_configurations.each do |config| config.build_settings['SWIFT_VERSION'] = '4.1' end end end file_name = Dir.glob("*.xcodeproj")[0] app_project = Xcodeproj::Project.open(file_name) app_project.native_targets.each do |target| target.build_configurations.each do |config| if (config.build_settings['OTHER_SWIFT_FLAGS']) unless config.build_settings['OTHER_SWIFT_FLAGS'].include? '-DFB_SONARKIT_ENABLED' puts 'Adding -DFB_SONARKIT_ENABLED ...' swift_flags = config.build_settings['OTHER_SWIFT_FLAGS'] if swift_flags.split.last != '-Xcc' config.build_settings['OTHER_SWIFT_FLAGS'] << ' -Xcc' end config.build_settings['OTHER_SWIFT_FLAGS'] << ' -DFB_SONARKIT_ENABLED' end else puts 'OTHER_SWIFT_FLAGS does not exist thus assigning it to `$(inherited) -Xcc -DFB_SONARKIT_ENABLED`' config.build_settings['OTHER_SWIFT_FLAGS'] = '$(inherited) -Xcc -DFB_SONARKIT_ENABLED' end app_project.save end end installer.pods_project.save end end ``` You need to compile your project with the `FB_SONARKIT_ENABLED=1` compiler flag. The above `post_install` hook adds this compiler flag to your project settings.