Refactor: extract ios core like android

This commit is contained in:
Ming Ming 2023-09-06 23:25:48 +08:00
parent b43b099f7e
commit 904b898a44
8 changed files with 101 additions and 36 deletions

36
np_ios_core/.gitignore vendored Normal file
View file

@ -0,0 +1,36 @@
# macOS
.DS_Store
# Xcode
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata/
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
# Bundler
.bundle
# Add this line if you want to avoid checking in source code from Carthage dependencies.
# Carthage/Checkouts
Carthage/Build
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control
#
# Note: if you ignore the Pods directory, make sure to uncomment
# `pod install` in .travis.yml
#
# Pods/

View file

@ -0,0 +1,26 @@
Pod::Spec.new do |s|
s.name = 'NpIosCore'
s.version = '0.1.0'
s.summary = 'A short description of NpIosCore.'
s.description = <<-DESC
TODO: Add long description of the pod here.
DESC
s.homepage = 'http://example.com'
s.license = { :type => 'GPLv3' }
s.author = { 'Your Company' => 'email@example.com' }
s.source = { :path => '.' }
s.ios.deployment_target = '12.0'
s.source_files = 'NpIosCore/Classes/**/*'
# s.resource_bundles = {
# 'NpIosCore' => ['NpIosCore/Assets/*.png']
# }
# s.public_header_files = 'Pod/Classes/**/*.h'
# s.frameworks = 'UIKit', 'MapKit'
# s.dependency 'AFNetworking', '~> 2.3'
s.dependency 'Flutter'
s.dependency 'Logging'
end

View file

View file

@ -0,0 +1,22 @@
import Foundation
public class AppError: Error {
public init(_ message: String? = nil, stackTrace: [String] = Thread.callStackSymbols) {
self.message_ = message
self.stackTrace = stackTrace.joined(separator: "\n")
}
public var description: String {
return "\(message_ ?? "") (throw: \(String(describing: self))\nStack trace:\n\(stackTrace)"
}
public var message: String {
return message_ == nil ? String(describing: self) : message_!
}
public let stackTrace: String
private let message_: String?
}
public class NilError: AppError {
}

View file

@ -0,0 +1,14 @@
import Foundation
public extension Optional {
func unwrap(
_ errorBuilder: (() -> Error)? = nil,
file: String = #fileID,
line: Int = #line
) throws -> Wrapped {
guard let value = self else {
throw errorBuilder?() ?? NilError("\(type(of: self)) is nil in \(file):\(line)")
}
return value
}
}

View file

@ -1,5 +1,6 @@
import Flutter
import Foundation
import NpIosCore
class LockChannelHandler {
func onMethodCall(call: FlutterMethodCall, result: FlutterResult) {

View file

@ -1,35 +0,0 @@
import Foundation
class AppError: Error {
init(_ message: String? = nil, stackTrace: [String] = Thread.callStackSymbols) {
self.message_ = message
self.stackTrace = stackTrace.joined(separator: "\n")
}
var description: String {
return "\(message_ ?? "") (throw: \(String(describing: self))\nStack trace:\n\(stackTrace)"
}
var message: String {
return message_ == nil ? String(describing: self) : message_!
}
let stackTrace: String
private let message_: String?
}
class NilError: AppError {
}
extension Optional {
func unwrap(
_ errorBuilder: (() -> Error)? = nil,
file: String = #fileID,
line: Int = #line
) throws -> Wrapped {
guard let value = self else {
throw errorBuilder?() ?? NilError("\(type(of: self)) is nil in \(file):\(line)")
}
return value
}
}

View file

@ -10,11 +10,12 @@ Pod::Spec.new do |s|
A new Flutter plugin project.
DESC
s.homepage = 'http://example.com'
s.license = { :file => '../LICENSE' }
s.license = { :type => 'GPLv3' }
s.author = { 'Your Company' => 'email@example.com' }
s.source = { :path => '.' }
s.source_files = 'Classes/**/*'
s.dependency 'Flutter'
s.dependency 'NpIosCore'
s.platform = :ios, '9.0'
# Flutter.framework does not contain a i386 slice.