A Wordpress Article Loader for SwiftUI.

Overview

SwiftUIWPArticleLoader

Hello to WPArticleLoader!

With the WPArticleLoader, you can easily load Articles from your WordPress Website.

How to use?

The usage is very easy! The only thing you have to do is setting your website address and build a receiver for the Publisher:

let handler = WPArticleLoader(websiteAdress: URL(staticString: "https://ml-projects.de"))
handler.fetchArticles()
    .receive(on: DispatchQueue.main)
    .sink { response in
        switch response {
        case let .failure(error):
            print(error)
        case .finished:
            print("Articles loaded")
        }
    } receiveValue: { response in
        self.articles = response
    }
    .store(in: &cancellables)

The Article class holds the most important Data and interprets it. If you want to interpret the data on your own you can use the ArticleLoadingService and receive ContentfulArticle. In ContentfulArticle is the complete Data from the JSON of the REST API. You can use the ArticleLoadingService like this:

let articleURL = URL(staticString: "https://ml-projects.de/wp-json/wp/v2/posts")
var components = URLComponents(string: articleURL.absoluteString)!
// this is to get the embeded Data too (The Embeded Data is used by the normal Loader too)
components.queryItems = [
    URLQueryItem(name: "_embed", value: nil)
]
// Create a URLRequest
let request = URLRequest(url: components.url!)
// Create the handler
let handler = ArticleLoadingService()
handler.fetchArticles(urlRequest: request)
    .receive(on: DispatchQueue.main)
    .sink { response in
        switch response {
        case let .failure(error):
            print(error)
        case .finished:
            print("Contentful Articles loaded")
        }
    } receiveValue: { response in
        self.contentfulArticles = response
    }
    .store(in: &cancellables)

ImageLoader

The ImageLoader is another simplification, it loads the image for you so you don't have to, use it combination with AsyncImage:

// Example for the featuredImage
AsyncImage(imageLoader: featuredImageLoader) {
    // your Placeholder
}

but you can also receive the Image on your own or use the URL:

// Image
if let featuredImage = featuredImageLoader.image {
    Image(uiImage: featuredImage)
}
// URL
featuredImageLoader.url

The featuredImageLoader is an optinal because not every Article has an featuredImage.

Use the ImageLoader for your URLs

If you want to use the ImageLoader for your own URLs, probably for URLs in content you can easily initialize it and use it with AsyncImage:

// Example for the featuredImage
AsyncImage(imageLoader: ImageLoader(url: URL(staticString: "youradress.com"))) {
    // your Placeholder
}

Developed by: Torben Köhler

You might also like...
100-Days-of-SwiftUI - Studying through Paul Hudson's 100 Days of SwiftUI
100-Days-of-SwiftUI - Studying through Paul Hudson's 100 Days of SwiftUI

Hacking with SwiftUI 100 Days of SwiftUI Studying through Paul Hudson's "100 Day

Watchos-navlink-swiftui-bug - Example Project to demonstrate bug in SwiftUI when NavigationLink is activated inside a TabView SwiftUI-Card - Simple card ui designed using SwiftUI
SwiftUI-Card - Simple card ui designed using SwiftUI

SwiftUI - Card Simple card ui designed using SwiftUI Preview

Swiftui-pressed-states-example - Examples of Pressed States in SwiftUI

Examples of Pressed States in SwiftUI pressed-states.mp4

IOS15-SwiftUI-InAppPurchaseDemo - In-App Purchase Demo app written with SwiftUI
IOS15-SwiftUI-InAppPurchaseDemo - In-App Purchase Demo app written with SwiftUI

iOS15-SwiftUI-InAppPurchaseDemo In-App Purchase Demo app written with SwiftUI If

SwiftUI Backports - Introducing a collection of SwiftUI backports to make your iOS development easier

SwiftUI Backports Introducing a collection of SwiftUI backports to make your iOS development easier. Many backports support iOS 13+ but where UIKIt fe

This SwiftUI project is a result of the third 'milestone' in "Hacking With Swift's 100 Days of SwiftUI".

exercise-tracker This SwiftUI project is a result of the third 'milestone' in "Hacking With Swift's 100 Days of SwiftUI". In this exercise tracking ap

A cross-platform Reddit client built in SwiftUI
A cross-platform Reddit client built in SwiftUI

