Skip to content

Instantly share code, notes, and snippets.

View Arrlindii's full-sized avatar

Arlind Aliu Arrlindii

View GitHub Profile
func getPetalCenteres() -> [CGPoint] {
let h = radius
let center = CGPoint(x: h/2, y: h/2)
var points: [CGPoint] = []
let d = petalCount - Double(Int(petalCount)) > 0 ? 1 : 0
for i in 0..<Int(petalCount) + d {
let angle = (Double(i) + Double(self.scale)) * (360/Double(petalCount))
let angleInRad = angle*Double.pi/180
let point = CGPoint(x: center.x + CGFloat(cos(angleInRad) * h), y: center.y + CGFloat(sin(angleInRad)*h))
points.append(point)
var animatableData: Double {
get {return petalCount}
set {petalCount = newValue}
}
func getPetalCenteres() -> [CGPoint] {
let h = radius
let center = CGPoint(x: h/2, y: h/2)
var points: [CGPoint] = []
for i in 0..<Int(petalCount) {
let angle = (Double(i) + Double(self.scale)) * (360/Double(petalCount))
let angleInRad = angle*Double.pi/180
NotificationCenter.default.publisher(for: .userUpdated).map { notification in
return notification.userInfo?["data"] as! Data
}
.decode(type: User.self, decoder: JSONDecoder())
.map { $0.name}
.sink { username in
self.usernameLabel.text = username
}
networkService.request(.login(username: username, password: password))
.flatMap { token in
networkService.request(.playlists(token))
}.flatMap { playlists in
let playlist = playlists.first
networkService.request(.songs(for: playlist.id))
}.sink(receiveCompletion: { _ in
UIApplication.shared.isNetworkActivityIndicatorVisible = false
}, receiveValue: { songs in
self.configure(with: songs)
let weatherPublisher = networkSevice.request(.weather(lat: lat, lon: lon))
let locationImagePublisher = networkSevice.request(.locationImage(lat: lat, lon: lon))
Publishers.Zip(weatherPublisher, locationImagePublisher).sink { (weather, image) in
self.weatherLabel.text = weather
self.locationImageView.image = image
}
let testData = (1...1000000).map { _ in randomString(length: 8) }
func testCombineSwift() {
_ = Publishers.Sequence(sequence: testData)
.flatMap { Publishers.Just($0) }
.map {$0.lowercased()}
.removeDuplicates()
.filter({$0.contains("a")})
.dropFirst(2)
.sink(receiveValue: { value in
print(value)
let selectedFilter = PassthroughSubject<String, Never>()
let searchText = NotificationCenter.default
.publisher(for: UITextField.textDidChangeNotification, object: searchTextField)
.map( { ($0.object as! UITextField).text } )
.debounce(for: .milliseconds(500), scheduler: RunLoop.main)
.eraseToAnyPublisher()
let publisher = Publishers.CombineLatest(selectedFilter,searchText, transform: { selectedFilter, searchText in
"\(selectedFilter) \(searchText)"
_ = Publishers.Sequence(sequence: [1,2,3,4,5])
.flatMap { Publishers.Just($0) }
.scan(0, +)
.sink(receiveValue: { value in
print(value)
})
let selectedFilter = PassthroughSubject<String, Never>()
let searchText = PassthroughSubject<String, Never>()
let publisher = Publishers.CombineLatest(selectedFilter,searchText, transform: { selectedFilter, searchText in
"\(selectedFilter) \(searchText)"
})
_ = publisher.sink { value in
print(value)
}