Skip to content

Commit

Permalink
chore: reodering
Browse files Browse the repository at this point in the history
  • Loading branch information
danil-pavlov committed Feb 27, 2025
1 parent a61f3f6 commit 6a7cce8
Showing 1 changed file with 64 additions and 64 deletions.
128 changes: 64 additions & 64 deletions docs/topics/multiplatform/multiplatform-ios-dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,79 +7,23 @@ You can also reuse other libraries and frameworks from the iOS ecosystem in your
interoperability with Objective-C dependencies and Swift dependencies if their APIs are exported to Objective-C with
the `@objc` attribute. Pure Swift dependencies are not yet supported.

To handle iOS dependencies in Kotlin Multiplatform projects, you can use the [CocoaPods dependency manager](#with-cocoapods)
(pure Swift pods are not supported) or manage them manually with the [cinterop tool](#without-cocoapods).
To handle iOS dependencies in Kotlin Multiplatform projects, you can manage them with the [cinterop tool](#with-cinterop)
or use the [CocoaPods dependency manager](#with-cocoapods) (pure Swift pods are not supported).

### With CocoaPods

1. Perform [initial CocoaPods integration setup](native-cocoapods.md#set-up-an-environment-to-work-with-cocoapods).
2. Add a dependency on a Pod library from the CocoaPods repository that you want to use by including the `pod()`
function call in `build.gradle(.kts)` of your project.

<tabs group="build-script">
<tab title="Kotlin" group-key="kotlin">

```kotlin
kotlin {
cocoapods {
version = "2.0"
//..
pod("SDWebImage") {
version = "5.20.0"
}
}
}
```

</tab>
<tab title="Groovy" group-key="groovy">

```groovy
kotlin {
cocoapods {
version = '2.0'
//..
pod('SDWebImage') {
version = '5.20.0'
}
}
}
```

</tab>
</tabs>

You can add the following dependencies on a Pod library:

* [From the CocoaPods repository](native-cocoapods-libraries.md#from-the-cocoapods-repository)
* [On a locally stored library](native-cocoapods-libraries.md#on-a-locally-stored-library)
* [From a custom Git repository](native-cocoapods-libraries.md#from-a-custom-git-repository)
* [From a custom Podspec repository](native-cocoapods-libraries.md#from-a-custom-podspec-repository)
* [With custom cinterop options](native-cocoapods-libraries.md#with-custom-cinterop-options)

3. Run **Reload All Gradle Projects** in IntelliJ IDEA (or **Sync Project with Gradle Files** in Android Studio)
to re-import the project.

To use the dependency in your Kotlin code, import the package `cocoapods.<library-name>`. For the example above, it's:
```kotlin
import cocoapods.SDWebImage.*
```
### Without CocoaPods
### With cinterop

If you don't want to use CocoaPods, you can use the cinterop tool to create Kotlin bindings for Objective-C or Swift
You can use the cinterop tool to create Kotlin bindings for Objective-C or Swift
declarations. This will allow you to call them from the Kotlin code.

The steps differ a bit for [libraries](#add-a-library-without-cocoapods)
and [frameworks](#add-a-framework-without-cocoapods), but the general workflow looks like this:
The steps differ a bit for [libraries](#add-a-library) and [frameworks](#add-a-framework),
but the general workflow looks like this:

1. Download your dependency.
2. Build it to get its binaries.
3. Create a special `.def` [definition file](native-definition-file.md) that describes this dependency to cinterop.
4. Adjust your build script to generate bindings during the build.

#### Add a library without CocoaPods
#### Add a library

1. Download the library source code and place it somewhere where you can reference it from your project.
2. Build a library (library authors usually provide a guide on how to do this) and get a path to the binaries.
Expand Down Expand Up @@ -169,7 +113,7 @@ property in the `.def` file. For the example above, this will be:
import DateTools.*
```

#### Add a framework without CocoaPods
#### Add a framework

1. Download the framework source code and place it somewhere that you can reference it from your project.
2. Build the framework (framework authors usually provide a guide on how to do this) and get a path to the binaries.
Expand Down Expand Up @@ -260,6 +204,62 @@ import MyFramework.*
Learn more about [Objective-C and Swift interop](native-objc-interop.md) and
[configuring cinterop from Gradle](multiplatform-dsl-reference.md#cinterops).

### With CocoaPods

1. Perform [initial CocoaPods integration setup](native-cocoapods.md#set-up-an-environment-to-work-with-cocoapods).
2. Add a dependency on a Pod library from the CocoaPods repository that you want to use by including the `pod()`
function call in `build.gradle(.kts)` of your project.

<tabs group="build-script">
<tab title="Kotlin" group-key="kotlin">

```kotlin
kotlin {
cocoapods {
version = "2.0"
//..
pod("SDWebImage") {
version = "5.20.0"
}
}
}
```

</tab>
<tab title="Groovy" group-key="groovy">

```groovy
kotlin {
cocoapods {
version = '2.0'
//..
pod('SDWebImage') {
version = '5.20.0'
}
}
}
```

</tab>
</tabs>

You can add the following dependencies on a Pod library:

* [From the CocoaPods repository](native-cocoapods-libraries.md#from-the-cocoapods-repository)
* [On a locally stored library](native-cocoapods-libraries.md#on-a-locally-stored-library)
* [From a custom Git repository](native-cocoapods-libraries.md#from-a-custom-git-repository)
* [From a custom Podspec repository](native-cocoapods-libraries.md#from-a-custom-podspec-repository)
* [With custom cinterop options](native-cocoapods-libraries.md#with-custom-cinterop-options)

3. Run **Reload All Gradle Projects** in IntelliJ IDEA (or **Sync Project with Gradle Files** in Android Studio)
to re-import the project.

To use the dependency in your Kotlin code, import the package `cocoapods.<library-name>`. For the example above, it's:
```kotlin
import cocoapods.SDWebImage.*
```
## What's next?

Check out other resources on adding dependencies in multiplatform projects and learn more about:
Expand Down

0 comments on commit 6a7cce8

Please sign in to comment.