A cross-platform Reddit client created in SwiftUI. Get the Public Beta Note: This project is far from complete. It still lacks many features of your t

An example to-do list app using SwiftUI which is introduced in WWDC19
An example to-do list app using SwiftUI which is introduced in WWDC19

SwiftUITodo SwiftUITodo is an example to-do list application using SwiftUI which is first introduced in WWDC19 keynote. Requirements Xcode 11 Beta Swi

Comments
  • How to use ImageLoader?

    How to use ImageLoader?

    Hey, thanks so much for the .xcodeproj file! It has helped loads, I'm able to understand how to use the API in much better detail now. :)

    Just a quick question, I'm using your project with my app, I was wondering how to load images in a WP article onto the SwiftUI page? For article.content only image URLs are loaded rather than actual images. Also, how can I load "article.featuredImageLoader.image"? It seems to always unwrap a nil no matter what I try, and my articles have a featured image.

    Thanks for any help, and thanks so much for making this project, it's incredibly helpful!!

    bug question 
    opened by thebrokenace 5
  • .xcodeproj variant?

    .xcodeproj variant?

    Hello there,

    Thank you so much for making this, this is exactly what I was looking for!

    I just wanted to ask whether you could provide a working iOS .xcodeproj version so I can get a test build working on my simulator? I hope to analyze some of the JSON elements of your code, and testing different versions by editing how JSON is parsed.

    Please let me know, thank you again so much for making this!

    feature request feature build 
    opened by thebrokenace 2
  • Notification on new post?

    Notification on new post?

    Hello friend, I hope you are doing well! Just wanted to thank you again for this amazing resource! I was wondering you could make some sort of enhancement where you could have push notifications whenever the Wordpress page has a new post? If this is already integrated please let me know if there's a way to make it! Thanks so much!

    opened by thebrokenace 2
Releases(1.3.3)
Owner
Torben Köhler
Torben Köhler
🎲 100% SwiftUI 2.0, classic 2048 game [SwiftUI 2.0, iOS 14.0+, iPadOS 14.0+, macOS 11.0+, Swift 5.3].

swiftui-2048 If you like the project, please give it a star ⭐ It will show the creator your appreciation and help others to discover the repo. ✍️ Abou

Astemir Eleev 174 Dec 17, 2022
A simple SwiftUI Application to demonstrate creation of UI using SwiftUI.

WatchShop_UI A simple SwiftUI Application to demonstrate creation of UI using SwiftUI. How to run the project ? Fork the project. Run the project usin

Shubham Kr. Singh 12 Apr 15, 2022
E-commerce app built in SwiftUI. Built in the course SwiftUI Masterclass in Udemy.

Touchdown-SwiftUI E-commerce app built in SwiftUI. Built in the course SwiftUI Masterclass in Udemy. Main components and concepts used: @EnvironmentOb

Jorge Martinez 5 Aug 18, 2022
A multiplatform SwiftUI project demonstrating various SwiftUI features.

WikiDemo A multiplatform SwiftUI project demonstrating various SwiftUI features, including creating a master-detail interface. It's a multiplatform ve

Swift Dev Journal 6 Oct 17, 2022
SwiftUI Projects from Udemy SwiftUI Masterclass

SwiftUI Masterclass Repos: AsyncImage (N/A) Fructus (finished): an app for getting information about different fruits. Data comes from json files. Afr

Patrick Spafford 1 Mar 3, 2022
Best architecture for SwiftUI + CombineBest architecture for SwiftUI + Combine

Best architecture for SwiftUI + Combine The content of the presentation: First of the proposed architectures - MVP + C Second of the proposed architec

Kyrylo Triskalo 3 Sep 1, 2022
Weather-swiftui - An example of using SwiftUI

weather-swiftui An example of using SwiftUI Installation Get openweather api key

null 0 Jan 1, 2022
Orbit-swiftui - Orbit design system implemented in SwiftUI for iOS

Orbit is a SwiftUI component library which provides developers the easiest possi

Kiwi.com 37 Jan 3, 2023
SwiftUI Resume - A simple resume writed by swiftUI + Combine

SwiftUI_Resume a simple "resume" writed by swiftUI + Combine

null 15 Apr 27, 2022
SwiftUI-MSALSample - Sample project to login with MSAL using SwiftUI

SwiftUI-MSALSample I could not find a good walkthrough on how to implement MSAL

Rob Evans 10 Nov 7, 2022