ManiaPlanet style Swift parser

Moderators: Xymph, NADEO

Post Reply
User avatar
toffe
Posts: 782
Joined: 15 Jun 2013, 10:57
Location: The Netherlands
Contact:

ManiaPlanet style Swift parser

Post by toffe »

Image Image

Hello,
I started a Swift Maniaplanet style formatter. Inputs a string, returns a NSAttributedString for style usage on labels and more.
I will use the framework myself in the Maniaplanet Toolkit in later versions for faster parsing of styles. Currently it's using the NSAttributedString HTML parser that is very slow (because it uses webviews on the background, and because of that it isn't threadable, needs to be on main/ui thread).

Code: Select all

let nickname = "$F80$i$S$oToffe$z$06FSmurf $z$n$l[http://goo.gl/y4M9VK][App]$l"
let styledNickname = MPFormatter().parse(nickname).getAttributedString()
Will result in Image

Install and usage instructions are in the github readme.md.
Cocoapods definition:

Code: Select all

pod 'MPFormatter', '~> 1.2.0'
Github: https://github.com/tomvlk/MPFormatter_swift

Announcement: Version 1.x.x freezed, from now 1.x.x will only get bugfixes.

Toffe
Last edited by toffe on 14 Feb 2017, 19:35, edited 5 times in total.
User avatar
toffe
Posts: 782
Joined: 15 Jun 2013, 10:57
Location: The Netherlands
Contact:

Re: ManiaPlanet style Swift parser

Post by toffe »

The library is now updated, can now strip styles,links and colors on the parse() return.
See github for examples.

Toffe
User avatar
toffe
Posts: 782
Joined: 15 Jun 2013, 10:57
Location: The Netherlands
Contact:

Re: ManiaPlanet style Swift parser

Post by toffe »

New version released on github. Has a fix for $h links.

Toffe
User avatar
toffe
Posts: 782
Joined: 15 Jun 2013, 10:57
Location: The Netherlands
Contact:

Re: ManiaPlanet style Swift parser

Post by toffe »

The github master is updated to Swift 1.2 for the new XCode (and Swift) support.
(Build is still failing at travis because of the lack of support for the new xcode at travis).

Toffe
novationx
Posts: 2723
Joined: 10 Aug 2013, 22:33

Re: ManiaPlanet style Swift parser

Post by novationx »

great work mate!
Can i ask for what this is used?

Is it to display maniaplanet-nicknames correctly on ios devices?
The neverending waiting game has to stop.
User avatar
toffe
Posts: 782
Joined: 15 Jun 2013, 10:57
Location: The Netherlands
Contact:

Re: ManiaPlanet style Swift parser

Post by toffe »

Its used in the ManiaPlanet toolkit app for iOS. To display the server names and the nicknames of the players. Also used for making links, and colors in news items.
And working great. :)

Toffe
User avatar
toffe
Posts: 782
Joined: 15 Jun 2013, 10:57
Location: The Netherlands
Contact:

Re: ManiaPlanet style Swift parser

Post by toffe »

Just updated to Swift 2.0!

Toffe
User avatar
toffe
Posts: 782
Joined: 15 Jun 2013, 10:57
Location: The Netherlands
Contact:

Re: ManiaPlanet style Swift parser

Post by toffe »

Now also supports tvOS.
And added Cocoapods support:



Make sure you got the Podfile header for using Swift code:

Code: Select all

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!
Then add the pod

Code: Select all

pod 'MPFormatter', '~> 1.1.1'
User avatar
toffe
Posts: 782
Joined: 15 Jun 2013, 10:57
Location: The Netherlands
Contact:

Re: ManiaPlanet style Swift parser

Post by toffe »

Lib has been converted and updated to support Swift 3!.

1.x.x will only get bugfixes from now.
Post Reply

Return to “General Tools”

Who is online

Users browsing this forum: No registered users and 1 guest