This library is a wrapper over the service layer in the VIPER architecture.
To use a service-core, all you will need to import 'ServiceCore' module into your swift file:
import ServiceCore
import ServiceCore
// MARK: - SomeSevice
protocol SomeSevice {
/// Obtain target entity
func obtain() -> ServiceCall<YourTargetPlainObject>
}
// MARK: - SomeServiceImplementation
final class SomeServiceImplementation: WebService {
// MARK: - Initializers
/// Default initializer
/// - Parameter:
/// - transport: HTTPTransport instance
init(transport: HTTPTransport) {
super.init(baseURL: URL(string: "https://yourBaseURL.com/"), transport: transport)
}
}
// MARK: - SomeSevice
extension SomeSeviceImplementation: SomeSevice {
func obtain() -> ServiceCall<YourTargetPlainObject> {
createCall { () -> Result<YourTargetPlainObject, Error> in
let request = HTTPRequest(
httpMethod: .get,
endpoint: "/entity",
base: self.baseRequest
)
let result = self.transport.send(request: request)
switch result {
case .success(let response):
let json = try response.getJSONDictionary() ?? [:]
let entity = try Mapper<YourTargetPlainObject>().map(JSON: json)
return .success(entity)
case .failure(let error):
log.error(error)
return .failure(error)
}
}
}
}
Learn more about http-transport
- iOS 12.0+
- Xcode 9.0
- Swift 5.3
- If you found a bug, open an issue.
- If you have a feature request, open an issue.
- If you want to contribute, submit a pull request.
CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:
$ gem install cocoapods
To install it using CocoaPods, simply add the following line to your Podfile:
use_frameworks!
target "<Your Target Name>" do
pod "service-core", :git => "https://github.com/Incetro/service-core", :tag => "[0.0.1]"
end
Then, run the following command:
$ pod install
If you prefer not to use any dependency managers, you can integrate service-core into your project manually.
-
Open up Terminal,
cd
into your top-level project directory, and run the following command "if" your project is not initialized as a git repository:$ git init
-
Add service-core as a git submodule by running the following command:
$ git submodule add https://github.com/incetro/service-core.git
-
Open the new
service-core
folder, and drag theServiceCore.xcodeproj
into the Project Navigator of your application's Xcode project.It should appear nested underneath your application's blue project icon. Whether it is above or below all the other Xcode groups does not matter.
-
Select the
ServiceCore.xcodeproj
in the Project Navigator and verify the deployment target matches that of your application target. -
Next, select your application project in the Project Navigator (blue project icon) to navigate to the target configuration window and select the application target under the "Targets" heading in the sidebar.
-
In the tab bar at the top of that window, open the "General" panel.
-
Click on the
+
button under the "Embedded Binaries" section. -
You will see two different
ServiceCore.xcodeproj
folders each with two different versions of theServiceCore.framework
nested inside aProducts
folder. -
Select the
ServiceCore.framework
.You can verify which one you selected by inspecting the build log for your project. The build target for
Nio
will be listed as eitherServiceCore iOS
. -
And that's it!
The
ServiceCore.framework
is automagically added as a target dependency, linked framework and embedded framework in a copy files build phase which is all you need to build on the simulator and a device.
TraxxasWyls: [email protected], incetro: [email protected]
Validator is available under the MIT license. See the LICENSE file for more info.